• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            eryar

            PipeCAD - Plant Piping Design Software.
            RvmTranslator - Translate AVEVA RVM to OBJ, glTF, etc.
            posts - 603, comments - 590, trackbacks - 0, articles - 0

            SQLite Hello Code

            Posted on 2012-10-27 23:21 eryar 閱讀(1521) 評(píng)論(0)  編輯 收藏 引用
              1: //------------------------------------------------------------------------------
            
              2: //	Copyright (c) 2012 eryar All Rights Reserved.
            
              3: //
            
              4: //		File    : Main.cpp
            
              5: //		Author  : eryar@163.com
            
              6: //		Date    : 2012-10-27 23:01
            
              7: //		Version : 0.1v
            
              8: //
            
              9: //	Description : Test SQLite program.
            
             10: //
            
             11: //==============================================================================
            
             12: 
            
             13: #include <stdio.h>
            
             14: #include "sqlite3.h"
            
             15: 
            
             16: // Query callback function.
            
             17: int QueryCallback(void* data, int colCount, char** colValues, char** colName);
            
             18: 
            
             19: int main(int argc, char* argv[])
            
             20: {
            
             21:     int iResultCode = 0;
            
             22:     char*   szErrorMsg  = NULL;
            
             23:     const char* szCreateTableSQL = "create table users(name varchar(20) primary key, age int, birthday datetime);";
            
             24:     
            
             25:     // Connect to the database.
            
             26:     sqlite3*    pDB = NULL;
            
             27: 
            
             28:     iResultCode = sqlite3_open("test.db", &pDB);
            
             29: 
            
             30:     if (iResultCode != SQLITE_OK)
            
             31:     {
            
             32:         fprintf(stderr, "Cann't open database: %s\n", sqlite3_errmsg(pDB));
            
             33:         return 1;
            
             34:     }
            
             35: 
            
             36:     printf("Connected to the database successfully!\n");
            
             37: 
            
             38: 
            
             39:     // Execute the create table command.
            
             40:     iResultCode = sqlite3_exec(pDB, szCreateTableSQL, 0, 0, &szErrorMsg);
            
             41:     if (iResultCode != SQLITE_OK)
            
             42:     {
            
             43:         fprintf(stderr, "SQL error: %s! \n", szErrorMsg);
            
             44: 
            
             45:         sqlite3_free(szErrorMsg);
            
             46:     }
            
             47: 
            
             48:     // Insert records to the database.
            
             49:     iResultCode = sqlite3_exec(pDB, "insert into users values('張三', 20, '2012-10-27');", 0, 0, &szErrorMsg);
            
             50:     if (iResultCode)
            
             51:     {
            
             52:         printf("Insert a record to the database.\n");
            
             53:     }
            
             54: 
            
             55:     // Query the database.
            
             56:     iResultCode = sqlite3_exec(pDB, "select * from users;", QueryCallback, 0, &szErrorMsg);
            
             57: 
            
             58:     sqlite3_close(pDB);
            
             59: 
            
             60:     return 0;
            
             61: }
            
             62: 
            
             63: // For every record will call the callback function.
            
             64: // N records will call the callback function N times.
            
             65: int QueryCallback( void* data, int colCount, char** colValues, char** colName )
            
             66: {
            
             67:     for (int i = 0; i < colCount; i++)
            
             68:     {
            
             69:         printf("%s = %s\n", colName[i], colValues[i] == 0 ? "NULL":colValues[i]);
            
             70:     }
            
             71: 
            
             72:     return 0;
            
             73: }
            
             74: 

             

            輸出結(jié)果:

              1: Connected to the database successfully!
            
              2: name = 張三
            
              3: age = 20
            
              4: birthday = 2012-10-27
            
              5: Press any key to continue

            只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問(wèn)   Chat2DB   管理


            一级做a爰片久久毛片毛片| 婷婷伊人久久大香线蕉AV| 久久青青草原精品影院| 夜夜亚洲天天久久| 久久久久国色AV免费看图片| 亚洲午夜精品久久久久久浪潮| 久久久久亚洲AV无码专区首JN| 97精品依人久久久大香线蕉97| 99久久免费国产精品热| 亚洲午夜久久久精品影院 | 久久99精品久久久久子伦| 嫩草影院久久99| 久久久亚洲裙底偷窥综合 | 久久91精品国产91| 韩国免费A级毛片久久| 亚洲欧美久久久久9999| 久久777国产线看观看精品| 亚洲国产成人久久一区WWW| 国产成人久久精品区一区二区| 欧美日韩成人精品久久久免费看 | 亚洲精品99久久久久中文字幕| 久久久婷婷五月亚洲97号色| 久久精品无码免费不卡| 精品久久一区二区| 无码人妻久久一区二区三区免费丨 | 久久香蕉一级毛片| 久久婷婷人人澡人人爽人人爱| 久久国产高清字幕中文| 亚洲国产另类久久久精品黑人| 亚洲七七久久精品中文国产| 天天综合久久久网| 91久久精一区二区三区大全| 亚洲综合熟女久久久30p| 思思久久99热只有频精品66| 亚洲&#228;v永久无码精品天堂久久 | 久久久国产打桩机| 狠狠色丁香久久婷婷综合蜜芽五月 | 亚洲国产精品久久久久网站| 国内精品久久国产大陆| 久久精品无码专区免费东京热| 国内精品伊人久久久久av一坑|