c++ builder2010 sqllite的使用

 

推荐一个我自己做的一个电影站,绝对没弹窗:-)  www.fastdy.com 速看电影吧,每天都更新,

最新的电影电视剧都在速看电影吧!~

 

 

下载sqllite3 的c++库(我忘记我的是哪个了,反正就那几个文件)

1 初始化


CppSqlite * m_sqlite;
sqlite3 * GetDBPointer() {
        return /* m_dictDb */ m_sqlite->GetSqlitePtr();
  }
 

 

 

   
         UnicodeString m_path = GetModuleName(0);
         UnicodeString fileName = ExtractFileName(m_path);
        int pos = m_path.Pos(fileName);
        m_path.Delete(pos, fileName.Length());

        AnsiString dbPath = m_path + "config.db";
        if (OpenDialog1->Execute(this->Handle)) {
            dbPath = OpenDialog1->FileName;
        }
        else
            return;
        m_sqlite->Open(dbPath.c_str());
 

 

2 赋值给cxtreelist

 

char * sqlStr =
        "select distinct SYS_TYPE,TABLE_TYPE,TABLE_NAME, TABLE_DESC, NO from FIELDS order by SYS_TYPE asc,TABLE_TYPE asc, TABLE_NAME asc";
 
    cxTreeListTables->BeginUpdate();
    if (ManageForm->strHttppath == "") {
        sqlite3_exec(GetDBPointer(), sqlStr,
            SqliteCallBack, NULL, NULL);
    }
 

 

 

 

int SqliteCallBack(void *data, int columnCount,
    char **columnValues, char **columnNames) {
    if (m_SysType != UnicodeString(columnValues[0])) {
        TcxTreeListNode * typeNode = m_me->cxTreeListTables->Add();
        typeNode->Texts[1] = columnValues[0];
        typeNode->Values[3] = false;
        typeNode->ImageIndex = 2;
        m_SysType = columnValues[0];

        if (m_currentNodeA)
            m_currentNodeA->Expand(true);
        m_currentNodeA = typeNode;
    }

    if (m_tableType != UnicodeString(columnValues[1])) {
        TcxTreeListNode * node = m_currentNodeA->AddChild();
        node->Texts[1] = columnValues[1];
        node->Values[3] = false;
        node->ImageIndex = 3;
        m_tableType = columnValues[1];

        if (m_currentNode)
            m_currentNode->Expand(true);
        m_currentNode = node;
    }
    TcxTreeListNode * nodeA = m_currentNode->AddChild();

    nodeA->Texts[1] = columnValues[2];
    nodeA->Texts[2] = columnValues[3];
    nodeA->Values[3] = false;
    nodeA->Texts[4] = columnValues[4];
    nodeA->ImageIndex = 15;

    return 0;
}

 

3.如何 读取sqllite3 blob数据

 

   char * buf, *output;
        int len;
        m_sqlite->ReadBlob(AnsiString(sqlStr).c_str(), buf, len);
        if (len == 0)
            return "";
        m_aes->InvCipher(buf, len, output);//这是我自己的解密函数 AES
        UnicodeString rst = output;
        delete[]buf;
        delete[]output;
        return rst;
 

 

4.执行SQL语句  

 

int __fastcall Execsql(UnicodeString updateStr) {
    int err;
    err = ManageForm->m_sqlite->ExecNonQuery(AnsiString(updateStr).c_str());
    return err;

}

 

5  写combox

 

     AnsiString    sqlStr = "select ID, DESCRIPTION from session";
    TcxComboBoxProperties * prop = (TcxComboBoxProperties*)
            this->cxTreeListColumn_kind->Properties; 
       m_sqlite->ExecSql(sqlStr.c_str());
        while (!ManageForm->m_sqlite->IsEOF()) {
            prop->Items->Add(UnicodeString
                (m_sqlite->GetFieldByIndex(0).c_str()    ));
            props->Items->Add(UnicodeString
                (m_sqlite->GetFieldByIndex(0).c_str()    ));
            m_sqlite->MoveNext();
        }
   
 

 

 

 

 

 

 

转载于:https://www.cnblogs.com/kongchao/archive/2011/04/01/2002244.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值