const wxString dbFile = wxGetCwd() + "/test.db";
m_textctrl->AppendText(dbFile);
wxSQLite3Database db;
if (wxSQLite3Database::HasEncryptionSupport())
{
db.Open(dbFile, wxString(wxT("password")));
m_textctrl->AppendText("open db with password\n");
}
else
{
db.Open(dbFile);
m_textctrl->AppendText("open db without password\n");
}
I am a beginner,just learn program with sqlite3.
code like abvoe , compile x64 debug done ,when it runs first time and the text.db not exist,it will ok,it can creat the test.db. While i try to run it again and the test.db exsited. It will give me an error :unhandled exception An unhandled exception occurred. I delete the test.db,then run it ,it OK. Can anyone help me and tell me why ?
HOHO~ I see ,the error has resolved ,the code above is correct . THANK
but, when I add the code :
db.ExecuteUpdate("CREATE TABLE emp(useraccount CHAR(11) PRIMARY KEY UNIQUE NOT NULL, password CHAR(8) NOT NULL, firsttime DATE, secondtime DATE, thirdtime DATE, times INTEGER);");
now new problem is coming , the test.db will not open by sqliteexpert : error info is not a database.... why ? BTW, the db.TableExists("emp") is TRUE.
love8gege wrote:now new problem is coming , the test.db will not open by sqliteexpert : error info is not a database.... why ?
I assume that you tried to use the SQLite management tool SQLiteExpert to check the database you created with your wxSQLite3 application. If that is correct, you have to make sure that SQLiteExpert uses a SQLite library supporting the same encryption method as wxSQLite3. Please take a look at the answer to the question How do I open a password protected database? in the SQLiteExpert FAQ.
if (wxSQLite3Database::HasEncryptionSupport())
{
db.Open(dbFile, wxString(wxT("password")));
m_textctrl->AppendText("open db with password\n");
}
else
{
db.Open(dbFile);
m_textctrl->AppendText("open db without password\n");
}
Don't pass a password and the database won't be encrypted.