QtopiaÖÐʹÓÃSQLite×ܽἰSQLiteÖд洢ÖÐÎIJÙ×÷
¡¾¹¤×÷»·¾³£º»ùÓÚÓÑÉÆÖ®±Ûmini2440¿ª·¢°å+Qtopia2.2°æ±¾+RedHat9+SQLite-3.3.6¡¿
1.QtopiaÖÐʹÓÃSQLite
ÓÉÓÚQt2²»Ö§³ÖÊý¾Ý¿â²Ù×÷£¬£¨Qt3°æ±¾¾ÍÌṩÁËÖ§³ÖÊý¾Ý¿â²Ù×÷µÄÀ࣬µ«ÊÇQtopia2±È½Ï¾µä£¬ÊÇ»ùÓÚQt2µÄ£¬Ã»°ì·¨£¡£©ËùÒÔÔÚQt/Qtopia³ÌÐòÖÐÐèÒªÊý¾Ý¿âʱ£¬¿ÉÒÔ¿¼ÂÇÔÚQtÖÐʹÓÃLinuxϲÙ×÷SQLiteÊý¾Ý¿âµÄ·½·¨¡££¨±í´ïµÄÓе㲻Çå³þ£¬ºÇºÇ£¬»ù±¾ÉϾÍÊÇÖ±½Ó°ÑLinuxϲÙ×÷SQLiteµÄ´úÂëCopyµ½QT³ÌÐòµÄijһ¸öº¯ÊýÏ¡££©
ÐèÒªÎÒÃÇÐ޸ĵĵط½£º
¢ÙÔÚQtopia³ÌÐòÖÐÌí¼ÓÍ·Îļþsqlite3.h
¢ÚÔÚMakefileÎļþÖÐLIBSÌí¼ÓSQLite¿âµÄ°²×°Â·¾¶
È磺-L/usr/local/sqlite-3.3.6/lib -lsqlite3
¢ÛÈç¹ûÊDZàÒëÔÚ¿ª·¢°åÉÏÔËÐеijÌÐò£¬ÔòÌí¼Óarmƽ̨ϱàÒëµÄsqliteµÄ¿â·¾¶¡££¨ÏȰѱàÒëºÃµÄ¿â¿½±´µ½¿ª·¢°å£¬Ö´ÐÐexport LD_LIBRARY_PATH,ÈÃÄãµÄϵͳÄܹ»Ê¶±ð¿â·¾¶£©
2.SQLiteÖд洢ÖÐÎIJÙ×÷
֮ǰ¿ÉÒÔÔÚQtopiaÖÐÏÔʾÖÐÎÄ£¬ºóÀ´³ÌÐòÖÐÐèÒªµ÷ÓÃÊý¾Ý¿âµÄÐÅÏ¢ÇÒÒªÊÇÖÐÎĵģ¬¾ÍÊÔÁËÏ£¬¿ÉÒÔÏÔʾ¡££¨×Ô¼º×ܽáһϣ¬Êý¾Ý¿âÖд洢µÄ»¹²»ÊÇ0ºÍ1Â𣬲»¹ÜÄãÊÇÖÐÎÄ»¹ÊÇÓ¢ÎÄ£¬Ö»ÒªÄãÊäÈëµÄʱºòºÍÊä³öµÄʱºòÌṩһÖµıàÂ룬¾Í¿ÉÒÔÁË¡££©
¢ÙÕâÀﶼʹÓÃUTF-8±àÂ뷽ʽ£¬ÊäÈëÖÐÎĵĻ·¾³Ò»¶¨Ò²ÒªÊÇUTF-8µÄ£¨ÎÒµÄVi´ò¿ªµÄ¾Í²»ÊÇ£©£¬ÓÃQtCreator¹¤¾ß£¬¿ÉÒÔÑ¡Ôñ±àÂë´ò¿ªÀàÐÍ¡£
ÀûÓñà³Ìinsert£¬²åÈëÒ»¸öÖÐÎÄ×ֶΡ£
char *zErrMsg = 0;
char *sql;
char buf[256];
char *v1="ÄãºÃ";
sprintf(buf,"insert into \"gpio_config_info\" values('%s');",v1);
sql=buf;
sqlite3_exec(db,sql,0,0,&zErrMsg);
¢Ú²éѯºÍʹÓÃÊý¾Ý¿âÖб£´æµÄÖÐÎÄÐÅÏ¢
char *zErrMsg = 0;
char *sql;
int nrow = 0, ncolumn = 0;
char **azResult;
sql = "SELECT * from gpio_config_info";
sqlite3_get_table( db , sql , &azResult , &nrow , &ncolumn , &zErrMsg );
int i = 0 ;
printf( "row:%d column=%d \n" , nrow , ncolumn );
printf( "\nThe result of querying is : \n" );
item1->setText(2,codec->toUnicode(azResult[8]));//azResult[8]¼´Îª¶ÔÓ¦µÄ“ÄãºÃ”×Ö¶Î
for( i=0 ; i<( nrow + 1 ) * ncolumn ; i++ )
printf( "azResult[%d] = %s\n", i , azResult[i] );
sqlite3_free_table(azResult);
ÕâÑùÔÚQtopia³ÌÐòÖоͿÉÒÔÏÔʾ³öÖÐÎÄÁË¡£
Ïà¹ØÎĵµ£º
£¨2£© SQLÓï¾ä²Ù×÷
±¾½Ú½éÉÜÈçºÎÓÃsqlite Ö´Ðбê×¼ sql Óï·¨¡£
i.1 Ö´ÐÐsqlÓï¾ä
int sqlite3_exec(sqlite3*, const char *sql, sqlite3_callback, void ......
¡ïÈçºÎȨºâ£¿
¡¡¡¡µ±ÄãÔÚȨºâij¸ö³¡ºÏÊÇ·ñÓ¦¸ÃʹÓÃSQLiteʱ£¬£¨ÔÚ¼¼Êõ²ãÃ棩ÖÁÉÙÒª¿¼ÂÇÈçϼ¸µã£º
¡¡¡¡¡óÄÜ·ñ·¢»ÓSQLiteµÄijЩÌس¤£¿
¡¡¡¡¡óÊÇ·ñ»¹ÓÐÆäËüµÄÌæ´ú·½°¸£¿
¡¡¡¡¡óÊÇ·ñÓÐɶDZÔڵļ¼Êõ·çÏÕ£¿
¡¡¡¡ÏëÇå³þÉÏÊöÎÊÌâÖ®ºó£¬ÔÙ×ö³ö¾ö²ß¡£
¡¡¡¡¡ïSQLiteµÄÌصã
¡¡¡¡¹ØÓÚSQLiteµÄÌس¤£¬ÔÚÉϴεÄÌû×ÓÖÐÒѾ½éÉܹýÁË¡£ ......
ÕâÁ½ÌìC/SµÄÏîÄ¿ÖÐÓõ½ÁËsqlite£¬Õâ¸öС¶«Î÷»¹ÕæÊǺÃÓ᣷ÃÎÊËٶȺܿ첻˵£¬Éú³ÉµÄÊý¾Ý¿âÎļþÒ²ºÜС¡£·Ç³£ÊʺÏСÐÍÏîÄ¿µÄÊý¾Ý¿â¡£winceÖÐÇ¿ÁÒ½¨ÒéʹÓá£
²»¹ý½ñÌìÓöµ½Ò»¸öÎÊÌâÈÃÈËÍ·´ó£¬deleteÊý¾ÝµÄʱºòÌáʾno such table¡£
Êý¾Ý¿âÖеıíÃ÷Ã÷´æÔÚ£¬ÔÚÊý¾Ý¿âÖÐÖ´ÐÐdeleteµÄsqlҲûÓÐÎÊÌâ¡£¿´À´²»ÊÇsqlÓï¾äµÄÎÊÌâ¡£
µ«ÊÇÖ ......
SQLite²»½ö¿ÉÒÔ°ÑÊý¾Ý¿â ·ÅÔÚÓ²ÅÌÉÏ£¬»¹¿ÉÒÔ·ÅÔÚÄÚ´æÖУ¨sqlite3_open(":memory:", &db)£©£¬¾²âÊÔ£¬Í¬ÑùÌõ¼þÏÂÊý¾Ý¿â·ÅÔÚÄÚ´æÖбȷÅÔÚÓ²ÅÌÉϲåÈë¼Ç¼Ëٶȿì²î²»¶à3±¶¡£µ«Êý¾Ý¿â·ÅÔÚÄÚ´æÖÐʱÓÐÈçÏÂȱÏÝ£º
1¡¢¶Ïµç»ò³ÌÐò±ÀÀ£ºóÊý¾Ý¿â¾Í»áÏûʧ£¬ÄãÐèÒª¶¨ÆÚAttachµ½Ó²ÅÌÉϱ¸·Ý£»
2¡¢ÔÚÄÚ´æÖеÄÊý¾Ý¿â²»Äܱ»±ðµÄ½ø³Ì ......
ÕâƪÎÄÕÂÊÇʹÓÃSQLite C/C++½Ó¿ÚµÄÒ»¸ö¸ÅÒª½éÉܺÍÈëÃÅÖ¸ÄÏ¡£
ÓÉÓÚÔçÆÚµÄSQLiteÖ»Ö§³Ö5¸öC/C++½Ó¿Ú£¬Òò¶ø·Ç³£ÈÝÒ×ѧϰºÍʹÓ㬵«ÊÇËæ×ÅSQLite¹¦ÄܵÄÔöÇ¿£¬ÐµÄC/C++½Ó¿Ú²»¶ÏµÄÔö¼Ó½øÀ´£¬µ½ÏÖÔÚÓг¬¹ý150¸ö²»Í¬µÄAPI½Ó¿Ú¡£ÕâÍùÍùʹ³õѧÕßÍû¶øÈ´²½¡£ÐÒÔ˵ÄÊÇ£¬´ó¶àÊýSQLiteÖеÄC/C++½Ó¿ÚÊÇרÓõģ¬Òò¶øºÜÉÙ±»Ê¹Óõ½¡£¾¡¹ÜÓÐÕâ ......