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

📄 hash.c

📁 ORACLE编程的好东西,纯C写的OCI封装.很好用,支持数据池.
💻 C
字号:
#include "ocilib.h"

int main()
{
    int i, n;
    OCI_Connection *cn;
    OCI_Statement  *st;
    OCI_Resultset  *rs;
    OCI_HashTable *table;
    OCI_HashEntry *e;
    OCI_HashValue *v;

    if (!OCI_Initialize(NULL, NULL, OCI_ENV_DEFAULT))
        return EXIT_FAILURE;

    cn    = OCI_ConnectionCreate("db", "usr", "pwd", OCI_SESSION_DEFAULT);
    st    = OCI_StatementCreate(cn);
    table = OCI_HashCreate(256, OCI_HASH_INTEGER);

    /* fill the hash table with data from DB */

    OCI_ExecuteStmt(st, "select code, name from products");
                  
    rs = OCI_GetResultset(st);

    while (OCI_FetchNext(rs))
        OCI_HashAddInt(table, OCI_GetString2(rs, "name"), OCI_GetInt2(rs, "code"));

    printf("%d row(s) fetched\n", OCI_GetRowCount(rs));

    /* lookup an entry */
   
    printf("code for %s is : %d\n", "Cars", OCI_HashGetInt(table, "Cars"));

    /* browse the hash table */

    n = OCI_HashGetSize(table);

    for (i = 0; i < n; i++)
    {
        e = OCI_HashGetEntry(table, i);

        while (e != NULL)
        {
            printf (">key: '%s'\n", e->key);

            v = e->values;

            while (v != NULL)
            {
                printf ("..... value : '%i'\n", v->value.num);
                v = v->next;
            }

            e = e->next;
        }
    }

    /* destroy table */

    OCI_HashFree(table);
    
    OCI_Cleanup();
 
    return EXIT_SUCCESS;
}

⌨️ 快捷键说明

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