Set PRAGMA encoding =“UTF-16” for main database in

2019-07-04 00:44发布

I read that it is not possible to change the text encoding of a database after it has been created and any attempt to do so will be silently ignored.(from here)

Frome this post, to create main database,say 'databasename.db' in SQLite, we have to type following in command prompt :

sqlite3 databasename.db

which creates the database and displays sqlite shell as :

C:\Documents and Settings\Administrator>sqlite3 AudioData.db
SQLite version 3.7.11 2012-03-20 11:35:50
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite>

In this case, how to set PRAGMA encoding ? How can I give PRAGMA command before create database command since the sqlite shell starts after create database command?? Thanks in advance!

2条回答
欢心
2楼-- · 2019-07-04 01:07

You just call sqlite3 as you wrote. At this time there is just an empty file. Then you set your pragmas. The database with all its settings will be written after creating the first table. And the time of writing with all the environment variables is important. Just then the database is really created. So just set your pragmas before creating the first table.
e.g.

sqlite3 test.db

opens sqlite, nothing is written at that time

pragma encoding=utf16;

there is still nothing written

.quit

closes sqlite, an empty file test.db gets created

sqlite3 test.db

opens sqlite

pragma encoding = utf16;
pragma nnnn=xxx;

sets the pragma(s), the file test.db is still empty

create table test (testid integer);

now the database gets really created and the database file test.db gets written with content

查看更多
3楼-- · 2019-07-04 01:07

Use SQLlite Browser for such advanced functionalities. It is very straight forward to use.

查看更多
登录 后发表回答