[ Previous ] [ Contents ] [ Index ] [ Next ]

Ns_PdDbOpen

Overview

Open a connection to the database.

Syntax

    void  Ns_PdDbOpen (void *handle, char *openArgs);

Description

This function opens a connection to the database based on the openArgs passed in. The handle passed in is the handle that was returned by Ns_PdDbInit, and will usually be cast to some driver-specific data structure. If the open operation is successful, this function should call Ns_PdSendString with OK_STATUS. On failure, the function should use Ns_PdSendString to return an error string.

Psuedo-code Example

    /* Things italicized would be your DBMS-specific structures and 
calls. */
    void
    Ns_PdDbOpen(void *handle, char *openArgs) {
        DBMSState       *state = (DBMSState *) handle;
        int             status = NS_ERROR;
        char            errbuf[ERRBUF_SIZE];
        Ns_PdLog(Trace, "open:");
        Ns_PdParseOpenArgs(openArgs, &state->datasource, 
    &state->user, &state->password,
            &state->param);
        Ns_PdLog(Notice,
            "Connecting to datasource '%s' as user '%s' with password 
'%s' and param '%s'",
            state->datasource == NULL ? "NULL" : state->datasource,
            state->user == NULL ? "NULL" : state->user,
            state->password == NULL ? "NULL" : state->password,
            state->param == NULL ? "NULL" : state->param);
        errbuf[0] = '\0';
        if (state->datasource == NULL) {
            sprintf(errbuf, "Illustra proxy daemon received NULL 
    datasource");
            Ns_PdLog(Error, "NULL datasource in openargs");
        } else if ((sep = strchr(state->datasource, ':')) == NULL) {
            sprintf(errbuf, "Illustra proxy daemon received malformed 
datasource: %s",
                state->datasource);
            Ns_PdLog(Error, "Malformed datasource:  %s", 
    state->datasource);
        } else {
        /*initialize the state and open a connection to the database*/
        /* ... */
        if (status == NS_OK) {
            Ns_PdSendString(OK_STATUS);
        } else if (errbuf[0] != '\0') {
            Ns_PdSendString(errbuf);
        } else {
            Ns_PdSendException(state->exceptionCode, 
    state->exceptionMsg);
        }
    }

Top of Page

[ Previous ] [ Contents ] [ Index ] [ Next ]
Copyright © 1998-99 America Online, Inc.