Bool CROVSOFEWAREDlg: : Connectmysqlite ()
{
//create the database//sqlite3 database handle has been declared as a global
ZErrMsg=NULL;
Rc=sqlite3_open (" DataBase \ \ ShuJu db ", & amp; My_sqlite);//open the specified database files, if there is no will create a database file with the same name (ShuJu. Db)
Char SQL [400]="";
If (rc!=SQLITE_OK)
{
Sqlite3_close (my_sqlite);//open the failure!
MessageBox (_T (" database open failed, please check again after operation!" ), NULL, MB_ICONSTOP);
return FALSE;
}
Sqlite3_free (zErrMsg);
//create a table, named "Jilu"
//happened to test
Memset (SQL, 0, sizeof (SQL));
Sprintf_s (SQL, "CREATE TABLE IF NOT EXISTS user_database (Id int PRIMARY KEY NOT NULL, the Name varchar (20) NOT NULL, UNIQUE Password varchar (20) NOT NULL)");//create a table
If (sqlite3_exec (my_sqlite, SQL, NULL, NULL, & amp; ZErrMsg)!=SQLITE_OK)
{
MessageBox (_T (" fails, database list generated error!" ), NULL, MB_ICONSTOP);
return FALSE;
}
//test insert data
Int initialNum=3;
Int rows;
Char UserName [20].
Int UserPasswrod;
Memset (UserName, 0, 20);
Strcpy (UserName "Admin");
UserPasswrod=12345678;
Sprintf_s (SQL, "INSERT INTO user_database (Id, Name, Password) VALUES (% d, '% s',' % s')", 1, UserName, "12345678");
Int the exit=sqlite3_exec (my_sqlite, SQL, NULL, NULL, & amp; ZErrMsg);//test content until here
Memset (SQL, 0, sizeof (SQL));
Sprintf_s (SQL, "CREATE TABLE IF NOT EXISTS Jilu (, Time varchar (10) NOT NULL, UNIQUE, KP double the NOT NULL, KI double the NOT NULL, KD double the NOT NULL, depth_setpoint double, the depth varchar (10), CRPM varchar (10), MRPM varchar (10), temperature varchar (10), the volt varchar (10)");
Sqlite3_exec (my_sqlite, SQL, NULL, NULL, & amp; ZErrMsg);
If (sqlite3_exec (my_sqlite, SQL, NULL, NULL, & amp; ZErrMsg)!=SQLITE_OK)
{
MessageBox (_T (" fails, database list generated error!" ), NULL, MB_ICONSTOP);
return FALSE;
}
Sqlite3_free (zErrMsg);
Memset (SQL, 0, sizeof (SQL));
Sprintf_s (SQL, "INSERT INTO Jilu (Time, KP, KI, KD, depth_setpoint, CRPM, MRPM, temperature, the volt) VALUES (' % s', %, 2 lf, %, 2 lf, %, 2 lf, '% s',' % s', '% s',' % s', '% s')", "2018.5.6", K_P, K_I and K_D, "1", "1000", "990", "37", "80");
Sqlite3_exec (my_sqlite, SQL, NULL, NULL, & amp; ZErrMsg);
If (sqlite3_exec (my_sqlite, SQL, NULL, NULL, & amp; ZErrMsg)!=SQLITE_OK)
{
MessageBox (_T (insert data failed! "" ), NULL, MB_ICONSTOP);
return FALSE;
}
Sqlite3_free (zErrMsg);
Sqlite3_close (my_sqlite);//close
return TRUE;
}
CodePudding user response:
Make sure your SQL statement does not have what problem ~CodePudding user response:
The CREATE TABLE IF NOT EXISTS Jilu ( , Time varchar (10) NOT NULL, UNIQUE... )More than a comma,
CodePudding user response:
CodePudding user response:
Many commas, actually these SQL should be in the database management software test passed first, then put the program