Commit 296e7ba2 authored by Bruce Momjian's avatar Bruce Momjian

ODBC source code cleanup patch. Should match rest of PostgreSQL code better.

parent 062a79a9
/* Module: bind.c
/*-------
* Module: bind.c
*
* Description: This module contains routines related to binding
* columns and parameters.
......@@ -9,7 +10,7 @@
* SQLParamOptions(NI)
*
* Comments: See "notice.txt" for copyright and license information.
*
*-------
*/
#ifdef HAVE_CONFIG_H
......@@ -33,8 +34,8 @@
#include "sqlext.h"
#endif
/* Bind parameters on a statement handle */
/* Bind parameters on a statement handle */
RETCODE SQL_API
SQLBindParameter(
HSTMT hstmt,
......@@ -112,8 +113,8 @@ SQLBindParameter(
}
}
ipar--; /* use zero based column numbers for the
* below part */
/* use zero based column numbers for the below part */
ipar--;
/* store the given info */
stmt->parameters[ipar].buflen = cbValueMax;
......@@ -158,7 +159,6 @@ SQLBindParameter(
return SQL_SUCCESS;
}
/* - - - - - - - - - */
/* Associate a user-supplied buffer with a database column. */
RETCODE SQL_API
......@@ -197,7 +197,6 @@ SQLBindCol(
/* If the bookmark column is being bound, then just save it */
if (icol == 0)
{
if (rgbValue == NULL)
{
stmt->bookmark.buffer = NULL;
......@@ -220,10 +219,12 @@ SQLBindCol(
return SQL_SUCCESS;
}
/* allocate enough bindings if not already done */
/* Most likely, execution of a statement would have setup the */
/* necessary bindings. But some apps call BindCol before any */
/* statement is executed. */
/*
* Allocate enough bindings if not already done.
* Most likely, execution of a statement would have setup the
* necessary bindings. But some apps call BindCol before any
* statement is executed.
*/
if (icol > stmt->bindings_allocated)
extend_bindings(stmt, icol);
......@@ -236,8 +237,8 @@ SQLBindCol(
return SQL_ERROR;
}
icol--; /* use zero based col numbers from here
* out */
/* use zero based col numbers from here out */
icol--;
/* Reset for SQLGetData */
stmt->bindings[icol].data_left = -1;
......@@ -264,15 +265,15 @@ SQLBindCol(
return SQL_SUCCESS;
}
/* - - - - - - - - - */
/* Returns the description of a parameter marker. */
/* This function is listed as not being supported by SQLGetFunctions() because it is */
/* used to describe "parameter markers" (not bound parameters), in which case, */
/* the dbms should return info on the markers. Since Postgres doesn't support that, */
/* it is best to say this function is not supported and let the application assume a */
/* data type (most likely varchar). */
/*
* Returns the description of a parameter marker.
* This function is listed as not being supported by SQLGetFunctions() because it is
* used to describe "parameter markers" (not bound parameters), in which case,
* the dbms should return info on the markers. Since Postgres doesn't support that,
* it is best to say this function is not supported and let the application assume a
* data type (most likely varchar).
*/
RETCODE SQL_API
SQLDescribeParam(
HSTMT hstmt,
......@@ -323,10 +324,8 @@ SQLDescribeParam(
return SQL_SUCCESS;
}
/* - - - - - - - - - */
/* Sets multiple values (arrays) for the set of parameter markers. */
RETCODE SQL_API
SQLParamOptions(
HSTMT hstmt,
......@@ -341,15 +340,16 @@ SQLParamOptions(
return SQL_ERROR;
}
/* - - - - - - - - - */
/* This function should really talk to the dbms to determine the number of */
/* "parameter markers" (not bound parameters) in the statement. But, since */
/* Postgres doesn't support that, the driver should just count the number of markers */
/* and return that. The reason the driver just can't say this function is unsupported */
/* like it does for SQLDescribeParam is that some applications don't care and try */
/* to call it anyway. */
/* If the statement does not have parameters, it should just return 0. */
/*
* This function should really talk to the dbms to determine the number of
* "parameter markers" (not bound parameters) in the statement. But, since
* Postgres doesn't support that, the driver should just count the number of markers
* and return that. The reason the driver just can't say this function is unsupported
* like it does for SQLDescribeParam is that some applications don't care and try
* to call it anyway.
* If the statement does not have parameters, it should just return 0.
*/
RETCODE SQL_API
SQLNumParams(
HSTMT hstmt,
......@@ -387,10 +387,8 @@ SQLNumParams(
}
else
{
for (i = 0; i < strlen(stmt->statement); i++)
{
if (stmt->statement[i] == '?' && !in_quote)
(*pcpar)++;
else
......@@ -399,12 +397,12 @@ SQLNumParams(
in_quote = (in_quote ? FALSE : TRUE);
}
}
return SQL_SUCCESS;
}
}
/********************************************************************
/*
* Bindings Implementation
*/
BindInfoClass *
......@@ -428,6 +426,7 @@ create_empty_bindings(int num_columns)
return new_bindings;
}
void
extend_bindings(StatementClass *stmt, int num_columns)
{
......@@ -437,11 +436,12 @@ extend_bindings(StatementClass *stmt, int num_columns)
mylog("%s: entering ... stmt=%u, bindings_allocated=%d, num_columns=%d\n", func, stmt, stmt->bindings_allocated, num_columns);
/* if we have too few, allocate room for more, and copy the old */
/* entries into the new structure */
/*
* if we have too few, allocate room for more, and copy the old
* entries into the new structure
*/
if (stmt->bindings_allocated < num_columns)
{
new_bindings = create_empty_bindings(num_columns);
if (!new_bindings)
{
......@@ -466,11 +466,12 @@ extend_bindings(StatementClass *stmt, int num_columns)
stmt->bindings = new_bindings;
stmt->bindings_allocated = num_columns;
}
/* There is no reason to zero out extra bindings if there are */
/* more than needed. If an app has allocated extra bindings, */
/* let it worry about it by unbinding those columns. */
/*
* There is no reason to zero out extra bindings if there are
* more than needed. If an app has allocated extra bindings,
* let it worry about it by unbinding those columns.
*/
/* SQLBindCol(1..) ... SQLBindCol(10...) # got 10 bindings */
/* SQLExecDirect(...) # returns 5 cols */
......
/* Module: columninfo.c
/*-------
* Module: columninfo.c
*
* Description: This module contains routines related to
* reading and storing the field information from a query.
......@@ -8,7 +9,7 @@
* API functions: none
*
* Comments: See "notice.txt" for copyright and license information.
*
*-------
*/
#include "columninfo.h"
......@@ -37,6 +38,7 @@ CI_Constructor()
return rv;
}
void
CI_Destructor(ColumnInfoClass *self)
{
......@@ -45,10 +47,12 @@ CI_Destructor(ColumnInfoClass *self)
free(self);
}
/* Read in field descriptions.
If self is not null, then also store the information.
If self is null, then just read, don't store.
*/
/*
* Read in field descriptions.
* If self is not null, then also store the information.
* If self is null, then just read, don't store.
*/
char
CI_read_fields(ColumnInfoClass *self, ConnectionClass *conn)
{
......@@ -71,14 +75,12 @@ CI_read_fields(ColumnInfoClass *self, ConnectionClass *conn)
mylog("num_fields = %d\n", new_num_fields);
if (self)
{ /* according to that allocate memory */
/* according to that allocate memory */
CI_set_num_fields(self, new_num_fields);
}
/* now read in the descriptions */
for (lf = 0; lf < new_num_fields; lf++)
{
SOCK_get_string(sock, new_field_name, 2 * MAX_COLUMN_LEN);
new_adtid = (Oid) SOCK_get_int(sock, 4);
new_adtsize = (Int2) SOCK_get_int(sock, 2);
......@@ -86,7 +88,6 @@ CI_read_fields(ColumnInfoClass *self, ConnectionClass *conn)
/* If 6.4 protocol, then read the atttypmod field */
if (PG_VERSION_GE(conn, 6.4))
{
mylog("READING ATTTYPMOD\n");
new_atttypmod = (Int4) SOCK_get_int(sock, 4);
......@@ -107,7 +108,6 @@ CI_read_fields(ColumnInfoClass *self, ConnectionClass *conn)
}
void
CI_free_memory(ColumnInfoClass *self)
{
......@@ -143,6 +143,7 @@ CI_free_memory(ColumnInfoClass *self)
self->atttypmod = NULL;
}
void
CI_set_num_fields(ColumnInfoClass *self, int new_num_fields)
{
......@@ -158,11 +159,11 @@ CI_set_num_fields(ColumnInfoClass *self, int new_num_fields)
self->atttypmod = (Int4 *) malloc(sizeof(Int4) * self->num_fields);
}
void
CI_set_field_info(ColumnInfoClass *self, int field_num, char *new_name,
Oid new_adtid, Int2 new_adtsize, Int4 new_atttypmod)
{
/* check bounds */
if ((field_num < 0) || (field_num >= self->num_fields))
return;
......
This diff is collapsed.
This diff is collapsed.
/* Module: dlg_specific.c
/*-------
* Module: dlg_specific.c
*
* Description: This module contains any specific code for handling
* dialog boxes such as driver/datasource options. Both the
......@@ -12,7 +13,7 @@
* API functions: none
*
* Comments: See "notice.txt" for copyright and license information.
*
*-------
*/
/* Multibyte support Eiji Tokuya 2001-03-15 */
......@@ -50,11 +51,11 @@
extern GLOBAL_VALUES globals;
#ifdef WIN32
void
SetDlgStuff(HWND hdlg, ConnInfo *ci)
{
/*
* If driver attribute NOT present, then set the datasource name and
* description
......@@ -72,6 +73,7 @@ SetDlgStuff(HWND hdlg, ConnInfo *ci)
SetDlgItemText(hdlg, IDC_PORT, ci->port);
}
void
GetDlgStuff(HWND hdlg, ConnInfo *ci)
{
......@@ -85,7 +87,6 @@ GetDlgStuff(HWND hdlg, ConnInfo *ci)
}
int CALLBACK
driver_optionsProc(HWND hdlg,
WORD wMsg,
......@@ -141,7 +142,6 @@ driver_optionsProc(HWND hdlg,
switch (GET_WM_COMMAND_ID(wParam, lParam))
{
case IDOK:
globals.commlog = IsDlgButtonChecked(hdlg, DRV_COMMLOG);
globals.disable_optimizer = IsDlgButtonChecked(hdlg, DRV_OPTIMIZER);
globals.ksqo = IsDlgButtonChecked(hdlg, DRV_KSQO);
......@@ -228,12 +228,12 @@ driver_optionsProc(HWND hdlg,
break;
}
}
return FALSE;
}
int CALLBACK
ds_optionsProc(HWND hdlg,
WORD wMsg,
......@@ -267,11 +267,9 @@ ds_optionsProc(HWND hdlg,
else if (strncmp(ci->protocol, PG63, strlen(PG63)) == 0)
CheckDlgButton(hdlg, DS_PG63, 1);
else
/* latest */
/* latest */
CheckDlgButton(hdlg, DS_PG64, 1);
CheckDlgButton(hdlg, DS_SHOWOIDCOLUMN, atoi(ci->show_oid_column));
CheckDlgButton(hdlg, DS_FAKEOIDINDEX, atoi(ci->fake_oid_index));
CheckDlgButton(hdlg, DS_ROWVERSIONING, atoi(ci->row_versioning));
......@@ -283,7 +281,6 @@ ds_optionsProc(HWND hdlg,
SetDlgItemText(hdlg, DS_CONNSETTINGS, ci->conn_settings);
break;
case WM_COMMAND:
switch (GET_WM_COMMAND_ID(wParam, lParam))
{
......@@ -292,9 +289,7 @@ ds_optionsProc(HWND hdlg,
EnableWindow(GetDlgItem(hdlg, DS_FAKEOIDINDEX), IsDlgButtonChecked(hdlg, DS_SHOWOIDCOLUMN));
return TRUE;
case IDOK:
ci = (ConnInfo *) GetWindowLong(hdlg, DWL_USER);
mylog("IDOK: got ci = %u\n", ci);
......@@ -307,7 +302,7 @@ ds_optionsProc(HWND hdlg,
else if (IsDlgButtonChecked(hdlg, DS_PG63))
strcpy(ci->protocol, PG63);
else
/* latest */
/* latest */
strcpy(ci->protocol, PG64);
sprintf(ci->show_system_tables, "%d", IsDlgButtonChecked(hdlg, DS_SHOWSYSTEMTABLES));
......@@ -321,7 +316,6 @@ ds_optionsProc(HWND hdlg,
/* Datasource Connection Settings */
GetDlgItemText(hdlg, DS_CONNSETTINGS, ci->conn_settings, sizeof(ci->conn_settings));
/* fall through */
case IDCANCEL:
......@@ -335,6 +329,7 @@ ds_optionsProc(HWND hdlg,
#endif /* WIN32 */
void
makeConnectString(char *connect_string, ConnInfo *ci)
{
......@@ -365,10 +360,10 @@ makeConnectString(char *connect_string, ConnInfo *ci)
encoded_conn_settings);
}
void
copyAttributes(ConnInfo *ci, char *attribute, char *value)
{
if (stricmp(attribute, "DSN") == 0)
strcpy(ci->dsn, value);
......@@ -415,9 +410,9 @@ copyAttributes(ConnInfo *ci, char *attribute, char *value)
}
mylog("copyAttributes: DSN='%s',server='%s',dbase='%s',user='%s',passwd='%s',port='%s',onlyread='%s',protocol='%s', conn_settings='%s')\n", ci->dsn, ci->server, ci->database, ci->username, ci->password, ci->port, ci->onlyread, ci->protocol, ci->conn_settings);
}
void
getDSNdefaults(ConnInfo *ci)
{
......@@ -450,8 +445,10 @@ getDSNinfo(ConnInfo *ci, char overwrite)
char *DSN = ci->dsn;
char encoded_conn_settings[LARGE_REGISTRY_LEN];
/* If a driver keyword was present, then dont use a DSN and return. */
/* If DSN is null and no driver, then use the default datasource. */
/*
* If a driver keyword was present, then dont use a DSN and return.
* If DSN is null and no driver, then use the default datasource.
*/
if (DSN[0] == '\0')
{
if (ci->driver[0] != '\0')
......@@ -514,11 +511,9 @@ getDSNinfo(ConnInfo *ci, char overwrite)
if (ci->translation_option[0] == '\0' || overwrite)
SQLGetPrivateProfileString(DSN, INI_TRANSLATIONOPTION, "", ci->translation_option, sizeof(ci->translation_option), ODBC_INI);
/* Allow override of odbcinst.ini parameters here */
getGlobalDefaults(DSN, ODBC_INI, TRUE);
qlog("DSN info: DSN='%s',server='%s',port='%s',dbase='%s',user='%s',passwd='%s'\n",
DSN,
ci->server,
......@@ -546,7 +541,6 @@ getDSNinfo(ConnInfo *ci, char overwrite)
qlog(" translation_dll='%s',translation_option='%s'\n",
ci->translation_dll,
ci->translation_option);
}
......@@ -626,15 +620,15 @@ writeDSNinfo(ConnInfo *ci)
}
/* This function reads the ODBCINST.INI portion of
the registry and gets any driver defaults.
*/
/*
* This function reads the ODBCINST.INI portion of
* the registry and gets any driver defaults.
*/
void
getGlobalDefaults(char *section, char *filename, char override)
{
char temp[256];
/* Fetch Count is stored in driver section */
SQLGetPrivateProfileString(section, INI_FETCH, "",
temp, sizeof(temp), filename);
......@@ -648,7 +642,6 @@ getGlobalDefaults(char *section, char *filename, char override)
else if (!override)
globals.fetch_max = FETCH_MAX;
/* Socket Buffersize is stored in driver section */
SQLGetPrivateProfileString(section, INI_SOCKET, "",
temp, sizeof(temp), filename);
......@@ -657,7 +650,6 @@ getGlobalDefaults(char *section, char *filename, char override)
else if (!override)
globals.socket_buffersize = SOCK_BUFFER_SIZE;
/* Debug is stored in the driver section */
SQLGetPrivateProfileString(section, INI_DEBUG, "",
temp, sizeof(temp), filename);
......@@ -666,7 +658,6 @@ getGlobalDefaults(char *section, char *filename, char override)
else if (!override)
globals.debug = DEFAULT_DEBUG;
/* CommLog is stored in the driver section */
SQLGetPrivateProfileString(section, INI_COMMLOG, "",
temp, sizeof(temp), filename);
......@@ -675,7 +666,6 @@ getGlobalDefaults(char *section, char *filename, char override)
else if (!override)
globals.commlog = DEFAULT_COMMLOG;
/* Optimizer is stored in the driver section only */
SQLGetPrivateProfileString(section, INI_OPTIMIZER, "",
temp, sizeof(temp), filename);
......@@ -734,8 +724,6 @@ getGlobalDefaults(char *section, char *filename, char override)
else if (!override)
globals.cancel_as_freestmt = DEFAULT_CANCELASFREESTMT;
/* UseDeclareFetch is stored in the driver section only */
SQLGetPrivateProfileString(section, INI_USEDECLAREFETCH, "",
temp, sizeof(temp), filename);
......@@ -744,7 +732,6 @@ getGlobalDefaults(char *section, char *filename, char override)
else if (!override)
globals.use_declarefetch = DEFAULT_USEDECLAREFETCH;
/* Max Varchar Size */
SQLGetPrivateProfileString(section, INI_MAXVARCHARSIZE, "",
temp, sizeof(temp), filename);
......@@ -804,7 +791,6 @@ getGlobalDefaults(char *section, char *filename, char override)
/* Dont allow override of an override! */
if (!override)
{
/*
* ConnSettings is stored in the driver section and per datasource
* for override
......@@ -831,14 +817,14 @@ getGlobalDefaults(char *section, char *filename, char override)
strcpy(globals.protocol, temp);
else
strcpy(globals.protocol, DEFAULT_PROTOCOL);
}
}
/* This function writes any global parameters (that can be manipulated)
to the ODBCINST.INI portion of the registry
*/
/*
* This function writes any global parameters (that can be manipulated)
* to the ODBCINST.INI portion of the registry
*/
void
updateGlobals(void)
{
......
/* Module: drvconn.c
/*-------
* Module: drvconn.c
*
* Description: This module contains only routines related to
* implementing SQLDriverConnect.
......@@ -8,7 +9,7 @@
* API functions: SQLDriverConnect
*
* Comments: See "notice.txt" for copyright and license information.
*
*-------
*/
#ifdef HAVE_CONFIG_H
......@@ -110,9 +111,11 @@ SQLDriverConnect(
/* Parse the connect string and fill in conninfo for this hdbc. */
dconn_get_connect_attributes(connStrIn, ci);
/* If the ConnInfo in the hdbc is missing anything, */
/* this function will fill them in from the registry (assuming */
/* of course there is a DSN given -- if not, it does nothing!) */
/*
* If the ConnInfo in the hdbc is missing anything,
* this function will fill them in from the registry (assuming
* of course there is a DSN given -- if not, it does nothing!)
*/
getDSNinfo(ci, CONN_DONT_OVERWRITE);
/* Fill in any default parameters if they are not there. */
......@@ -147,7 +150,6 @@ dialog:
ci->port[0] == '\0' ||
password_required)
{
dialog_result = dconn_DoDialog(hwnd, ci);
if (dialog_result != SQL_SUCCESS)
return dialog_result;
......@@ -173,12 +175,11 @@ dialog:
ci->database[0] == '\0' ||
ci->port[0] == '\0')
{
/* (password_required && ci->password[0] == '\0')) */
/* (password_required && ci->password[0] == '\0')) */
return SQL_NO_DATA_FOUND;
}
/* do the actual connect */
retval = CC_connect(conn, password_required);
if (retval < 0)
......@@ -206,9 +207,9 @@ dialog:
return SQL_ERROR;
}
/*********************************************/
/* Create the Output Connection String */
/*********************************************/
/*
* Create the Output Connection String
*/
result = SQL_SUCCESS;
makeConnectString(connStrOut, ci);
......@@ -216,7 +217,6 @@ dialog:
if (szConnStrOut)
{
/*
* Return the completed string to the caller. The correct method
* is to only construct the connect string if a dialog was put up,
......@@ -247,6 +247,7 @@ dialog:
return result;
}
#ifdef WIN32
RETCODE
dconn_DoDialog(HWND hwnd, ConnInfo *ci)
......@@ -296,7 +297,6 @@ dconn_FDriverConnectProc(
SetWindowLong(hdlg, DWL_USER, lParam); /* Save the ConnInfo for
* the "OK" */
SetDlgStuff(hdlg, ci);
if (ci->database[0] == '\0')
......@@ -309,38 +309,29 @@ dconn_FDriverConnectProc(
SetFocus(GetDlgItem(hdlg, IDC_USER));
else if (ci->focus_password)
SetFocus(GetDlgItem(hdlg, IDC_PASSWORD));
break;
case WM_COMMAND:
switch (GET_WM_COMMAND_ID(wParam, lParam))
{
case IDOK:
ci = (ConnInfo *) GetWindowLong(hdlg, DWL_USER);
GetDlgStuff(hdlg, ci);
case IDCANCEL:
EndDialog(hdlg, GET_WM_COMMAND_ID(wParam, lParam) == IDOK);
return TRUE;
case IDC_DRIVER:
DialogBoxParam(s_hModule, MAKEINTRESOURCE(DLG_OPTIONS_DRV),
hdlg, driver_optionsProc, (LPARAM) NULL);
break;
case IDC_DATASOURCE:
ci = (ConnInfo *) GetWindowLong(hdlg, DWL_USER);
DialogBoxParam(s_hModule, MAKEINTRESOURCE(DLG_OPTIONS_DS),
hdlg, ds_optionsProc, (LPARAM) ci);
break;
}
}
......@@ -350,6 +341,7 @@ dconn_FDriverConnectProc(
#endif /* WIN32 */
void
dconn_get_connect_attributes(UCHAR FAR *connect_string, ConnInfo *ci)
{
......@@ -393,6 +385,5 @@ dconn_get_connect_attributes(UCHAR FAR *connect_string, ConnInfo *ci)
}
free(our_connect_string);
}
/* Module: environ.c
/*-------
* Module: environ.c
*
* Description: This module contains routines related to
* the environment, such as storing connection handles,
......@@ -9,7 +10,7 @@
* API functions: SQLAllocEnv, SQLFreeEnv, SQLError
*
* Comments: See "notice.txt" for copyright and license information.
*
*-------
*/
#include "environ.h"
......@@ -54,6 +55,7 @@ SQLAllocEnv(HENV FAR *phenv)
return SQL_SUCCESS;
}
RETCODE SQL_API
SQLFreeEnv(HENV henv)
{
......@@ -73,8 +75,8 @@ SQLFreeEnv(HENV henv)
return SQL_ERROR;
}
/* Returns the next SQL error information. */
/* Returns the next SQL error information. */
RETCODE SQL_API
SQLError(
HENV henv,
......@@ -208,24 +210,19 @@ SQLError(
case STMT_INVALID_CURSOR_POSITION:
strcpy(szSqlState, "S1109");
break;
case STMT_VALUE_OUT_OF_RANGE:
strcpy(szSqlState, "22003");
break;
case STMT_OPERATION_INVALID:
strcpy(szSqlState, "S1011");
break;
case STMT_EXEC_ERROR:
default:
strcpy(szSqlState, "S1000");
/* also a general error */
break;
}
mylog(" szSqlState = '%s', szError='%s'\n", szSqlState, szErrorMsg);
}
else
{
......@@ -237,10 +234,11 @@ SQLError(
szErrorMsg[0] = '\0';
mylog(" returning NO_DATA_FOUND\n");
return SQL_NO_DATA_FOUND;
}
return SQL_SUCCESS;
return SQL_SUCCESS;
}
else if (SQL_NULL_HDBC != hdbc)
{
......@@ -310,7 +308,6 @@ SQLError(
break;
case CONN_TRANSACT_IN_PROGRES:
strcpy(szSqlState, "S1010");
/*
* when the user tries to switch commit mode in a
* transaction
......@@ -324,18 +321,15 @@ SQLError(
case STMT_NOT_IMPLEMENTED_ERROR:
strcpy(szSqlState, "S1C00");
break;
case CONN_VALUE_OUT_OF_RANGE:
case STMT_VALUE_OUT_OF_RANGE:
strcpy(szSqlState, "22003");
break;
default:
strcpy(szSqlState, "S1000");
/* general error */
break;
}
}
else
{
......@@ -349,8 +343,8 @@ SQLError(
return SQL_NO_DATA_FOUND;
}
return SQL_SUCCESS;
return SQL_SUCCESS;
}
else if (SQL_NULL_HENV != henv)
{
......@@ -419,15 +413,10 @@ SQLError(
}
/*********************************************************************/
/*
* EnvironmentClass implementation
*/
EnvironmentClass
*
EnvironmentClass *
EN_Constructor(void)
{
EnvironmentClass *rv;
......@@ -451,8 +440,10 @@ EN_Destructor(EnvironmentClass *self)
mylog("in EN_Destructor, self=%u\n", self);
/* the error messages are static strings distributed throughout */
/* the source--they should not be freed */
/*
* the error messages are static strings distributed throughout
* the source--they should not be freed
*/
/* Free any connections belonging to this environment */
for (lf = 0; lf < MAX_CONNECTIONS; lf++)
......@@ -466,6 +457,7 @@ EN_Destructor(EnvironmentClass *self)
return rv;
}
char
EN_get_error(EnvironmentClass *self, int *number, char **message)
{
......@@ -481,6 +473,7 @@ EN_get_error(EnvironmentClass *self, int *number, char **message)
return 0;
}
char
EN_add_connection(EnvironmentClass *self, ConnectionClass *conn)
{
......@@ -504,6 +497,7 @@ EN_add_connection(EnvironmentClass *self, ConnectionClass *conn)
return FALSE;
}
char
EN_remove_connection(EnvironmentClass *self, ConnectionClass *conn)
{
......@@ -519,6 +513,7 @@ EN_remove_connection(EnvironmentClass *self, ConnectionClass *conn)
return FALSE;
}
void
EN_log_error(char *func, char *desc, EnvironmentClass *self)
{
......
/* Module: execute.c
/*-------
* Module: execute.c
*
* Description: This module contains routines related to
* preparing and executing an SQL statement.
......@@ -9,7 +10,7 @@
* SQLCancel, SQLNativeSql, SQLParamData, SQLPutData
*
* Comments: See "notice.txt" for copyright and license information.
*
*-------
*/
#ifdef HAVE_CONFIG_H
......@@ -126,14 +127,10 @@ SQLPrepare(HSTMT hstmt,
}
return SQL_SUCCESS;
}
/* - - - - - - - - - */
/* Performs the equivalent of SQLPrepare, followed by SQLExecute. */
RETCODE SQL_API
SQLExecDirect(
HSTMT hstmt,
......@@ -155,8 +152,10 @@ SQLExecDirect(
if (stmt->statement)
free(stmt->statement);
/* keep a copy of the un-parametrized statement, in case */
/* they try to execute this statement again */
/*
* keep a copy of the un-parametrized statement, in case
* they try to execute this statement again
*/
stmt->statement = make_string(szSqlStr, cbSqlStr, NULL);
if (!stmt->statement)
{
......@@ -170,9 +169,11 @@ SQLExecDirect(
stmt->prepare = FALSE;
/* If an SQLPrepare was performed prior to this, but was left in */
/* the premature state because an error occurred prior to SQLExecute */
/* then set the statement to finished so it can be recycled. */
/*
* If an SQLPrepare was performed prior to this, but was left in
* the premature state because an error occurred prior to SQLExecute
* then set the statement to finished so it can be recycled.
*/
if (stmt->status == STMT_PREMATURE)
stmt->status = STMT_FINISHED;
......@@ -195,6 +196,7 @@ SQLExecDirect(
return result;
}
/* Execute a prepared SQL statement */
RETCODE SQL_API
SQLExecute(
......@@ -206,7 +208,6 @@ SQLExecute(
int i,
retval;
mylog("%s: entering...\n", func);
if (!stmt)
......@@ -280,7 +281,6 @@ SQLExecute(
if ((stmt->prepare && stmt->status != STMT_READY) ||
(stmt->status != STMT_ALLOCATED && stmt->status != STMT_READY))
{
stmt->errornumber = STMT_STATUS_ERROR;
stmt->errormsg = "The handle does not point to a statement that is ready to be executed";
SC_log_error(func, "", stmt);
......@@ -288,7 +288,6 @@ SQLExecute(
return SQL_ERROR;
}
/* Check if statement has any data-at-execute parameters when it is not in SC_pre_execute. */
if (!stmt->pre_executing)
{
......@@ -336,15 +335,10 @@ SQLExecute(
mylog(" stmt_with_params = '%s'\n", stmt->stmt_with_params);
return SC_execute(stmt);
}
/* - - - - - - - - - */
RETCODE SQL_API
SQLTransact(
HENV henv,
......@@ -380,7 +374,6 @@ SQLTransact(
if (conn && conn->henv == henv)
if (SQLTransact(henv, (HDBC) conn, fType) != SQL_SUCCESS)
return SQL_ERROR;
}
return SQL_SUCCESS;
}
......@@ -388,15 +381,9 @@ SQLTransact(
conn = (ConnectionClass *) hdbc;
if (fType == SQL_COMMIT)
{
stmt_string = "COMMIT";
}
else if (fType == SQL_ROLLBACK)
{
stmt_string = "ROLLBACK";
}
else
{
conn->errornumber = CONN_INVALID_ARGUMENT_NO;
......@@ -408,7 +395,6 @@ SQLTransact(
/* If manual commit and in transaction, then proceed. */
if (!CC_is_in_autocommit(conn) && CC_is_in_trans(conn))
{
mylog("SQLTransact: sending on conn %d '%s'\n", conn, stmt_string);
res = CC_send_query(conn, stmt_string, NULL);
......@@ -433,7 +419,6 @@ SQLTransact(
return SQL_SUCCESS;
}
/* - - - - - - - - - */
RETCODE SQL_API
SQLCancel(
......@@ -464,8 +449,6 @@ SQLCancel(
*/
if (stmt->data_at_exec < 0)
{
/*
* MAJOR HACK for Windows to reset the driver manager's cursor
* state: Because of what seems like a bug in the Odbc driver
......@@ -507,14 +490,14 @@ SQLCancel(
stmt->put_data = FALSE;
return SQL_SUCCESS;
}
/* - - - - - - - - - */
/* Returns the SQL string as modified by the driver. */
/* Currently, just copy the input string without modification */
/* observing buffer limits and truncation. */
/*
* Returns the SQL string as modified by the driver.
* Currently, just copy the input string without modification
* observing buffer limits and truncation.
*/
RETCODE SQL_API
SQLNativeSql(
HDBC hdbc,
......@@ -564,11 +547,11 @@ SQLNativeSql(
return result;
}
/* - - - - - - - - - */
/* Supplies parameter data at execution time. Used in conjuction with */
/* SQLPutData. */
/*
* Supplies parameter data at execution time.
* Used in conjuction with SQLPutData.
*/
RETCODE SQL_API
SQLParamData(
HSTMT hstmt,
......@@ -636,11 +619,9 @@ SQLParamData(
CC_set_no_trans(stmt->hdbc);
}
stmt->lobj_fd = -1;
}
/* Done, now copy the params and then execute the statement */
if (stmt->data_at_exec == 0)
{
......@@ -675,11 +656,11 @@ SQLParamData(
return SQL_NEED_DATA;
}
/* - - - - - - - - - */
/* Supplies parameter data at execution time. Used in conjunction with */
/* SQLParamData. */
/*
* Supplies parameter data at execution time.
* Used in conjunction with SQLParamData.
*/
RETCODE SQL_API
SQLPutData(
HSTMT hstmt,
......@@ -701,7 +682,6 @@ SQLPutData(
return SQL_INVALID_HANDLE;
}
if (stmt->current_exec_param < 0)
{
stmt->errornumber = STMT_SEQUENCE_ERROR;
......@@ -714,7 +694,6 @@ SQLPutData(
if (!stmt->put_data)
{ /* first call */
mylog("SQLPutData: (1) cbValue = %d\n", cbValue);
stmt->put_data = TRUE;
......@@ -733,11 +712,9 @@ SQLPutData(
if (cbValue == SQL_NULL_DATA)
return SQL_SUCCESS;
/* Handle Long Var Binary with Large Objects */
if (current_param->SQLType == SQL_LONGVARBINARY)
{
/* begin transaction if needed */
if (!CC_is_in_trans(stmt->hdbc))
{
......@@ -775,8 +752,10 @@ SQLPutData(
return SQL_ERROR;
}
/* major hack -- to allow convert to see somethings there */
/* have to modify convert to handle this better */
/*
* major hack -- to allow convert to see somethings there
* have to modify convert to handle this better
*/
current_param->EXEC_buffer = (char *) &current_param->lobj_oid;
/* store the fd */
......@@ -791,11 +770,10 @@ SQLPutData(
retval = lo_write(stmt->hdbc, stmt->lobj_fd, rgbValue, cbValue);
mylog("lo_write: cbValue=%d, wrote %d bytes\n", cbValue, retval);
}
else
{ /* for handling fields */
{
/* for handling fields */
if (cbValue == SQL_NTS)
{
current_param->EXEC_buffer = strdup(rgbValue);
......@@ -841,25 +819,21 @@ SQLPutData(
}
}
}
else
{ /* calling SQLPutData more than once */
{
/* calling SQLPutData more than once */
mylog("SQLPutData: (>1) cbValue = %d\n", cbValue);
if (current_param->SQLType == SQL_LONGVARBINARY)
{
/* the large object fd is in EXEC_buffer */
retval = lo_write(stmt->hdbc, stmt->lobj_fd, rgbValue, cbValue);
mylog("lo_write(2): cbValue = %d, wrote %d bytes\n", cbValue, retval);
*current_param->EXEC_used += cbValue;
}
else
{
buffer = current_param->EXEC_buffer;
if (cbValue == SQL_NTS)
......@@ -880,11 +854,9 @@ SQLPutData(
/* reassign buffer incase realloc moved it */
current_param->EXEC_buffer = buffer;
}
else if (cbValue > 0)
{
old_pos = *current_param->EXEC_used;
*current_param->EXEC_used += cbValue;
......@@ -906,17 +878,14 @@ SQLPutData(
/* reassign buffer incase realloc moved it */
current_param->EXEC_buffer = buffer;
}
else
{
SC_log_error(func, "bad cbValue", stmt);
return SQL_ERROR;
}
}
}
return SQL_SUCCESS;
}
/* GetPrivateProfileString()
/*-------
* GetPrivateProfileString()
*
* approximate implementation of
* Windows NT System Services version of GetPrivateProfileString()
......@@ -15,6 +16,7 @@
* are allowed (that is an anachronism anyway)
* Added code to search for ODBC_INI file in users home directory on
* Unix
*-------
*/
#ifndef WIN32
......@@ -110,7 +112,6 @@ GetPrivateProfileString(char *theSection, /* section name */
aFile = (FILE *) (buf ? fopen(buf, PG_BINARY_R) : NULL);
}
aLength = (theDefault == NULL) ? 0 : strlen(theDefault);
if (theReturnBufferLength == 0 || theReturnBuffer == NULL)
......@@ -123,7 +124,6 @@ GetPrivateProfileString(char *theSection, /* section name */
if (aFile == NULL)
{
/* no ini file specified, return the default */
++aLength; /* room for NULL char */
aLength = theReturnBufferLength < aLength ?
theReturnBufferLength : aLength;
......@@ -132,7 +132,6 @@ GetPrivateProfileString(char *theSection, /* section name */
return aLength - 1;
}
while (fgets(aLine, sizeof(aLine), aFile) != NULL)
{
aLineLength = strlen(aLine);
......@@ -147,7 +146,6 @@ GetPrivateProfileString(char *theSection, /* section name */
break;
case '[': /* section marker */
if ((aString = strchr(aLine, ']')))
{
aStart = aLine + 1;
......@@ -159,30 +157,25 @@ GetPrivateProfileString(char *theSection, /* section name */
*(aString + 1) = '\0';
/* accept as matched if NULL key or exact match */
if (!theSection || !strcmp(aStart, theSection))
aSectionFound = TRUE;
else
aSectionFound = FALSE;
}
break;
default:
/* try to match value keys if in proper section */
if (aSectionFound)
{
/* try to match requested key */
if ((aString = aValue = strchr(aLine, '=')))
{
*aValue = '\0';
++aValue;
/* strip leading blanks in value field */
while (*aValue == ' ' && aValue < aLine + sizeof(aLine))
*aValue++ = '\0';
if (aValue >= aLine + sizeof(aLine))
......@@ -196,7 +189,6 @@ GetPrivateProfileString(char *theSection, /* section name */
aStart++;
/* strip trailing blanks from key */
if (aString)
{
while (--aString >= aStart && *aString == ' ')
......@@ -204,16 +196,13 @@ GetPrivateProfileString(char *theSection, /* section name */
}
/* see if key is matched */
if (theKey == NULL || !strcmp(theKey, aStart))
{
/* matched -- first, terminate value part */
aKeyFound = TRUE;
aLength = strlen(aValue);
/* remove trailing blanks from aValue if any */
aString = aValue + aLength - 1;
while (--aString > aValue && *aString == ' ')
......@@ -223,7 +212,6 @@ GetPrivateProfileString(char *theSection, /* section name */
}
/* unquote value if quoted */
if (aLength >= 2 && aValue[0] == '"' &&
aValue[aLength - 1] == '"')
{
......@@ -236,7 +224,6 @@ GetPrivateProfileString(char *theSection, /* section name */
else
{
/* single quotes allowed also... */
if (aLength >= 2 && aValue[0] == '\'' &&
aValue[aLength - 1] == '\'')
{
......@@ -247,13 +234,11 @@ GetPrivateProfileString(char *theSection, /* section name */
}
/* compute maximum length copyable */
aLineLength = (aLength <
theReturnBufferLength - aReturnLength) ? aLength :
theReturnBufferLength - aReturnLength;
/* do the copy to return buffer */
if (aLineLength)
{
strncpy(&theReturnBuffer[aReturnLength],
......@@ -270,11 +255,9 @@ GetPrivateProfileString(char *theSection, /* section name */
fclose(aFile);
aFile = NULL;
}
return aReturnLength > 0 ? aReturnLength - 1 : 0;
}
}
break;
}
}
......@@ -283,7 +266,8 @@ GetPrivateProfileString(char *theSection, /* section name */
fclose(aFile);
if (!aKeyFound)
{ /* key wasn't found return default */
{
/* key wasn't found return default */
++aLength; /* room for NULL char */
aLength = theReturnBufferLength < aLength ?
theReturnBufferLength : aLength;
......@@ -294,6 +278,7 @@ GetPrivateProfileString(char *theSection, /* section name */
return aReturnLength > 0 ? aReturnLength - 1 : 0;
}
DWORD
WritePrivateProfileString(char *theSection, /* section name */
char *theKey, /* write key name */
......@@ -304,8 +289,10 @@ WritePrivateProfileString(char *theSection, /* section name */
return 0;
}
#if 0
/* Ok. What the hell's the default behaviour for a null input buffer, and null
/*
* Ok. What the hell's the default behaviour for a null input buffer, and null
* section name. For now if either are null I ignore the request, until
* I find out different.
*/
......@@ -353,11 +340,12 @@ WritePrivateProfileString(char *theSection, /* section name */
if (ptr == NULL || *ptr == '\0')
ptr = "/home";
/* This doesn't make it so we find an ini file but allows normal */
/* processing to continue further on down. The likelihood is that */
/* the file won't be found and thus the default value will be */
/* returned. */
/* */
/*
* This doesn't make it so we find an ini file but allows normal
* processing to continue further on down. The likelihood is that
* the file won't be found and thus the default value will be
* returned.
*/
if (MAXPGPATH - 1 < strlen(ptr) + j)
{
if (MAXPGPATH - 1 < strlen(ptr))
......@@ -368,9 +356,10 @@ WritePrivateProfileString(char *theSection, /* section name */
sprintf(buf, "%s/%s", ptr, theIniFileName);
/* This code makes it so that a file in the users home dir */
/* overrides a the "default" file as passed in */
/* */
/*
* This code makes it so that a file in the users home dir
* overrides a the "default" file as passed in
*/
aFile = (FILE *) (buf ? fopen(buf, "r+") : NULL);
if (!aFile)
{
......@@ -380,13 +369,13 @@ WritePrivateProfileString(char *theSection, /* section name */
return 0;
}
aLength = strlen(theBuffer);
/* We have to search for theKey, because if it already */
/* exists we have to overwrite it. If it doesn't exist */
/* we just write a new line to the file. */
/* */
/*
* We have to search for theKey, because if it already
* exists we have to overwrite it. If it doesn't exist
* we just write a new line to the file.
*/
while (fgets(aLine, sizeof(aLine), aFile) != NULL)
{
aLineLength = strlen(aLine);
......@@ -401,7 +390,6 @@ WritePrivateProfileString(char *theSection, /* section name */
break;
case '[': /* section marker */
if ((aString = strchr(aLine, ']')))
{
*aString = '\0';
......@@ -411,13 +399,10 @@ WritePrivateProfileString(char *theSection, /* section name */
if (!strcmp(aLine + 1, theSection))
aSectionFound = TRUE;
}
break;
default:
/* try to match value keys if in proper section */
if (aSectionFound)
{
/* try to match requested key */
......@@ -428,7 +413,6 @@ WritePrivateProfileString(char *theSection, /* section name */
++aValue;
/* strip leading blanks in value field */
while (*aValue == ' ' && aValue < aLine + sizeof(aLine))
*aValue++ = '\0';
if (aValue >= aLine + sizeof(aLine))
......@@ -438,7 +422,6 @@ WritePrivateProfileString(char *theSection, /* section name */
aValue = "";
/* strip trailing blanks from key */
if (aString)
{
while (--aString >= aLine && *aString == ' ')
......@@ -446,7 +429,6 @@ WritePrivateProfileString(char *theSection, /* section name */
}
/* see if key is matched */
if (!strcmp(theKey, aLine))
{
keyFound = TRUE;
......@@ -460,7 +442,6 @@ WritePrivateProfileString(char *theSection, /* section name */
}
}
}
break;
}
}
......
This diff is collapsed.
/* Module: lobj.c
/*--------
* Module: lobj.c
*
* Description: This module contains routines related to manipulating
* large objects.
......@@ -8,13 +9,14 @@
* API functions: none
*
* Comments: See "notice.txt" for copyright and license information.
*
*--------
*/
#include "lobj.h"
#include "psqlodbc.h"
#include "connection.h"
Oid
lo_creat(ConnectionClass *conn, int mode)
{
......@@ -30,10 +32,9 @@ lo_creat(ConnectionClass *conn, int mode)
return 0; /* invalid oid */
else
return retval;
}
int
lo_open(ConnectionClass *conn, int lobjId, int mode)
{
......@@ -41,7 +42,6 @@ lo_open(ConnectionClass *conn, int lobjId, int mode)
int result_len;
LO_ARG argv[2];
argv[0].isint = 1;
argv[0].len = 4;
argv[0].u.integer = lobjId;
......@@ -59,6 +59,7 @@ lo_open(ConnectionClass *conn, int lobjId, int mode)
return fd;
}
int
lo_close(ConnectionClass *conn, int fd)
{
......@@ -66,17 +67,14 @@ lo_close(ConnectionClass *conn, int fd)
int retval,
result_len;
argv[0].isint = 1;
argv[0].len = 4;
argv[0].u.integer = fd;
if (!CC_send_function(conn, LO_CLOSE, &retval, &result_len, 1, argv, 1))
return -1;
else
return retval;
}
......@@ -86,7 +84,6 @@ lo_read(ConnectionClass *conn, int fd, char *buf, int len)
LO_ARG argv[2];
int result_len;
argv[0].isint = 1;
argv[0].len = 4;
argv[0].u.integer = fd;
......@@ -97,11 +94,11 @@ lo_read(ConnectionClass *conn, int fd, char *buf, int len)
if (!CC_send_function(conn, LO_READ, (int *) buf, &result_len, 0, argv, 2))
return -1;
else
return result_len;
}
int
lo_write(ConnectionClass *conn, int fd, char *buf, int len)
{
......@@ -109,7 +106,6 @@ lo_write(ConnectionClass *conn, int fd, char *buf, int len)
int retval,
result_len;
if (len <= 0)
return 0;
......@@ -123,11 +119,11 @@ lo_write(ConnectionClass *conn, int fd, char *buf, int len)
if (!CC_send_function(conn, LO_WRITE, &retval, &result_len, 1, argv, 2))
return -1;
else
return retval;
}
int
lo_lseek(ConnectionClass *conn, int fd, int offset, int whence)
{
......@@ -135,7 +131,6 @@ lo_lseek(ConnectionClass *conn, int fd, int offset, int whence)
int retval,
result_len;
argv[0].isint = 1;
argv[0].len = 4;
argv[0].u.integer = fd;
......@@ -150,11 +145,11 @@ lo_lseek(ConnectionClass *conn, int fd, int offset, int whence)
if (!CC_send_function(conn, LO_LSEEK, &retval, &result_len, 1, argv, 3))
return -1;
else
return retval;
}
int
lo_tell(ConnectionClass *conn, int fd)
{
......@@ -162,18 +157,17 @@ lo_tell(ConnectionClass *conn, int fd)
int retval,
result_len;
argv[0].isint = 1;
argv[0].len = 4;
argv[0].u.integer = fd;
if (!CC_send_function(conn, LO_TELL, &retval, &result_len, 1, argv, 1))
return -1;
else
return retval;
}
int
lo_unlink(ConnectionClass *conn, Oid lobjId)
{
......@@ -181,14 +175,12 @@ lo_unlink(ConnectionClass *conn, Oid lobjId)
int retval,
result_len;
argv[0].isint = 1;
argv[0].len = 4;
argv[0].u.integer = lobjId;
if (!CC_send_function(conn, LO_UNLINK, &retval, &result_len, 1, argv, 1))
return -1;
else
return retval;
}
/* Module: misc.c
/*-------
* Module: misc.c
*
* Description: This module contains miscellaneous routines
* such as for debugging/logging and string functions.
......@@ -8,7 +9,7 @@
* API functions: none
*
* Comments: See "notice.txt" for copyright and license information.
*
*-------
*/
#include <stdio.h>
......@@ -31,6 +32,7 @@
extern GLOBAL_VALUES globals;
void generate_filename(char *, char *, char *);
void
generate_filename(char *dirname, char *prefix, char *filename)
{
......@@ -56,8 +58,8 @@ generate_filename(char *dirname, char *prefix, char *filename)
return;
}
#ifdef MY_LOG
#ifdef MY_LOG
void
mylog(char *fmt,...)
{
......@@ -83,12 +85,10 @@ mylog(char *fmt,...)
va_end(args);
}
}
#endif
#ifdef Q_LOG
void
qlog(char *fmt,...)
{
......@@ -114,7 +114,6 @@ qlog(char *fmt,...)
va_end(args);
}
}
#endif
/* Undefine these because windows.h will redefine and cause a warning */
......@@ -137,7 +136,10 @@ qlog(char *fmt,...)
#endif
/* returns STRCPY_FAIL, STRCPY_TRUNCATED, or #bytes copied (not including null term) */
/*
* returns STRCPY_FAIL, STRCPY_TRUNCATED, or #bytes copied
* (not including null term)
*/
int
my_strcpy(char *dst, int dst_len, char *src, int src_len)
{
......@@ -154,7 +156,6 @@ my_strcpy(char *dst, int dst_len, char *src, int src_len)
if (src_len <= 0)
return STRCPY_FAIL;
else
{
if (src_len < dst_len)
......@@ -173,10 +174,13 @@ my_strcpy(char *dst, int dst_len, char *src, int src_len)
return strlen(dst);
}
/* strncpy copies up to len characters, and doesn't terminate */
/* the destination string if src has len characters or more. */
/* instead, I want it to copy up to len-1 characters and always */
/* terminate the destination string. */
/*
* strncpy copies up to len characters, and doesn't terminate
* the destination string if src has len characters or more.
* instead, I want it to copy up to len-1 characters and always
* terminate the destination string.
*/
char *
strncpy_null(char *dst, const char *src, int len)
{
......@@ -185,7 +189,6 @@ strncpy_null(char *dst, const char *src, int len)
if (NULL != dst)
{
/* Just in case, check for special lengths */
if (len == SQL_NULL_DATA)
{
......@@ -204,9 +207,14 @@ strncpy_null(char *dst, const char *src, int len)
return dst;
}
/* Create a null terminated string (handling the SQL_NTS thing): */
/* 1. If buf is supplied, place the string in there (assumes enough space) and return buf. */
/* 2. If buf is not supplied, malloc space and return this string */
/*------
* Create a null terminated string (handling the SQL_NTS thing):
* 1. If buf is supplied, place the string in there
* (assumes enough space) and return buf.
* 2. If buf is not supplied, malloc space and return this string
*------
*/
char *
make_string(char *s, int len, char *buf)
{
......@@ -234,14 +242,16 @@ make_string(char *s, int len, char *buf)
return NULL;
}
/* Concatenate a single formatted argument to a given buffer handling the SQL_NTS thing. */
/* "fmt" must contain somewhere in it the single form '%.*s' */
/* This is heavily used in creating queries for info routines (SQLTables, SQLColumns). */
/* This routine could be modified to use vsprintf() to handle multiple arguments. */
/*
* Concatenate a single formatted argument to a given buffer handling the SQL_NTS thing.
* "fmt" must contain somewhere in it the single form '%.*s'.
* This is heavily used in creating queries for info routines (SQLTables, SQLColumns).
* This routine could be modified to use vsprintf() to handle multiple arguments.
*/
char *
my_strcat(char *buf, char *fmt, char *s, int len)
{
if (s && (len > 0 || (len == SQL_NTS && strlen(s) > 0)))
{
int length = (len > 0) ? len : strlen(s);
......@@ -254,6 +264,7 @@ my_strcat(char *buf, char *fmt, char *s, int len)
return NULL;
}
void
remove_newlines(char *string)
{
......@@ -267,6 +278,7 @@ remove_newlines(char *string)
}
}
char *
trim(char *s)
{
......
/*
/*--------
* Module : multibyte.c
*
* Description: Mlutibyte related additional function.
*
* Create 2001-03-03 Eiji Tokuya
*
*--------
*/
#include <string.h>
......@@ -13,6 +13,7 @@
int multibyte_client_encoding; /* Multibyte Client Encoding. */
int multibyte_status; /* Multibyte Odds and ends character. */
unsigned char *
multibyte_strchr(unsigned char *s, unsigned char c)
{
......@@ -36,7 +37,6 @@ multibyte_strchr(unsigned char *s, unsigned char c)
}
break;
/* Chinese Big5 Support. */
case BIG5:
{
......@@ -59,12 +59,14 @@ multibyte_strchr(unsigned char *s, unsigned char c)
return (s + i);
}
void
multibyte_init(void)
{
multibyte_status = 0;
}
unsigned char *
check_client_encoding(unsigned char *str)
{
......@@ -81,19 +83,21 @@ check_client_encoding(unsigned char *str)
return ("OHTER");
}
/*
/*--------
* Multibyte Status Function.
* Input char
* Output 0 : 1 Byte Character.
* 1 : MultibyteCharacter Last Byte.
* N : MultibyteCharacter Fast or Middle Byte.
*--------
*/
int
multibyte_char_check(unsigned char s)
{
switch (multibyte_client_encoding)
{
/* Japanese Shift-JIS(CP932) Support. */
/* Japanese Shift-JIS(CP932) Support. */
case SJIS:
{
if (multibyte_status < 2 && s > 0x80 && !(s > 0x9f && s < 0xE0))
......@@ -105,8 +109,7 @@ multibyte_char_check(unsigned char s)
}
break;
/* Chinese Big5(CP950) Support. */
/* Chinese Big5(CP950) Support. */
case BIG5:
{
if (multibyte_status < 2 && s > 0xA0)
......
/* Module: options.c
/*--------
* Module: options.c
*
* Description: This module contains routines for getting/setting
* connection and statement options.
......@@ -9,7 +10,7 @@
* SQLGetStmtOption
*
* Comments: See "notice.txt" for copyright and license information.
*
*--------
*/
#ifdef HAVE_CONFIG_H
......@@ -43,7 +44,6 @@ RETCODE set_statement_option(ConnectionClass *conn,
UDWORD vParam);
RETCODE
set_statement_option(ConnectionClass *conn,
StatementClass *stmt,
......@@ -53,7 +53,6 @@ set_statement_option(ConnectionClass *conn,
static char *func = "set_statement_option";
char changed = FALSE;
switch (fOption)
{
case SQL_ASYNC_ENABLE: /* ignored */
......@@ -68,12 +67,10 @@ set_statement_option(ConnectionClass *conn,
break;
case SQL_CONCURRENCY:
/*
* positioned update isn't supported so cursor concurrency is
* read-only
*/
if (conn)
conn->stmtOptions.scroll_concurrency = vParam;
if (stmt)
......@@ -104,7 +101,6 @@ set_statement_option(ConnectionClass *conn,
*/
case SQL_CURSOR_TYPE:
/*
* if declare/fetch, then type can only be forward. otherwise,
* it can only be forward or static.
......@@ -113,18 +109,15 @@ set_statement_option(ConnectionClass *conn,
if (globals.lie)
{
if (conn)
conn->stmtOptions.cursor_type = vParam;
if (stmt)
stmt->options.cursor_type = vParam;
}
else
{
if (globals.use_declarefetch)
{
if (conn)
conn->stmtOptions.cursor_type = SQL_CURSOR_FORWARD_ONLY;
if (stmt)
......@@ -137,7 +130,6 @@ set_statement_option(ConnectionClass *conn,
{
if (vParam == SQL_CURSOR_FORWARD_ONLY || vParam == SQL_CURSOR_STATIC)
{
if (conn)
conn->stmtOptions.cursor_type = vParam; /* valid type */
if (stmt)
......@@ -145,7 +137,6 @@ set_statement_option(ConnectionClass *conn,
}
else
{
if (conn)
conn->stmtOptions.cursor_type = SQL_CURSOR_STATIC;
if (stmt)
......@@ -167,11 +158,17 @@ set_statement_option(ConnectionClass *conn,
break;
/*
* if (globals.lie) stmt->keyset_size = vParam; else {
/*-------
* if (globals.lie)
* stmt->keyset_size = vParam;
* else
* {
* stmt->errornumber = STMT_NOT_IMPLEMENTED_ERROR;
* stmt->errormsg = "Driver does not support keyset size
* option"; SC_log_error(func, "", stmt); return SQL_ERROR; }
* stmt->errormsg = "Driver does not support keyset size option";
* SC_log_error(func, "", stmt);
* return SQL_ERROR;
* }
*-------
*/
case SQL_MAX_LENGTH: /* ignored, but saved */
......@@ -194,12 +191,12 @@ set_statement_option(ConnectionClass *conn,
mylog("SetStmtOption: SQL_NOSCAN, vParam = %d\n", vParam);
break;
case SQL_QUERY_TIMEOUT:/* ignored */
case SQL_QUERY_TIMEOUT: /* ignored */
mylog("SetStmtOption: SQL_QUERY_TIMEOUT, vParam = %d\n", vParam);
/* "0" returned in SQLGetStmtOption */
break;
case SQL_RETRIEVE_DATA:/* ignored, but saved */
case SQL_RETRIEVE_DATA: /* ignored, but saved */
mylog("SetStmtOption(): SQL_RETRIEVE_DATA, vParam = %d\n", vParam);
if (conn)
conn->stmtOptions.retrieve_data = vParam;
......@@ -210,7 +207,6 @@ set_statement_option(ConnectionClass *conn,
case SQL_ROWSET_SIZE:
mylog("SetStmtOption(): SQL_ROWSET_SIZE, vParam = %d\n", vParam);
/*
* Save old rowset size for SQLExtendedFetch purposes If the
* rowset_size is being changed since the last call to fetch
......@@ -230,7 +226,6 @@ set_statement_option(ConnectionClass *conn,
conn->stmtOptions.rowset_size = vParam;
if (stmt)
stmt->options.rowset_size = vParam;
break;
case SQL_SIMULATE_CURSOR: /* NOT SUPPORTED */
......@@ -249,7 +244,6 @@ set_statement_option(ConnectionClass *conn,
return SQL_ERROR;
case SQL_USE_BOOKMARKS:
if (stmt)
stmt->options.use_bookmarks = vParam;
if (conn)
......@@ -298,7 +292,6 @@ set_statement_option(ConnectionClass *conn,
}
/* Implements only SQL_AUTOCOMMIT */
RETCODE SQL_API
SQLSetConnectOption(
......@@ -320,10 +313,8 @@ SQLSetConnectOption(
return SQL_INVALID_HANDLE;
}
switch (fOption)
{
/*
* Statement Options (apply to all stmts on the connection and
* become defaults for new stmts)
......@@ -362,15 +353,14 @@ SQLSetConnectOption(
break;
/**********************************/
/***** Connection Options *******/
/**********************************/
/*
* Connection Options
*/
case SQL_ACCESS_MODE: /* ignored */
break;
case SQL_AUTOCOMMIT:
if (CC_is_in_trans(conn))
{
conn->errormsg = "Cannot switch commit mode while a transaction is in progress";
......@@ -397,13 +387,12 @@ SQLSetConnectOption(
CC_log_error(func, "", conn);
return SQL_ERROR;
}
break;
case SQL_CURRENT_QUALIFIER: /* ignored */
break;
case SQL_LOGIN_TIMEOUT:/* ignored */
case SQL_LOGIN_TIMEOUT: /* ignored */
break;
case SQL_PACKET_SIZE: /* ignored */
......@@ -412,7 +401,7 @@ SQLSetConnectOption(
case SQL_QUIET_MODE: /* ignored */
break;
case SQL_TXN_ISOLATION:/* ignored */
case SQL_TXN_ISOLATION: /* ignored */
break;
/* These options should be handled by driver manager */
......@@ -434,7 +423,6 @@ SQLSetConnectOption(
CC_log_error(func, option, conn);
return SQL_ERROR;
}
}
if (changed)
......@@ -447,7 +435,6 @@ SQLSetConnectOption(
return SQL_SUCCESS;
}
/* - - - - - - - - - */
/* This function just can tell you whether you are in Autcommit mode or not */
RETCODE SQL_API
......@@ -484,7 +471,7 @@ SQLGetConnectOption(
break;
case SQL_LOGIN_TIMEOUT:/* NOT SUPPORTED */
case SQL_LOGIN_TIMEOUT: /* NOT SUPPORTED */
*((UDWORD *) pvParam) = 0;
break;
......@@ -496,7 +483,7 @@ SQLGetConnectOption(
*((UDWORD *) pvParam) = (UDWORD) NULL;
break;
case SQL_TXN_ISOLATION:/* NOT SUPPORTED */
case SQL_TXN_ISOLATION: /* NOT SUPPORTED */
*((UDWORD *) pvParam) = SQL_TXN_SERIALIZABLE;
break;
......@@ -520,13 +507,11 @@ SQLGetConnectOption(
return SQL_ERROR;
break;
}
}
return SQL_SUCCESS;
}
/* - - - - - - - - - */
RETCODE SQL_API
SQLSetStmtOption(
......@@ -539,10 +524,11 @@ SQLSetStmtOption(
mylog("%s: entering...\n", func);
/* thought we could fake Access out by just returning SQL_SUCCESS */
/* all the time, but it tries to set a huge value for SQL_MAX_LENGTH */
/* and expects the driver to reduce it to the real value */
/*
* Though we could fake Access out by just returning SQL_SUCCESS
* all the time, but it tries to set a huge value for SQL_MAX_LENGTH
* and expects the driver to reduce it to the real value.
*/
if (!stmt)
{
SC_log_error(func, "", NULL);
......@@ -553,8 +539,6 @@ SQLSetStmtOption(
}
/* - - - - - - - - - */
RETCODE SQL_API
SQLGetStmtOption(
HSTMT hstmt,
......@@ -567,10 +551,11 @@ SQLGetStmtOption(
mylog("%s: entering...\n", func);
/* thought we could fake Access out by just returning SQL_SUCCESS */
/* all the time, but it tries to set a huge value for SQL_MAX_LENGTH */
/* and expects the driver to reduce it to the real value */
/*
* thought we could fake Access out by just returning SQL_SUCCESS
* all the time, but it tries to set a huge value for SQL_MAX_LENGTH
* and expects the driver to reduce it to the real value
*/
if (!stmt)
{
SC_log_error(func, "", NULL);
......@@ -689,5 +674,3 @@ SQLGetStmtOption(
return SQL_SUCCESS;
}
/* - - - - - - - - - */
/* Module: parse.c
/*--------
* Module: parse.c
*
* Description: This module contains routines related to parsing SQL statements.
* This can be useful for two reasons:
* Description: This module contains routines related to parsing SQL
* statements. This can be useful for two reasons:
*
* 1. So the query does not actually have to be executed to return data about it
* 1. So the query does not actually have to be executed
* to return data about it
*
* 2. To be able to return information about precision, nullability, aliases, etc.
* in the functions SQLDescribeCol and SQLColAttributes. Currently, Postgres
* doesn't return any information about these things in a query.
* 2. To be able to return information about precision,
* nullability, aliases, etc. in the functions
* SQLDescribeCol and SQLColAttributes. Currently,
* Postgres doesn't return any information about
* these things in a query.
*
* Classes: none
*
* API functions: none
*
* Comments: See "notice.txt" for copyright and license information.
*
*--------
*/
/* Multibyte support Eiji Tokuya 2001-03-15 */
......@@ -50,6 +54,7 @@ char *getNextToken(char *s, char *token, int smax, char *delim, char *quote,
void getColInfo(COL_INFO *col_info, FIELD_INFO *fi, int k);
char searchColInfo(COL_INFO *col_info, FIELD_INFO *fi);
char *
getNextToken(char *s, char *token, int smax, char *delim, char *quote, char *dquote, char *numeric)
{
......@@ -87,7 +92,6 @@ getNextToken(char *s, char *token, int smax, char *delim, char *quote, char *dqu
while (!isspace((unsigned char) s[i]) && s[i] != ',' &&
s[i] != '\0' && out != smax)
{
/* Handle quoted stuff */
if (out == 0 && (s[i] == '\"' || s[i] == '\''))
{
......@@ -225,13 +229,13 @@ getColInfo(COL_INFO *col_info, FIELD_INFO *fi, int k)
fi->display_size = atoi(QR_get_value_manual(col_info->result, k, 12));
}
char
searchColInfo(COL_INFO *col_info, FIELD_INFO *fi)
{
int k, cmp;
char *col;
for (k = 0; k < QR_get_num_tuples(col_info->result); k++)
{
col = QR_get_value_manual(col_info->result, k, 3);
......@@ -289,7 +293,6 @@ parse_statement(StatementClass *stmt)
StatementClass *col_stmt;
RETCODE result;
mylog("%s: entering...\n", func);
ptr = stmt->statement;
......@@ -301,7 +304,6 @@ parse_statement(StatementClass *stmt)
while ((ptr = getNextToken(ptr, token, sizeof(token), &delim, &quote, &dquote, &numeric)) != NULL)
{
unquoted = !(quote || dquote);
mylog("unquoted=%d, quote=%d, dquote=%d, numeric=%d, delim='%c', token='%s', ptr='%s'\n", unquoted, quote, dquote, numeric, delim, token, ptr);
......@@ -345,7 +347,6 @@ parse_statement(StatementClass *stmt)
!stricmp(token, "group") ||
!stricmp(token, "having")))
{
in_select = FALSE;
in_from = FALSE;
in_where = TRUE;
......@@ -356,7 +357,6 @@ parse_statement(StatementClass *stmt)
if (in_select)
{
if (in_distinct)
{
mylog("in distinct\n");
......@@ -378,7 +378,8 @@ parse_statement(StatementClass *stmt)
}
if (in_expr || in_func)
{ /* just eat the expression */
{
/* just eat the expression */
mylog("in_expr=%d or func=%d\n", in_expr, in_func);
if (quote || dquote)
continue;
......@@ -389,7 +390,6 @@ parse_statement(StatementClass *stmt)
in_expr = FALSE;
in_field = FALSE;
}
else if (token[0] == '(')
{
blevel++;
......@@ -414,7 +414,6 @@ parse_statement(StatementClass *stmt)
if (!in_field)
{
if (!token[0])
continue;
......@@ -462,7 +461,6 @@ parse_statement(StatementClass *stmt)
blevel = 1;
continue;
}
else
{
strcpy(fi[stmt->nfld]->name, token);
......@@ -478,9 +476,9 @@ parse_statement(StatementClass *stmt)
continue;
}
/**************************/
/* We are in a field now */
/**************************/
/*
* We are in a field now
*/
if (in_dot)
{
stmt->nfld--;
......@@ -494,7 +492,6 @@ parse_statement(StatementClass *stmt)
mylog("in_dot: got comma\n");
in_field = FALSE;
}
continue;
}
......@@ -547,12 +544,10 @@ parse_statement(StatementClass *stmt)
fi[stmt->nfld - 1]->expr = TRUE;
fi[stmt->nfld - 1]->name[0] = '\0';
mylog("*** setting expression\n");
}
if (in_from)
{
if (!in_table)
{
if (!token[0])
......@@ -603,17 +598,15 @@ parse_statement(StatementClass *stmt)
}
}
/*************************************************/
/* Resolve any possible field names with tables */
/*************************************************/
/*
* Resolve any possible field names with tables
*/
parse = TRUE;
/* Resolve field names with tables */
for (i = 0; i < stmt->nfld; i++)
{
if (fi[i]->func || fi[i]->expr || fi[i]->numeric)
{
fi[i]->ti = NULL;
......@@ -621,7 +614,6 @@ parse_statement(StatementClass *stmt)
parse = FALSE;
continue;
}
else if (fi[i]->quote)
{ /* handle as text */
fi[i]->ti = NULL;
......@@ -629,7 +621,6 @@ parse_statement(StatementClass *stmt)
fi[i]->precision = 0;
continue;
}
/* it's a dot, resolve to table or alias */
else if (fi[i]->dot[0])
{
......@@ -665,15 +656,13 @@ parse_statement(StatementClass *stmt)
mylog("Table %d: name='%s', alias='%s'\n", i, ti[i]->name, ti[i]->alias);
/******************************************************/
/* Now save the SQLColumns Info for the parse tables */
/******************************************************/
/*
* Now save the SQLColumns Info for the parse tables
*/
/* Call SQLColumns for each table and store the result */
for (i = 0; i < stmt->ntab; i++)
{
/* See if already got it */
char found = FALSE;
......@@ -689,7 +678,6 @@ parse_statement(StatementClass *stmt)
if (!found)
{
mylog("PARSE: Getting SQLColumns for table[%d]='%s'\n", i, ti[i]->name);
result = SQLAllocStmt(stmt->hdbc, &hcol_stmt);
......@@ -713,7 +701,6 @@ parse_statement(StatementClass *stmt)
mylog(" Success\n");
if (!(conn->ntables % COL_INCR))
{
mylog("PARSE: Allocing col_info at ntables=%d\n", conn->ntables);
conn->col_info = (COL_INFO **) realloc(conn->col_info, (conn->ntables + COL_INCR) * sizeof(COL_INFO *));
......@@ -762,18 +749,13 @@ parse_statement(StatementClass *stmt)
mylog("associate col_info: i=%d, k=%d\n", i, k);
}
mylog("Done SQLColumns\n");
/******************************************************/
/* Now resolve the fields to point to column info */
/******************************************************/
/*
* Now resolve the fields to point to column info
*/
for (i = 0; i < stmt->nfld;)
{
/* Dont worry about functions or quotes */
if (fi[i]->func || fi[i]->quote || fi[i]->numeric)
{
......@@ -784,7 +766,6 @@ parse_statement(StatementClass *stmt)
/* Stars get expanded to all fields in the table */
else if (fi[i]->name[0] == '*')
{
char do_all_tables;
int total_cols,
old_alloc,
......@@ -810,7 +791,6 @@ parse_statement(StatementClass *stmt)
increased_cols = total_cols - 1;
/* Allocate some more field pointers if necessary */
/*------------------------------------------------------------- */
old_alloc = ((stmt->nfld - 1) / FLD_INCR + 1) * FLD_INCR;
new_size = stmt->nfld + increased_cols;
......@@ -830,8 +810,6 @@ parse_statement(StatementClass *stmt)
stmt->fi = fi;
}
/*------------------------------------------------------------- */
/*
* copy any other fields (if there are any) up past the
* expansion
......@@ -843,21 +821,16 @@ parse_statement(StatementClass *stmt)
}
mylog("done copying fields\n");
/*------------------------------------------------------------- */
/* Set the new number of fields */
stmt->nfld += increased_cols;
mylog("stmt->nfld now at %d\n", stmt->nfld);
/*------------------------------------------------------------- */
/* copy the new field info */
do_all_tables = (fi[i]->ti ? FALSE : TRUE);
for (k = 0; k < (do_all_tables ? stmt->ntab : 1); k++)
{
TABLE_INFO *the_ti = do_all_tables ? ti[k] : fi[i]->ti;
cols = QR_get_num_tuples(the_ti->col_info->result);
......@@ -890,8 +863,6 @@ parse_statement(StatementClass *stmt)
i += cols;
mylog("i now at %d\n", i);
}
/*------------------------------------------------------------- */
}
/*
......@@ -901,7 +872,6 @@ parse_statement(StatementClass *stmt)
*/
else if (fi[i]->ti)
{
if (!searchColInfo(fi[i]->ti->col_info, fi[i]))
parse = FALSE;
......@@ -925,13 +895,11 @@ parse_statement(StatementClass *stmt)
}
}
if (!parse)
stmt->parse_status = STMT_PARSE_INCOMPLETE;
else
stmt->parse_status = STMT_PARSE_COMPLETE;
mylog("done parse_statement: parse=%d, parse_status=%d\n", parse, stmt->parse_status);
return parse;
}
/* Module: pgtypes.c
/*--------
* Module: pgtypes.c
*
* Description: This module contains routines for getting information
* about the supported Postgres data types. Only the function
* pgtype_to_sqltype() returns an unknown condition. All other
* functions return a suitable default so that even data types that
* are not directly supported can be used (it is handled as char data).
* about the supported Postgres data types. Only the
* function pgtype_to_sqltype() returns an unknown condition.
* All other functions return a suitable default so that
* even data types that are not directly supported can be
* used (it is handled as char data).
*
* Classes: n/a
*
* API functions: none
*
* Comments: See "notice.txt" for copyright and license information.
*
*--------
*/
#ifdef HAVE_CONFIG_H
......@@ -40,15 +42,18 @@ extern GLOBAL_VALUES globals;
Int4 getCharPrecision(StatementClass *stmt, Int4 type, int col, int handle_unknown_size_as);
/*
* these are the types we support. all of the pgtype_ functions should
* return values for each one of these.
* Even types not directly supported are handled as character types
* so all types should work (points, etc.)
*/
/* these are the types we support. all of the pgtype_ functions should */
/* return values for each one of these. */
/* Even types not directly supported are handled as character types
so all types should work (points, etc.) */
/*
* ALL THESE TYPES ARE NO LONGER REPORTED in SQLGetTypeInfo. Instead, all
* the SQL TYPES are reported and mapped to a corresponding Postgres Type
*/
/* ALL THESE TYPES ARE NO LONGER REPORTED in SQLGetTypeInfo. Instead, all
the SQL TYPES are reported and mapped to a corresponding Postgres Type
*/
/*
Int4 pgtypes_defined[] = {
PG_TYPE_CHAR,
......@@ -102,6 +107,7 @@ Int2 sqlTypes[] = {
0
};
Int4
sqltype_to_pgtype(SWORD fSqlType)
{
......@@ -109,7 +115,6 @@ sqltype_to_pgtype(SWORD fSqlType)
switch (fSqlType)
{
case SQL_BINARY:
pgType = PG_TYPE_BYTEA;
break;
......@@ -185,15 +190,19 @@ sqltype_to_pgtype(SWORD fSqlType)
return pgType;
}
/* There are two ways of calling this function:
1. When going through the supported PG types (SQLGetTypeInfo)
2. When taking any type id (SQLColumns, SQLGetData)
The first type will always work because all the types defined are returned here.
The second type will return a default based on global parameter when it does not
know. This allows for supporting
types that are unknown. All other pg routines in here return a suitable default.
*/
/*
* There are two ways of calling this function:
*
* 1. When going through the supported PG types (SQLGetTypeInfo)
*
* 2. When taking any type id (SQLColumns, SQLGetData)
*
* The first type will always work because all the types defined are returned here.
* The second type will return a default based on global parameter when it does not
* know. This allows for supporting
* types that are unknown. All other pg routines in here return a suitable default.
*/
Int2
pgtype_to_sqltype(StatementClass *stmt, Int4 type)
{
......@@ -253,20 +262,20 @@ pgtype_to_sqltype(StatementClass *stmt, Int4 type)
return globals.bools_as_char ? SQL_CHAR : SQL_BIT;
default:
/*
* first, check to see if 'type' is in list. If not, look up
* with query. Add oid, name to list. If it's already in
* list, just return.
*/
if (type == stmt->hdbc->lobj_type) /* hack until permanent
* type is available */
/* hack until permanent type is available */
if (type == stmt->hdbc->lobj_type)
return SQL_LONGVARBINARY;
return globals.unknowns_as_longvarchar ? SQL_LONGVARCHAR : SQL_VARCHAR;
}
}
Int2
pgtype_to_ctype(StatementClass *stmt, Int4 type)
{
......@@ -305,15 +314,15 @@ pgtype_to_ctype(StatementClass *stmt, Int4 type)
return SQL_C_BINARY;
default:
if (type == stmt->hdbc->lobj_type) /* hack until permanent
* type is available */
/* hack until permanent type is available */
if (type == stmt->hdbc->lobj_type)
return SQL_C_BINARY;
return SQL_C_CHAR;
}
}
char *
pgtype_to_name(StatementClass *stmt, Int4 type)
{
......@@ -369,8 +378,8 @@ pgtype_to_name(StatementClass *stmt, Int4 type)
return PG_TYPE_LO_NAME;
default:
if (type == stmt->hdbc->lobj_type) /* hack until permanent
* type is available */
/* hack until permanent type is available */
if (type == stmt->hdbc->lobj_type)
return PG_TYPE_LO_NAME;
/*
......@@ -381,6 +390,7 @@ pgtype_to_name(StatementClass *stmt, Int4 type)
}
}
static Int2
getNumericScale(StatementClass *stmt, Int4 type, int col)
{
......@@ -417,6 +427,7 @@ getNumericScale(StatementClass *stmt, Int4 type, int col)
PG_NUMERIC_MAX_SCALE);
}
static Int4
getNumericPrecision(StatementClass *stmt, Int4 type, int col)
{
......@@ -453,6 +464,7 @@ getNumericPrecision(StatementClass *stmt, Int4 type, int col)
PG_NUMERIC_MAX_PRECISION);
}
Int4
getCharPrecision(StatementClass *stmt, Int4 type, int col, int handle_unknown_size_as)
{
......@@ -524,19 +536,19 @@ getCharPrecision(StatementClass *stmt, Int4 type, int col, int handle_unknown_si
return p;
}
/* For PG_TYPE_VARCHAR, PG_TYPE_BPCHAR, PG_TYPE_NUMERIC, SQLColumns will
override this length with the atttypmod length from pg_attribute .
If col >= 0, then will attempt to get the info from the result set.
This is used for functions SQLDescribeCol and SQLColAttributes.
*/
/*
* For PG_TYPE_VARCHAR, PG_TYPE_BPCHAR, PG_TYPE_NUMERIC, SQLColumns will
* override this length with the atttypmod length from pg_attribute .
*
* If col >= 0, then will attempt to get the info from the result set.
* This is used for functions SQLDescribeCol and SQLColAttributes.
*/
Int4
pgtype_precision(StatementClass *stmt, Int4 type, int col, int handle_unknown_size_as)
{
switch (type)
{
case PG_TYPE_CHAR:
return 1;
case PG_TYPE_CHAR2:
......@@ -597,10 +609,10 @@ pgtype_precision(StatementClass *stmt, Int4 type, int col, int handle_unknown_si
}
}
Int4
pgtype_display_size(StatementClass *stmt, Int4 type, int col, int handle_unknown_size_as)
{
switch (type)
{
case PG_TYPE_INT2:
......@@ -634,16 +646,16 @@ pgtype_display_size(StatementClass *stmt, Int4 type, int col, int handle_unknown
}
}
/* For PG_TYPE_VARCHAR, PG_TYPE_BPCHAR, SQLColumns will
override this length with the atttypmod length from pg_attribute
*/
/*
* For PG_TYPE_VARCHAR, PG_TYPE_BPCHAR, SQLColumns will
* override this length with the atttypmod length from pg_attribute
*/
Int4
pgtype_length(StatementClass *stmt, Int4 type, int col, int handle_unknown_size_as)
{
switch (type)
{
case PG_TYPE_INT2:
return 2;
......@@ -674,19 +686,18 @@ pgtype_length(StatementClass *stmt, Int4 type, int col, int handle_unknown_size_
case PG_TYPE_TIMESTAMP:
return 16;
/* Character types (and NUMERIC) use the default precision */
default:
return pgtype_precision(stmt, type, col, handle_unknown_size_as);
}
}
Int2
pgtype_scale(StatementClass *stmt, Int4 type, int col)
{
switch (type)
{
case PG_TYPE_INT2:
case PG_TYPE_OID:
case PG_TYPE_XID:
......@@ -729,24 +740,24 @@ pgtype_radix(StatementClass *stmt, Int4 type)
case PG_TYPE_MONEY:
case PG_TYPE_FLOAT8:
return 10;
default:
return -1;
}
}
Int2
pgtype_nullable(StatementClass *stmt, Int4 type)
{
return SQL_NULLABLE; /* everything should be nullable */
}
Int2
pgtype_auto_increment(StatementClass *stmt, Int4 type)
{
switch (type)
{
case PG_TYPE_INT2:
case PG_TYPE_OID:
case PG_TYPE_XID:
......@@ -770,6 +781,7 @@ pgtype_auto_increment(StatementClass *stmt, Int4 type)
}
}
Int2
pgtype_case_sensitive(StatementClass *stmt, Int4 type)
{
......@@ -792,6 +804,7 @@ pgtype_case_sensitive(StatementClass *stmt, Int4 type)
}
}
Int2
pgtype_money(StatementClass *stmt, Int4 type)
{
......@@ -804,6 +817,7 @@ pgtype_money(StatementClass *stmt, Int4 type)
}
}
Int2
pgtype_searchable(StatementClass *stmt, Int4 type)
{
......@@ -825,6 +839,7 @@ pgtype_searchable(StatementClass *stmt, Int4 type)
}
}
Int2
pgtype_unsigned(StatementClass *stmt, Int4 type)
{
......@@ -848,12 +863,12 @@ pgtype_unsigned(StatementClass *stmt, Int4 type)
}
}
char *
pgtype_literal_prefix(StatementClass *stmt, Int4 type)
{
switch (type)
{
case PG_TYPE_INT2:
case PG_TYPE_OID:
case PG_TYPE_XID:
......@@ -869,12 +884,12 @@ pgtype_literal_prefix(StatementClass *stmt, Int4 type)
}
}
char *
pgtype_literal_suffix(StatementClass *stmt, Int4 type)
{
switch (type)
{
case PG_TYPE_INT2:
case PG_TYPE_OID:
case PG_TYPE_XID:
......@@ -890,6 +905,7 @@ pgtype_literal_suffix(StatementClass *stmt, Int4 type)
}
}
char *
pgtype_create_params(StatementClass *stmt, Int4 type)
{
......@@ -906,8 +922,10 @@ pgtype_create_params(StatementClass *stmt, Int4 type)
Int2
sqltype_to_default_ctype(Int2 sqltype)
{
/* from the table on page 623 of ODBC 2.0 Programmer's Reference */
/* (Appendix D) */
/*
* from the table on page 623 of ODBC 2.0 Programmer's Reference
* (Appendix D)
*/
switch (sqltype)
{
case SQL_CHAR:
......@@ -951,7 +969,8 @@ sqltype_to_default_ctype(Int2 sqltype)
case SQL_TIMESTAMP:
return SQL_C_TIMESTAMP;
default: /* should never happen */
default:
/* should never happen */
return SQL_C_CHAR;
}
}
......
/* Module: psqlodbc.c
/*--------
* Module: psqlodbc.c
*
* Description: This module contains the main entry point (DllMain) for the library.
* It also contains functions to get and set global variables for the
* driver in the registry.
* Description: This module contains the main entry point (DllMain)
* for the library. It also contains functions to get
* and set global variables for the driver in the registry.
*
* Classes: n/a
*
* API functions: none
*
* Comments: See "notice.txt" for copyright and license information.
*
*--------
*/
#ifdef HAVE_CONFIG_H
......@@ -59,7 +60,6 @@ DllMain(HANDLE hInst, ULONG ul_reason_for_call, LPVOID lpReserved)
if (LOBYTE(wsaData.wVersion) != 1 ||
HIBYTE(wsaData.wVersion) != 1)
{
WSACleanup();
return FALSE;
}
......@@ -71,9 +71,7 @@ DllMain(HANDLE hInst, ULONG ul_reason_for_call, LPVOID lpReserved)
break;
case DLL_PROCESS_DETACH:
WSACleanup();
return TRUE;
case DLL_THREAD_DETACH:
......@@ -111,7 +109,8 @@ init(void)
#else /* not __GNUC__ */
/* These two functions do shared library initialziation on UNIX, well at least
/*
* These two functions do shared library initialziation on UNIX, well at least
* on Linux. I don't know about other systems.
*/
BOOL
......@@ -131,12 +130,14 @@ _fini(void)
#endif /* not WIN32 */
/* This function is used to cause the Driver Manager to
call functions by number rather than name, which is faster.
The ordinal value of this function must be 199 to have the
Driver Manager do this. Also, the ordinal values of the
functions must match the value of fFunction in SQLGetFunctions()
*/
/*
* This function is used to cause the Driver Manager to
* call functions by number rather than name, which is faster.
* The ordinal value of this function must be 199 to have the
* Driver Manager do this. Also, the ordinal values of the
* functions must match the value of fFunction in SQLGetFunctions()
*/
RETCODE SQL_API
SQLDummyOrdinal(void)
{
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
/* Module: socket.c
/*-------
* Module: socket.c
*
* Description: This module contains functions for low level socket
* operations (connecting/reading/writing to the backend)
......@@ -8,7 +9,7 @@
* API functions: none
*
* Comments: See "notice.txt" for copyright and license information.
*
*-------
*/
#ifdef HAVE_CONFIG_H
......@@ -42,6 +43,7 @@ SOCK_clear_error(SocketClass *self)
self->errormsg = NULL;
}
SocketClass *
SOCK_Constructor()
{
......@@ -70,16 +72,14 @@ SOCK_Constructor()
free(rv);
return NULL;
}
rv->errormsg = NULL;
rv->errornumber = 0;
rv->reverse = FALSE;
}
return rv;
}
void
SOCK_Destructor(SocketClass *self)
{
......@@ -97,7 +97,6 @@ SOCK_Destructor(SocketClass *self)
free(self->buffer_out);
free(self);
}
......@@ -149,7 +148,6 @@ SOCK_connect_to(SocketClass *self, unsigned short port, char *hostname)
if (connect(self->socket, (struct sockaddr *) & (sadr),
sizeof(sadr)) < 0)
{
self->errornumber = SOCKET_COULD_NOT_CONNECT;
self->errormsg = "Could not connect to remote socket.";
closesocket(self->socket);
......@@ -194,9 +192,10 @@ SOCK_put_n_char(SocketClass *self, char *buffer, int len)
}
/* bufsize must include room for the null terminator
will read at most bufsize-1 characters + null.
*/
/*
* bufsize must include room for the null terminator
* will read at most bufsize-1 characters + null.
*/
void
SOCK_get_string(SocketClass *self, char *buffer, int bufsize)
{
......@@ -297,15 +296,16 @@ SOCK_flush_output(SocketClass *self)
self->buffer_filled_out = 0;
}
unsigned char
SOCK_get_next_byte(SocketClass *self)
{
if (self->buffer_read_in >= self->buffer_filled_in)
{
/* there are no more bytes left in the buffer so */
/* reload the buffer */
/*
* there are no more bytes left in the buffer so
* reload the buffer
*/
self->buffer_read_in = 0;
self->buffer_filled_in = recv(self->socket, (char *) self->buffer_in, globals.socket_buffersize, 0);
......@@ -329,6 +329,7 @@ SOCK_get_next_byte(SocketClass *self)
return self->buffer_in[self->buffer_read_in++];
}
void
SOCK_put_next_byte(SocketClass *self, unsigned char next_byte)
{
......
This diff is collapsed.
/* Module: tuple.c
/*-------
* Module: tuple.c
*
* Description: This module contains functions for setting the data for individual
* fields (TupleField structure) of a manual result set.
* Description: This module contains functions for setting the data
* for individual fields (TupleField structure) of a
* manual result set.
*
* Important Note: These functions are ONLY used in building manual result sets for
* info functions (SQLTables, SQLColumns, etc.)
* Important Note: These functions are ONLY used in building manual
* result sets for info functions (SQLTables,
* SQLColumns, etc.)
*
* Classes: n/a
*
* API functions: none
*
* Comments: See "notice.txt" for copyright and license information.
*
*-------
*/
#include "tuple.h"
#include <string.h>
#include <stdlib.h>
void
set_tuplefield_null(TupleField *tuple_field)
{
......@@ -25,6 +29,7 @@ set_tuplefield_null(TupleField *tuple_field)
tuple_field->value = NULL; /* strdup(""); */
}
void
set_tuplefield_string(TupleField *tuple_field, char *string)
{
......@@ -39,7 +44,6 @@ set_tuplefield_int2(TupleField *tuple_field, Int2 value)
{
char buffer[10];
sprintf(buffer, "%d", value);
tuple_field->len = strlen(buffer) + 1;
......@@ -47,6 +51,7 @@ set_tuplefield_int2(TupleField *tuple_field, Int2 value)
tuple_field->value = strdup(buffer);
}
void
set_tuplefield_int4(TupleField *tuple_field, Int4 value)
{
......
/* Module: tuplelist.c
/*--------
* Module: tuplelist.c
*
* Description: This module contains functions for creating a manual result set
* (the TupleList) and retrieving data from it for a specific row/column.
* Description: This module contains functions for creating a manual
* result set (the TupleList) and retrieving data from
* it for a specific row/column.
*
* Classes: TupleListClass (Functions prefix: "TL_")
*
* API functions: none
*
* Comments: See "notice.txt" for copyright and license information.
*
*--------
*/
#include <stdlib.h>
#include "tuplelist.h"
#include "tuple.h"
TupleListClass *
TL_Constructor(UInt4 fieldcnt)
{
......@@ -25,7 +28,6 @@ TL_Constructor(UInt4 fieldcnt)
rv = (TupleListClass *) malloc(sizeof(TupleListClass));
if (rv)
{
rv->num_fields = fieldcnt;
rv->num_tuples = 0;
rv->list_start = NULL;
......@@ -39,6 +41,7 @@ TL_Constructor(UInt4 fieldcnt)
return rv;
}
void
TL_Destructor(TupleListClass *self)
{
......@@ -134,7 +137,6 @@ TL_get_fieldval(TupleListClass *self, Int4 tupleno, Int2 fieldno)
}
else if (start_is_closer)
{
/*
* the shortest way is to start the search from the head of the
* list
......@@ -177,11 +179,9 @@ TL_get_fieldval(TupleListClass *self, Int4 tupleno, Int2 fieldno)
}
char
TL_add_tuple(TupleListClass *self, TupleNode *new_field)
{
/*
* we append the tuple at the end of the doubly linked list of the
* tuples we have already read in
......@@ -200,7 +200,6 @@ TL_add_tuple(TupleListClass *self, TupleNode *new_field)
}
else
{
/*
* there is already an element in the list, so add the new one at
* the end of the list
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment