Reuse, not rework
Home

License Awareness



Highly Reusable Software

By activity
Professions, Sciences, Humanities, Business, ...

User Interface
Text-based, GUI, Audio, Video, Keyboards, Mouse, Images,...

Text Strings
Conversions, tests, processing, manipulation,...

Math
Integer, Floating point, Matrix, Statistics, Boolean, ...

Processing
Algorithms, Memory, Process control, Debugging, ...

Stored Data
Data storage, Integrity, Encryption, Compression, ...

Communications
Networks, protocols, Interprocess, Remote, Client Server, ...

Hard World
Timing, Calendar and Clock, Audio, Video, Printer, Controls...

File System
Management, Filtering, File & Directory access, Viewers, ...


NAME

librock_dbi_open - Initiate a connection to a database manager
librock_dbi_close - Close a connection opened with librock_dbi_open
librock_dbi_exec - Perform a database operation
librock_dbi_fetch_row - Retrieve results from a database operation
librock_dbi_quote - Encode special characters
#License - #Source code - #Example Use -

SYNOPSIS

#include <librock/data.h>

void *                     /* a connection ID for use in other calls */
librock_dbi_open(
    const char *pszParams, /* blank-separated list of parameters.  First is driver name */
    char **ppaszErr        /* stores a librock_astring error message */
    );

DESCRIPTION

These functions implement a standard API to database manager call-level interfaces. The call to librock_dbi_open specifies which driver to use, and that sets up function pointers which correspond to the other librock_dbi_ functions.

The implementation of librock_dbi_exec must intercept the special query "SHOW TABLES" and perform the appropriate action so that librock_db_fetch_row will return a list of tables.

If the caller expects to have more than one query open simultaneously, (i.e. a call to librock_dbi_exec() before finishing the with results of a previous query) it must call librock_dbi_open() for each simultaneous query. (The implementation may pool such connections, but is not required to.)

Based on compile-time flags, drivers can be disabled by #define librock_dbi_DRIVER_open librock_dbi_fail_open

As of 2002-06-14, the driver supported is 'odbc'. The paramete for open is the DSN.

Typical use is

    char *err = 0;
    void *idConn = librock_dbi_open("odbc DRIVER={Microsoft Text Driver (*.txt; *.csv)};DefaultDir=g:\\reuse\\db\\;",&err);
    void *idStmt;
    if (!idConn) {
        printf("%s\n",err);
        return -1;
    }
    idStmt = librock_dbi_exec(idConn,"SELECT * FROM tablename",&err);
    if (idStmt) {
        const char **pCols;
        int n;
        int i;
        while(1) {
            librock_dbi_fetch_row(idStmt,&pCols,&n,&err);
            if (err && !strncmp(err,"I-106-",5)) {
                librock_dbi_fetch_row(idStmt,0,0,&err);
                break;
            }
            i =0;
            while(i < n) {
                if (i) {
                    printf("\t%s",pCols[i]);
                } else {
                    printf("%s",pCols[i]);
                }
                i++;
            }
            printf("\n");

        }
    }

    librock_dbi_close(idConn,&err);

    librock_astrfree(&err);


USES

  librock_wordcmp
  librock_dbi_odbc_open



LICENSE

  Copyright 1998-2002 Forrest J. Cavalier III, http://www.mibsoftware.com
  Licensed under BSD-ish license, NO WARRANTY. Copies must retain this block.
  License text in <librock/license/librock.txt> librock_LIDESC_MD5=f2a00374df769e694451262ac9df1336

Source Code

./data/database/dbi.c (implementation, plus source of this manual page)

This software is part of Librock

Rapid reuse, without rework. Details
This page copyright (C) 2002-2003 Forrest J. Cavalier III, d-b-a Mib Software, Saylorsburg PA 18353, USA

Verbatim copying and distribution of this generated page is permitted in any medium provided that no changes are made.
(The source of this manual page may be covered by a more permissive license which allows modifications.)

Want to help? We welcome comments, patches. -- Need help? Request paid support.