0

When trying to insert into the database a string such as :
"セブンゴースト; 神幻拍挡07;"
there is no error but it is read as nil after a select.

Exemple :

string = "セブンゴースト; 神幻拍挡07;"
db = SQLite3::Database.new "randomfilename"
prep = db.prepare "INSERT INTO test_db VALUES (NULL, ?)"
prep.bind_param 1, string
prep.execute
prep2 = db.prepare "SELECT * FROM test_db"
ret = prep2.execute
p ret

this will display something like this : [[0, nil]]
( assuming that the table has a primary int key as first value and a TEXT for second )

It is possible that my database does not have the good encoding but if it is the case, how do I change it without loosing everything ?

  • 1
    Are you sure that string is using UTF-8 encoding? Does [this answer offer any advice](http://stackoverflow.com/questions/27356441/sqlite-in-ruby-prepared-statement-cutting-utf-8-input)? – tadman Nov 24 '16 at 22:24
  • Are you sure the columns are in the order you think they are? You really should specify the columns in your INSERT: `insert into test_db (column_name1, column_name2) values (null, ?)` or better, leave the `null` out completely (unless you're trying to override a non-NULL default): `insert into test_db (column_name2) values (?)`. You should also include the schema for your `test_db` table. – mu is too short Nov 25 '16 at 00:13
  • yes for both, i can display the string content using puts. – Matthieu Raynaud de Fitte Nov 25 '16 at 09:18
  • the first value is a primary key with auto increment so I do not wish to touch it – Matthieu Raynaud de Fitte Nov 25 '16 at 09:19

1 Answers1

0

found the answer : I needed a NTEXT field, not a TEXT.
the NTEXT supports UTF-8 encoding
http://www.w3schools.com/sql/sql_datatypes.asp