Page 1 of 1

Run error when the database exsited

Posted: Sat Sep 02, 2017 11:50 am
by love8gege

Code: Select all

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 ?

Re: Run error when the database exsited

Posted: Sat Sep 02, 2017 12:16 pm
by doublemax
wxSQLite3 throws exceptions. Wrap your code in try/catch and check the exception message. Hopefully it tells you what's wrong.

Re: Run error when the database exsited

Posted: Sun Sep 03, 2017 1:25 pm
by love8gege
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.

Re: Run error when the database exsited

Posted: Sun Sep 03, 2017 1:47 pm
by doublemax
the test.db will not open by sqliteexpert : error info is not a database.... why ? BTW, the db.TableExists("emp") is TRUE.
Check if it works without encryption.

Re: Run error when the database exsited

Posted: Sun Sep 03, 2017 9:14 pm
by utelle
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.

Regards,

Ulrich

Re: Run error when the database exsited

Posted: Tue Sep 05, 2017 12:57 pm
by love8gege
thanks your reply!
i want to use the database with no encryption method ,but i don't know how to do ? can you tell me? thanks again!

Re: Run error when the database exsited

Posted: Tue Sep 05, 2017 2:12 pm
by doublemax
It's in the code you posted:

Code: Select all

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.