65.9K
CodeProject is changing. Read more.
Home

C++ wrapper for Sybase's OPENCLIENT Interface

starIconstarIcon
emptyStarIcon
starIcon
emptyStarIconemptyStarIcon

2.33/5 (5 votes)

Sep 28, 2002

viewsIcon

54741

downloadIcon

586

This article will provide a cross platform C++ wrapper for Sybase's OPENCLIENT interface.

Introduction

With this C++ wrapper, you can easily do the following:

  • Connect/disconnect to a Sybase server;
  • Execute SQL select/insert/update/delete commands;
  • Store the query result in a simple linked list;

This project is a cross platform implementation.

class  ObList ;
class  Record ;
class  RecordSet;
int Connect();
int Connect(char *user, char *pass, char *service);
void DisConnect();
int ExecCommand(char* cmdbuf);

Examples:

#include <stdio.h>
#include "dbclient.h"

int main(int argc, char* argv[])
{
    Connect("sybase11","sa","");
    RecordSet set;
    set.Open("select * from EMP");
    for(int k=0;k<set.GetRecordsCount();k++)
    {
        Record *pRec=set.GetRecord(k);
        for(int l=0;l<pRec->GetFieldsCount();l++)
        {
            printf("%s",pRec->GetFieldValue(l));
            if(l==(pRec->GetFieldsCount()-1))
                printf("\n");
            else
                printf("\t");
        }
    }

    DisConnect();
    return 0;
}

If you are interested in this article, and want to get details, contact me at lihaijian@sina.com or ema13@dongfang-china.com.