Run error when the database exsited

In this forum you can discuss database related issues which can be wxWidgets related, but also generic in nature.
Post Reply
love8gege
In need of some credit
In need of some credit
Posts: 5
Joined: Fri Sep 01, 2017 12:47 pm

Run error when the database exsited

Post 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 ?
User avatar
doublemax
Moderator
Moderator
Posts: 19115
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Run error when the database exsited

Post by doublemax »

wxSQLite3 throws exceptions. Wrap your code in try/catch and check the exception message. Hopefully it tells you what's wrong.
Use the source, Luke!
love8gege
In need of some credit
In need of some credit
Posts: 5
Joined: Fri Sep 01, 2017 12:47 pm

Re: Run error when the database exsited

Post 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.
User avatar
doublemax
Moderator
Moderator
Posts: 19115
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Run error when the database exsited

Post 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.
Use the source, Luke!
utelle
Moderator
Moderator
Posts: 1125
Joined: Tue Jul 05, 2005 10:00 pm
Location: Cologne, Germany
Contact:

Re: Run error when the database exsited

Post 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
love8gege
In need of some credit
In need of some credit
Posts: 5
Joined: Fri Sep 01, 2017 12:47 pm

Re: Run error when the database exsited

Post 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!
User avatar
doublemax
Moderator
Moderator
Posts: 19115
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Run error when the database exsited

Post 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.
Use the source, Luke!
Post Reply