⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 byteinttest.c

📁 b树实现源码,linux和unix下运行,速度快,极好用
💻 C
字号:
#include<CSql.h>ByteInt id = 0;char name[196] = "PRABAKARAN";int select(Table *table, ComparisionOp op){    printf("Operator test for %d\n", op);    Condition p1;    ByteInt val1 = 3;    p1.setTerm("f1", op, &val1);    table->setCondition(&p1);    table->execute();    void *tuple;    while ( table->fetch() ) {        printf("tuple value is %d %s \n", (int)id, name);    }    table->close();    return 0;}int main(){    Connection conn;    DbRetVal rv = conn.open("root", "manager");    if (rv != OK)    {       printf("Error during connection %d\n", rv);       return 1;    }    DatabaseManager *dbMgr = conn.getDatabaseManager();    if (dbMgr == NULL) { printf("Auth failed\n"); return 2;}    TableDef tabDef;    tabDef.addField("f1", typeByteInt, 0, NULL, true);    tabDef.addField("f2", typeString, 196);    rv = dbMgr->createTable("t1", tabDef);    if (rv != OK) { printf("Table creation failed\n"); return 3; }    printf("Table created\n");#ifdef WITHINDEX    HashIndexInitInfo *idxInfo = new HashIndexInitInfo();    strcpy(idxInfo->tableName, "t1");    idxInfo->list.append("f1");    idxInfo->isUnique = true;    idxInfo->isPrimary = true;    idxInfo->indType = hashIndex;    rv = dbMgr->createIndex("indx1", idxInfo);    if (rv != OK) { printf("Index creation failed\n"); return -1; }    printf("Index created\n");    delete idxInfo;#endif    Table *table = dbMgr->openTable("t1");    if (table == NULL) { printf("Unable to open table\n"); return 4; }    table->bindFld("f1", &id);    table->bindFld("f2", name);    char *tuple;    int ret;    ByteInt i;    rv =conn.startTransaction();    for(i = 0; i< 5; i++)    {        if (rv != OK) exit(5);        id= i;        strcpy(name, "PRABAKARAN0123456750590");        ret = table->insertTuple();        if (ret != 0) break;    }    conn.commit();    conn.startTransaction();    select(table, OpEquals);    conn.commit();    conn.startTransaction();    select(table, OpNotEquals);    conn.commit();    conn.startTransaction();    select(table, OpLessThan);    conn.commit();    conn.startTransaction();    select( table, OpLessThanEquals);    conn.commit();    conn.startTransaction();    select( table, OpGreaterThan);    conn.commit();    conn.startTransaction();    select( table, OpGreaterThanEquals);    conn.commit();    Condition p1;    ByteInt val1 = 0;    p1.setTerm("f1", OpEquals, &val1);    table->setCondition(&p1);    rv  = conn.startTransaction();    for(i = 0; i< 5; i++)    {        if (rv != OK) exit (1);        val1 = i;        table->execute();        tuple = (char*)table->fetch() ;        if (tuple == NULL) {printf("loop break in %d\n", (char)i);table->close();break;}        strcpy(name, "PRABAKARAN0950576543210");        table->updateTuple();        table->close();    }    conn.commit();    rv = conn.startTransaction();    for(i = 0; i< 5; i++)    {        if (rv != OK) exit (1);        val1 = i;        table->execute();        tuple = (char*)table->fetch() ;        if (tuple == NULL) {printf("loop break in %d\n", (char)i);table->close();break;}        printf("deleting tuple %d %s \n", (int)id, name);        table->deleteTuple();        table->close();    }    conn.commit();    table->setCondition(NULL);    rv = conn.startTransaction();    table->execute();    while ((tuple = (char*) table->fetch())) {        printf("after delete tuple present. Its  value is %d %s \n", (int)id, name);    }    table->close();    conn.commit();    dbMgr->closeTable(table);    dbMgr->dropTable("t1");    conn.close();    return 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -