Font size tree print favorites
Post topic: Have you ever encountered the trouble of fuzzy query (like) when using sqlite3 ?...
Tty1a
- Grade: slightly smaller
- Credit: 289
- RMB: 150
- Quota: 26
- Registration: 2007-9-14
11th floor
The problem has been solved, not in the query aspect, but in the insert aspect. sqlite3_exec (dB, SQL, 0, 0, & zerrmsg) cannot be used directly );, you can use the following method to insert data.
...
Char * SQL = "insert into/" ca01/"values ('001 ',? , '123', '123 ');";
Sqlite3_stmt * stmt;
Sqlite3_prepare (dB, SQL, strlen (SQL), & stmt, null );
Sqlite3_bind_text (stmt, 1, "aihua product distribution department, Baoan District, Shenzhen City", 256, sqlite_transient );
Sqlite3_step (stmt );
...
Thank you very much for your enthusiastic friends.
Light smoke
2007-11-2 19:02:21
Myb123
- Grade: first glance
- Points: 35
- Money: 19
- Number of shards: 4
- Registration: 2007-5-11
12th floor
Tty1a brothers:
I did what you did, but I still couldn't find it. Hurry up and help. It is best to paste the complete code. 2007-11-5 0:05:15
Myb123
- Grade: first glance
- Points: 35
- Money: 19
- Number of shards: 4
- Registration: 2007-5-11
13th floor
Tty1a brother: My code is as follows, but only 0 records are found.
Sqlite3 * DB = NULL;
Char * errmsg = 0;
Int result;
Result = sqlite3_open ("My. DB", & dB );
Char SZ [] = "create table [ca01] ([a] Text null, [B] Text null, [c] Text null, [d] Text null )";
Result = sqlite3_exec (dB, SZ, null, null, & errmsg );
Char * SQL = "insert into/" ca01/"values ('001 ',? , '123', '123 ');";
Sqlite3_stmt * stmt;
Sqlite3_prepare (dB, SQL, strlen (SQL), & stmt, null );
Sqlite3_bind_text (stmt, 1, "aihua product distribution department, Baoan District, Shenzhen City", 256, sqlite_transient );
Sqlite3_step (stmt );
Char ** dbresult;
Int nrow, ncolumn, I, j, index;
Result = sqlite3_get_table (dB, "select * From ca01 where B like '% aihua %'", & dbresult, & nrow, & ncolumn, & errmsg );
If (sqlite_ OK = Result)
{
Index = ncolumn;
Trace ("% d records/N", nrow );
For (I = 0; I <nrow; I ++)
{
Trace ("% d records/N", I + 1 );
For (j = 0; j <ncolumn; j ++)
{
Trace ("field name: % s-> Field Value: % s/n", dbresult [J], dbresult [Index]);
++ Index;
}
Trace ("-------/N ");
}
}
Sqlite3_free_table (dbresult );
Sqlite3_close (db );
2007-11-5 0:35:00
Tty1a
- Grade: slightly smaller
- Credit: 289
- RMB: 150
- Quota: 26
- Registration: 2007-9-14
14th floor
I am very sorry for being busy recently and failing to return in time. You cannot find it. It is estimated that the problem is solved by using sqlite3_get_table. Please try to use the binding method. Use sqlite3_get_table with caution or even no need.
You can find the following method:
Sqlite3 * DB = NULL;
Int rc = sqlite3_open ("data. DB", & dB); // open the specified database file
If (RC)
{
Showmessage (sqlite3_errmsg (db ));
Sqlite3_close (db );
Return;
}
Sqlite3_stmt * stmt;
Ansistring temp = "% aihua % ";
Char * sqlstr = "select * From ca01 where a002 like ?; ";
Sqlite3_prepare (dB, sqlstr, strlen (sqlstr), & stmt, null );
Sqlite3_bind_text (stmt, 1, temp. c_str (), temp. Length (), sqlite_transient );
While (sqlite3_step (stmt) = sqlite_row)
{
// Test
Edit1-> text = strpas (sqlite3_column_text (stmt, 0 ));
Edit2-> text = strpas (sqlite3_column_text (stmt, 1 ));
}
Sqlite3_finalize (stmt );
Sqlite3_close (db );
Light smoke
2007-11-5 22:44:37
Myb123
- Grade: first glance
- Points: 35
- Money: 19
- Number of shards: 4
- Registration: 2007-5-11
15th floor
Tty1a brother, I will try it according to your code, but sqlite3_step always returns sqlite_done, instead of sqlite_row, so it is always not in the WHILE LOOP, that is, the record is not found. The Code is as follows:
Sqlite3 * DB = NULL;
Char * errmsg = 0;
Int result;
Result = sqlite3_open ("My. DB", & dB );
Char SZ [] = "create table [ca01] ([a001] Text null, [a002] Text null, [a003] Text null, [a004] Text null )";
Result = sqlite3_exec (dB, SZ, null, null, & errmsg );
Char * SQL = "insert into/" ca01/"values ('001 ',? , '123', '123 ');";
Sqlite3_stmt * stmt;
Sqlite3_prepare (dB, SQL, strlen (SQL), & stmt, null );
Sqlite3_bind_text (stmt, 1, "aihua product distribution department, Baoan District, Shenzhen City", 256, sqlite_transient );
Sqlite3_step (stmt );
// Ansistring temp = "% aihua % ";
Char temp [100] = "'% aihua %'"; // cannot be changed to "% aihua %" or "'% aihua % '"
Char * sqlstr = "select * From ca01 where a002 like? ";
Sqlite3_prepare (dB, sqlstr, strlen (sqlstr), & stmt, null );
// Sqlite3_bind_text (stmt, 1, temp. c_str (), temp. Length (), sqlite_transient );
Sqlite3_bind_text (stmt, 1, temp, strlen (temp), sqlite_transient );
While (sqlite3_step (stmt) = sqlite_row) // always sqlite3_step always returns sqlite_done instead of sqlite_row
{
// Test
Printf ("% s, % s/n", sqlite3_column_text (stmt, 0), sqlite3_column_text (stmt, 1 ));
// Edit1-> text = strpas (sqlite3_column_text (stmt, 0 ));
// Edit2-> text = strpas (sqlite3_column_text (stmt, 1 ));
}
Sqlite3_finalize (stmt );
Sqlite3_close (db); 0:39:42
Tty1a
- Grade: slightly smaller
- Credit: 289
- RMB: 150
- Quota: 26
- Registration: 2007-9-14
16th floor
CTRL + scroll wheel zoom in or out "src =" http://photo.store.qq.com/http_imgload.cgi? /Rurl2 = bytes "width =" 753 "onLoad =" If (this. width> screen. width * 0.75) {This. resized = true; this. width = body. offsetwidth * 0.75;} "border =" 0 "resized =" true ">
That is really strange. It may be the reason for your programming environment. Some friends say that it is very good at C. I tested it with the code you posted above. It is indeed correct and the returned results are correct.
Note: test environment: Simplified Chinese WINXP + C ++ build 6.0 + sqlite3
Light smoke
2007-11-6 3:26:31
Tty1a
- Grade: slightly smaller
- Credit: 289
- RMB: 150
- Quota: 26
- Registration: 2007-9-14
17th Floor
Ansistring temp = "% aihua % ";
Or
Char temp [100] = "'% aihua % '";
Or
Char temp [100] = "% aihua % ";
All tested. Yes.
I originally thought that it would be too difficult to use the like clause to query data. It would be very passive to use it. Now it's okay.
I don't know if SQLite for Linux can be used in SCO openserver. Of course, it is estimated that the actual application should be used in Linux first, just because the current system is installed conveniently. Wait for time to test.
[This post was last edited at 3:55:27]
Light smoke
2007-11-6 3:46:47
Myb123
- Grade: first glance
- Points: 35
- Money: 19
- Number of shards: 4
- Registration: 2007-5-11
18th Floor
Thank you very much!
This may be the reason for the programming environment. I use vc6. I will try another environment change or another method, and report the latest results.