How to insert a new line ("\n") character in SQLite?

iammilind

While trying to insert something like:

"Hello\nWorld"

SQLite throws error something like:

Message: unrecognized token: "'Hello";" (also few other errors)

Even though I convert above string to "Hello''\nWorld" or "Hello\"\n\"World", these escape characters sequences don't work in this case.

Currently using C++ language, I am inserting this column like any other simple string columns. I tried above escape sequence (even though I read in internet that, they don't work with \n).

How to insert new line and other such special characters in SQLite DB?

CL.

In SQL, there is no mechanism to escape newline characters; you have to insert them literally:

INSERT INTO MyTable VALUES('Hello
world');

Alternatively, construct the string dynamically:

INSERT INTO MyTable VALUES('Hello' || char(10) || 'world');

(The type of newline (13 or 10 or 13+10) is OS dependent.)

When you embed the SQL statements in C++ strings, you have to escape the newline in the first case:

q1 = "INSERT INTO MyTable VALUES('Hello\nworld');";
q2 = "INSERT INTO MyTable VALUES('Hello' || char(10) || 'world');";

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

how to create the new line character

分類Dev

New line with invisible character

分類Dev

how to insert new line if a line has more than 60 characters

分類Dev

Notepad ++ How to delete new line after a specific character?

分類Dev

How to append character to the end of a string without creating a new line

分類Dev

How to display a string with new line character in a HTML page using scriplets?

分類Dev

New Line Character in ONSEN ALERT

分類Dev

How to insert a character every n characters from end of string

分類Dev

How to insert separator (comma) in a character?

分類Dev

Python : How to insert special character

分類Dev

Enter Character should print a new line in html

分類Dev

Escape New line character in Spark CSV read

分類Dev

Why is my '+' operator considered as a new line character?

分類Dev

Powershell - XML Insert a new line in an existing section

分類Dev

Insert new line after all occurrences of a pattern

分類Dev

How to read an array up till the new line '\n'?

分類Dev

How do I insert new line in EditText field while reading the text from a file

分類Dev

Cannot insert character 'N' to PostgreSQL in Sequelize

分類Dev

Insert a new line string on every blank line in python

分類Dev

sed insert line command to add text with new line OSX

分類Dev

Insert a new line string on every blank line in python

分類Dev

CSV read error: new-line character seen in unquoted field

分類Dev

Best way to read this file while ignoring the new line character

分類Dev

Set if-condition for new line every 10th character

分類Dev

TinyMCE does not insert line break for \n

分類Dev

How to insert image into sqlite3 database?

分類Dev

How to remove last character of Nth line linux

分類Dev

How to count the number of a specific character in each line?

分類Dev

How to replace comma with new line

Related 関連記事

  1. 1

    how to create the new line character

  2. 2

    New line with invisible character

  3. 3

    how to insert new line if a line has more than 60 characters

  4. 4

    Notepad ++ How to delete new line after a specific character?

  5. 5

    How to append character to the end of a string without creating a new line

  6. 6

    How to display a string with new line character in a HTML page using scriplets?

  7. 7

    New Line Character in ONSEN ALERT

  8. 8

    How to insert a character every n characters from end of string

  9. 9

    How to insert separator (comma) in a character?

  10. 10

    Python : How to insert special character

  11. 11

    Enter Character should print a new line in html

  12. 12

    Escape New line character in Spark CSV read

  13. 13

    Why is my '+' operator considered as a new line character?

  14. 14

    Powershell - XML Insert a new line in an existing section

  15. 15

    Insert new line after all occurrences of a pattern

  16. 16

    How to read an array up till the new line '\n'?

  17. 17

    How do I insert new line in EditText field while reading the text from a file

  18. 18

    Cannot insert character 'N' to PostgreSQL in Sequelize

  19. 19

    Insert a new line string on every blank line in python

  20. 20

    sed insert line command to add text with new line OSX

  21. 21

    Insert a new line string on every blank line in python

  22. 22

    CSV read error: new-line character seen in unquoted field

  23. 23

    Best way to read this file while ignoring the new line character

  24. 24

    Set if-condition for new line every 10th character

  25. 25

    TinyMCE does not insert line break for \n

  26. 26

    How to insert image into sqlite3 database?

  27. 27

    How to remove last character of Nth line linux

  28. 28

    How to count the number of a specific character in each line?

  29. 29

    How to replace comma with new line

ホットタグ

アーカイブ