#ifndef WSCDBDRV_H
#define WSCDBDRV_H

#include <stdio.h>

#include <WScom.h>
#include <WSCvariant.h>
#include <WSCdb.h>

class WSCdbDrvRecord;

class WSCdbDrvDatabase
{
protected:
	void* _this;
public:
	WSDLEX32 WSCdbDrvDatabase();
	WSDLEX32 virtual ~WSCdbDrvDatabase();
	
	WSDLEX32 virtual long    open(char* host, char* uid, char* pwd, char* dbname, char* port = NULL);
	WSDLEX32 virtual long    close();
	WSDLEX32 virtual long    beginTran();
	WSDLEX32 virtual long    commitTran();
	WSDLEX32 virtual long    abortTran();
	WSDLEX32 virtual long    sqlExecute(const char* stmt);
	WSDLEX32 virtual WSCbool isOpen();
	WSDLEX32 virtual void    getErrorMsg(char* szState, char* szMsg);
	WSDLEX32 virtual void    getErrorMsg(char* szMsg,long size);
	WSDLEX32 virtual void    setEncode(long code);
	WSDLEX32 virtual long    getEncode();

private:
	WSDLEX32 void getError();

public:
	WSDLEX32 void setThisPtr(void*);
	WSDLEX32 void* getThisPtr();

};

class WSCdbDrvRecord
{
public:
	WSDLEX32 WSCdbDrvRecord(WSCdbDrvDatabase* pDatabase);
	WSDLEX32 virtual ~WSCdbDrvRecord();
	WSDLEX32 virtual long    open(const char* stmt);
	WSDLEX32 virtual long    open(const char* stmt, short eCousor, short eAccess = WSCDB_SQL_CONCUR_LOCK);
	WSDLEX32 virtual long    close();
	WSDLEX32 virtual WSCbool isEOF();
	WSDLEX32 virtual WSCbool isOpen();
	WSDLEX32 virtual long    getColValue(long index, WSCvariant* var);
	WSDLEX32 virtual long    getColValue(const char* name, WSCvariant* var);
	WSDLEX32 virtual long    getColStringValue(long index, char* var);
	WSDLEX32 virtual long    getColStringValue(const char* name, char* var);
	WSDLEX32 virtual long    setColValue(long index, WSCvariant var);
	WSDLEX32 virtual long    setColValue(const char* name, WSCvariant var);
	WSDLEX32 virtual long    edit();
	WSDLEX32 virtual long    update();
	WSDLEX32 virtual long    addnew();
	WSDLEX32 virtual long    deleterow();
	WSDLEX32 virtual long    moveNext();
	WSDLEX32 virtual long    movePrevious();
	WSDLEX32 virtual long    moveFirst();
	WSDLEX32 virtual long    moveLast();
	WSDLEX32 virtual long    getColName(long index, char* name);
	WSDLEX32 virtual long    getColIndex(const char* name);
	WSDLEX32 virtual long    getColType(long index);
	WSDLEX32 virtual long    getColType(const char* name);
	WSDLEX32 virtual long    getColLength(long index);
	WSDLEX32 virtual long    getColLength(const char* name);
	WSDLEX32 virtual long    getRowCount();
	WSDLEX32 virtual long    getColCount();
	WSDLEX32 virtual void    getErrorMsg(char* szState, char* szMsg);
	WSDLEX32 virtual WSCstring getErrorMessage();
	WSDLEX32 virtual long    isNull(long index);
	WSDLEX32 virtual long    isNull(const char* name);

private:
	void Cleanup(WSCdbDrvDatabase* pDatabase);
	long BindCols();
	void ReleaseCols();
	void getValue(int index, WSCvariant* var);
	void setValue(int index, WSCvariant* var);
	void getError();

};

#endif		// WSCDBDRV_H

