How to Add a Line Break to an SQLite Query

You must Login before you can answer or comment on any questions.

I have a lot of long queries in an app, and it would be really nice to be able to use line breaks in the query to make it more readable. I can do this in PHP, but every time I do it in Titanium I get a syntax error. Below is a simplified example.

This works:

db.execute("INSERT INTO myTable (column1, column2) VALUES('a','b')");
But this gives a syntax error:
db.execute("INSERT INTO myTable 
        (column1, column2) 
        VALUES('a','b')");
Any ideas on how I can improve the readability of my queries without incurring errors?

Thanks in advance.

1 Answer

Accepted Answer

javascript doesn't allow any line breaks in strings. You can to concat them together.

db.execute("INSERT INTO myTable " +
        "(column1, column2) " +
        "VALUES('a','b')");

— answered 9 months ago by Anthony Decena
answer permalink
2 Comments
  • According to the ECMAScript spec, you can also escape a linebreak with a backslash (), but I personally think that it can get ugly adding characters to a string thats already multi-line.

    — commented 9 months ago by Anthony Decena

  • Concatenation is a great idea. That'll help a lot. Thanks for your help.

    — commented 9 months ago by Clifton Labrum

Your Answer

Think you can help? Login to answer this question!