#include <sql.h>
#include <sqlext.h>
#include <stdio.h>
#include "../../basext.h"
Go to the source code of this file.
Data Structures | |
struct | _odbcHANDLE |
struct | _odbcOBJECT |
Defines | |
#define | BYTE_TYPE_ALREADY_DEFINED 1 |
#define | ODBC_ERROR_NOCN 0x00081001 |
#define | ODBC_ERROR_BDCN 0x00081002 |
#define | ODBC_ERROR_CREF 0x00081003 |
#define | ODBC_ERROR_EXEC 0x00081004 |
#define | ODBC_ERROR_NORS 0x00081005 |
#define | ODBC_ERROR_LVAL 0x00081006 |
#define | GET_DB_HANDLE |
#define | CONFLEN 100 |
#define | CONFROOT "odbc.connections." |
#define | MAXKL 20 |
Typedefs | |
typedef _odbcHANDLE | odbcHANDLE |
typedef _odbcHANDLE * | podbcHANDLE |
typedef _odbcOBJECT | odbcOBJECT |
typedef _odbcOBJECT * | podbcOBJECT |
Functions | |
besSUB_ERRMSG | switch (iError) |
besEND besVERSION_NEGOTIATE | return (int) |
INITLOCK | if (iFirst) |
if (besMODULEPOINTER==NULL) | |
SQLFreeHandle (SQL_HANDLE_ENV, p->hEnv) | |
static int | _GetData (pSupportTable pSt, LEFTVALUE Lval, podbcHANDLE q, long i, long j) |
besFUNCTION (odbc_fetcharray) | |
if (!(SQL_SUCCEEDED(ret))) | |
for (i=0;i< q->num_fields;i++) | |
LONGVALUE (besRETURNVALUE) | |
besEND | besFUNCTION (odbc_fetchhash) |
besEND | besFUNCTION (odbc_affected_rows) |
besDEREFERENCE (Argument) | |
if (!Argument) return EX_ERROR_TOO_FEW_ARGUMENTS | |
if (if ret==SQL_ERROR) | |
if (Argument) | |
if (pszDataSourceName) | |
if (pH==NULL) | |
strcpy (szConfigPath, CONFROOT) | |
if (STRLEN(Argument) > CONFLEN-strlen(CONFROOT)-MAXKL) return ODBC_ERROR_BDCN | |
memcpy (pszConf, STRINGVALUE(Argument), STRLEN(Argument)) | |
strcpy (pszConf,"dsn") | |
strcpy (pszConf,"user") | |
strcpy (pszConf,"password") | |
if (pH->hStmt=NULL==pszDataSourceName||NULL==pszUser||NULL==pszPassword) | |
Variables | |
return Unknown | error |
return | lTC |
besEND besSUB_START podbcOBJECT | p |
SQLRETURN | ret |
INITUNLO | besMODULEPOINTER = besALLOC(sizeof(odbcOBJECT)) |
return | |
* | Lval = besNEWARRAY(0,q->num_fields-1) |
if Lval return | COMMAND_ERROR_MEMORY_LOW |
ret = SQLFetch(q->hStmt) | |
besALLOC_RETURN_LONG | |
ret = SQLFetch(q->hStmt) | |
* | Lval = besNEWARRAY(0,2*q->num_fields-1) |
if Lval return | COMMAND_ERROR_MEMORY_LOW |
besALLOC_RETURN_LONG | |
Argument = besARGUMENT(2) | |
Argument = besCONVERT2STRING(Argument) | |
ret = SQLAllocHandle(SQL_HANDLE_STMT,q->hConn,&(q->hStmt)) | |
else | pszDataSourceName = NULL |
Argument = besARGUMENT(2) | |
else | pszUser = NULL |
Argument = besARGUMENT(3) | |
else | pszPassword = NULL |
ret | |
pH | hStmt = NULL |
SQLRETURN | ret |
char * | pszDataSourceName |
char * | pszUser |
char * | pszPassword |
podbcOBJECT | p |
char | szConfigPath [CONFLEN] |
char * | pszConf |
char * | pszCname |
podbcHANDLE | pH |
p = (podbcOBJECT)besMODULEPOINTER | |
pH = besALLOC(sizeof(odbcHANDLE)) | |
else return | ODBC_ERROR_NOCN |
pszConf = szConfigPath + strlen(szConfigPath) | |
pszConf = STRLEN(Argument) | |
* | pszConf = '.' |
pszDataSourceName = besCONFIG(szConfigPath) | |
pszUser = besCONFIG(szConfigPath) | |
pszPassword = besCONFIG(szConfigPath) |
|
Definition at line 15 of file interface.c. |
|
Definition at line 766 of file interface.c. |
|
Definition at line 767 of file interface.c. |
|
Value: p = (podbcOBJECT)besMODULEPOINTER;\ Argument = besARGUMENT(1);\ besDEREFERENCE(Argument);\ if( ! Argument )return EX_ERROR_TOO_FEW_ARGUMENTS;\ Argument = besCONVERT2LONG(Argument);\ q = besHandleGetPointer(p->HandleArray,LONGVALUE(Argument));\ if( q == NULL )return COMMAND_ERROR_ARGUMENT_RANGE; Definition at line 198 of file interface.c. |
|
Definition at line 768 of file interface.c. |
|
Definition at line 81 of file interface.c. Referenced by switch(). |
|
Definition at line 83 of file interface.c. Referenced by switch(). |
|
Definition at line 85 of file interface.c. Referenced by _GetData(), and switch(). |
|
Definition at line 89 of file interface.c. Referenced by switch(). |
|
ODBC Database Connection Module This module implements ODBC interface to connect to relational databases. Using this module you can use SQL RDBMS implementations from Windows/Unix/Linux platform independant of the actual database system. Though this module does not deliver all functions of the ODBC system it does implement most of the functions that are needed to write SQL based applications. You can connect to ODBC databases, disconnect, issue SQL commands and retrieve the data resulted by the queries. To use this module from a BASIC program you have to include the file T<odbc.bas> with the line =verbatim import odbc.bas =noverbatim to have all the neccessary function defintiions. This file and the neccessary T<odbc.dll> (or T<odbc.so>) are installed in the include and in the modules directories on Windows. A typical BASIC application using this module first calls R<Connect> or R<RealConnect> to get a connection to the database. Then the program calls R<Query> to execute SQL queries, altering the database and R<FetchHash> and/or R<FetchArray> to get the result of queries. Finally the program optionally calls R<Close> to close the connection. (Calling R<Close> is optional. R<Close> is automatically called for each opened database connection when the interpreter finishes.) The underlying ODBC system layer implements connection pooling on process level. Thus there is no need to use the ScriptBasic resource pooling module as it is done by the MySQL module. (By the time I write this the ScriptBasic resource pool support module is still experimental, and so is the MySQL module interface utilizing it.) When the ODBC module is initialized the module requests the underlying ODBC layer to perform process level connection pooling. The module also implements the multi-thread interface functions that allow the module to remain in memory if used in multi-thread application. The module raises module specific errors. For more information see R<Error>. Definition at line 79 of file interface.c. Referenced by switch(). |
|
Definition at line 87 of file interface.c. Referenced by switch(). |
|
|
|
|
|
|
|
|
|
Definition at line 208 of file interface.c. References COMMAND_ERROR_MEMORY_LOW, COMMAND_ERROR_SUCCESS, memcpy(), NULL, ODBC_ERROR_EXEC, q, and STRINGVALUE(). |
|
|
|
=section AffectedRows =H AffectedRows =verbatim R = ODBC::AffectedRows(DB) =noverbatim Use this function to get the number of rows affected by a previous T<UPDATE>, T<DELETE> or T<INSERT> command. The function returns undefined number in case the last executed was none of the above command types. The underlying ODBC function this function calls is T<SQLRowCount>. Definition at line 471 of file interface.c. References NULL, q, and SQLFreeHandle(). |
|
=section FetchHash =H FetchHash =verbatim R = ODBC::FetchHash(DB,arr) =noverbatim Use this function to fetch one row from the results after a successfully executed T<SELECT> statement. The first argument to the function is T<DB> the database handle. The second argument should be a variable. This variable will hold the hash-array containing the data of the actual row. The array is indexed from zero to T<2*n-1> where T<n> is the number of columns in the result set. Every even element (starting with index zero) will hold the name of a column and the next odd element of the array will hold the value of the column. This is according to the storage strategy of ScriptBasic for hashes. After the successful execution of this function you will be able to access the value of the column named T<"column"> with the syntax T<arr{"column"}>. Note however that column names in SQL are usually case insensitive, but ScriptBasic hash indexing is case sensitive. Use consecutive calls to this fucntion to get the rows of the result one after the other. You can mix consecutive calls to T<FetchHash> and R<FetchArray>. The function returns T<-1> (TRUE) if fetching a row of data was successful or T<0> (FALSE) if there are no more rows in the dataset. In the latter case T<arr> will be T<undef>. See also R<FetchArray>. This function calls the ODBC functions T<SQLFetch>, T<SQLDescribeCol>, T<SQLGetData>. Definition at line 357 of file interface.c. References besRETURNVALUE, and COMMAND_ERROR_SUCCESS. |
|
=section FetchArray =H FetchArray =verbatim R = ODBC::FetchArray(DB,arr) =noverbatim Use this function to fetch one row from the results after a successfully executed T<SELECT> statement. The first argument to the function is T<DB> the database handle. The second argument should be a variable. This variable will hold the array containing the data of the actual row. The array is indexed from zero to T<n-1> where T<n> is the number of columns in the result set. Use consecutive calls to this fucntion to get the rwos of the result one after the other. You can mix consecutive calls to R<FetchHash> and T<FetchArray>. The function returns T<-1> (TRUE) if fetching a row of data was successful or T<0> (FALSE) if there are no more rows in the dataset. In the latter case T<arr> will be T<undef>. See also R<FetchHash> This function calls the ODBC functions T<SQLFetch>, T<SQLDescribeCol>, T<SQLGetData>. Definition at line 275 of file interface.c. References besRETURNVALUE, and COMMAND_ERROR_SUCCESS. |
|
Definition at line 318 of file interface.c. |
|
Definition at line 810 of file interface.c. |
|
|
|
Definition at line 776 of file interface.c. |
|
Definition at line 693 of file interface.c. |
|
Definition at line 675 of file interface.c. References Argument, besCONVERT2ZCHAR(), and pszUser. |
|
Definition at line 566 of file interface.c. |
|
|
|
Definition at line 312 of file interface.c. References besALLOC_RETURN_LONG, besRETURNVALUE, COMMAND_ERROR_SUCCESS, and LONGVALUE(). |
|
Definition at line 170 of file interface.c. |
|
Definition at line 159 of file interface.c. References NULL. |
|
|
|
|
|
Definition at line 122 of file interface.c. |
|
Referenced by besFUNCTION(). |
|
|
|
|
|
|
|
|
|
=H Error Codes The module raises error in case when there is some problem with the underlying database handling. The error codes the module may raise: =itemize =item 0x00081001 there is no such connection name =item 0x00081002 there is some problem with the connection name. This is an error in the configuration file. =item 0x00081003 the connection was refused by the database. =item 0x00081004 query execution error. =item 0x00081005 the program tries to call R<FetchArray> or R<Fetchhash> without a preceeding query execution. =item 0x00081006 the second argument of a fetch does not evaluate to left value. =noitemize Definition at line 110 of file interface.c. References ODBC_ERROR_BDCN, ODBC_ERROR_CREF, ODBC_ERROR_EXEC, ODBC_ERROR_LVAL, ODBC_ERROR_NOCN, and ODBC_ERROR_NORS. |
|
Definition at line 681 of file interface.c. |
|
Definition at line 673 of file interface.c. |
|
Definition at line 563 of file interface.c. |
|
Definition at line 559 of file interface.c. |
|
Definition at line 452 of file interface.c. |
|
Definition at line 323 of file interface.c. |
|
Definition at line 169 of file interface.c. |
|
Definition at line 412 of file interface.c. |
|
Definition at line 308 of file interface.c. |
|
Definition at line 118 of file interface.c. |
|
Definition at line 692 of file interface.c. |
|
Definition at line 151 of file interface.c. |
|
Definition at line 411 of file interface.c. |
|
Definition at line 307 of file interface.c. |
|
Definition at line 786 of file interface.c. |
|
Definition at line 773 of file interface.c. |
|
Definition at line 765 of file interface.c. |
|
Definition at line 155 of file interface.c. |
|
Definition at line 775 of file interface.c. |
|
Definition at line 771 of file interface.c. |
|
Definition at line 770 of file interface.c. |
|
Definition at line 795 of file interface.c. |
|
Definition at line 794 of file interface.c. |
|
Definition at line 791 of file interface.c. |
|
Definition at line 769 of file interface.c. |
|
Definition at line 799 of file interface.c. |
|
Definition at line 764 of file interface.c. |
|
Definition at line 670 of file interface.c. |
|
Definition at line 807 of file interface.c. |
|
Definition at line 764 of file interface.c. |
|
Definition at line 685 of file interface.c. |
|
Definition at line 803 of file interface.c. |
|
Definition at line 764 of file interface.c. |
|
Definition at line 677 of file interface.c. |
|
Definition at line 762 of file interface.c. |
|
Initial value: SQLConnect(pH->hConn, pszDataSourceName,(SQLSMALLINT)strlen(pszDataSourceName), pszUser,(SQLSMALLINT)strlen(pszUser), pszPassword,(SQLSMALLINT)strlen(pszPassword)) Definition at line 688 of file interface.c. |
|
Definition at line 565 of file interface.c. |
|
Definition at line 404 of file interface.c. |
|
Definition at line 311 of file interface.c. |
|
Definition at line 156 of file interface.c. |
|
Definition at line 195 of file interface.c. |
|
Definition at line 769 of file interface.c. |