diff options
Diffstat (limited to 'src/interfaces')
43 files changed, 3013 insertions, 2789 deletions
diff --git a/src/interfaces/cli/example1.c b/src/interfaces/cli/example1.c index 95dbeabd640..88d8d7f403f 100644 --- a/src/interfaces/cli/example1.c +++ b/src/interfaces/cli/example1.c @@ -13,7 +13,7 @@ */ /* - * B.1 Create table, insert, select + * B.1 Create table, insert, select * * This example function creates a table, inserts data into the table, * and selects the inserted data. @@ -37,135 +37,137 @@ #define NULL 0 #endif -int print_err(SQLSMALLINT handletype, SQLINTEGER handle); +int print_err(SQLSMALLINT handletype, SQLINTEGER handle); -int example1(SQLCHAR *server, SQLCHAR *uid, SQLCHAR *authen) +int +example1(SQLCHAR * server, SQLCHAR * uid, SQLCHAR * authen) { - SQLHENV henv; - SQLHDBC hdbc; - SQLHDESC hdesc; - SQLHDESC hdesc1; - SQLHDESC hdesc2; - SQLHSTMT hstmt; - SQLINTEGER id; - SQLSMALLINT idind; - SQLCHAR name[51]; - SQLINTEGER namelen; - SQLSMALLINT nameind; - - /* EXEC SQL CONNECT TO :server USER :uid; */ - - /* allocate an environment handle */ - SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &henv); - /* allocate a connection handle */ - SQLAllocHandle(SQL_HANDLE_DBC, henv, &hdbc); - - /* connect to database */ - if (SQLConnect(hdbc, server, SQL_NTS, uid, SQL_NTS, - authen, SQL_NTS) - != SQL_SUCCESS) - return(print_err(SQL_HANDLE_DBC, hdbc)); - - /* allocate a statement handle */ - SQLAllocHandle(SQL_HANDLE_STMT, hdbc, &hstmt); - - /* EXEC SQL CREATE TABLE NAMEID (ID integer, NAME varchar(50)); */ - { - SQLCHAR create[] ="CREATE TABLE NAMEID (ID integer," - " NAME varchar(50))"; - - /* execute the CREATE TABLE statement */ - if (SQLExecDirect(hstmt, create, SQL_NTS) != SQL_SUCCESS) - return(print_err(SQL_HANDLE_STMT, hstmt)); - } - - /* EXEC SQL COMMIT WORK; */ - /* commit CREATE TABLE */ - SQLEndTran(SQL_HANDLE_ENV, henv, SQL_COMMIT); - /* EXEC SQL INSERT INTO NAMEID VALUES ( :id, :name ); */ - { - SQLCHAR insert[]= "INSERT INTO NAMEID VALUES (?, ?)"; - - /* show the use of SQLPrepare/SQLExecute method */ - /* prepare the INSERT */ - if (SQLPrepare(hstmt, insert, SQL_NTS) != SQL_SUCCESS) - return(print_err(SQL_HANDLE_STMT, hstmt)); - /* application parameter descriptor */ - SQLGetStmtAttr(hstmt, SQL_ATTR_APP_PARAM_ - DESC, &hdesc1, 0L, - (SQLINTEGER *)NULL); - SQLSetDescRec(hdesc1, 1, SQL_INTEGER, 0, 0L, 0, 0, - (SQLPOINTER)&id, (SQLINTEGER *)NULL, (SQLSMALLINT *)NULL); - SQLSetDescRec(hdesc1, 2, SQL_CHAR, 0, 0L, 0, 0, - (SQLPOINTER)name, (SQLINTEGER *)NULL, - (SQLSMALLINT *)NULL); - /* implementation parameter descriptor */ - SQLGetStmtAttr(hstmt, SQL_ATTR_IMP_PARAM_ - DESC, &hdesc2, 0L, - (SQLINTEGER *)NULL); - SQLSetDescRec(hdesc2, 1, SQL_INTEGER, 0, 0L, 0, 0, - (SQLPOINTER)NULL, (SQLINTEGER *)NULL, - (SQLSMALLINT *)NULL); - SQLSetDescRec(hdesc2, 2, SQL_VARCHAR, 0, 50L, 0, 0, - (SQLPOINTER)NULL, (SQLINTEGER *)NULL, - (SQLSMALLINT *)NULL); - - /* assign parameter values and execute the INSERT */ - id=500; - (void)strcpy(name, "Babbage"); - if (SQLExecute(hstmt) != SQL_SUCCESS) - return(print_err(SQL_HANDLE_STMT, hstmt)); - } - /* EXEC SQL COMMIT WORK; */ - SQLEndTran(SQL_HANDLE_ENV, henv, SQL_COMMIT); - /* commit inserts */ - - /* EXEC SQL DECLARE c1 CURSOR FOR SELECT ID, NAME FROM NAMEID; */ - /* EXEC SQL OPEN c1; */ - /* The application doesn't specify "declare c1 cursor for" */ - { - SQLCHAR select[]= "select ID, NAME from NAMEID"; - if (SQLExecDirect(hstmt, select, SQL_NTS) != SQL_SUCCESS) - return(print_err(SQL_HANDLE_STMT, hstmt)); - } - - /* EXEC SQL FETCH c1 INTO :id, :name; */ - /* this time, explicitly allocate an application row descriptor */ - SQLAllocHandle(SQL_HANDLE_DESC, hdbc, &hdesc); - SQLSetDescRec(hdesc, 1, SQL_INTEGER, 0, 0L, 0, 0, - (SQLPOINTER)&id, (SQLINTEGER *)NULL, (SQLSMALLINT *)&idind); - - SQLSetDescRec(hdesc, 2, SQL_ - CHAR, 0, (SQLINTEGER)sizeof(name), - 0, 0, (SQLPOINTER)&name, (SQLINTEGER *)&namelen, - (SQLSMALLINT *)&nameind); - /* associate descriptor with statement handle */ - SQLSetStmtAttr(hstmt, SQL_ATTR_APP_ROW_DESC, &hdesc, 0); - /* execute the fetch */ - SQLFetch(hstmt); - - /* EXEC SQL COMMIT WORK; */ - /* commit the transaction */ - SQLEndTran(SQL_HANDLE_ENV, henv, SQL_COMMIT); - - /* EXEC SQL CLOSE c1; */ - SQLClose(hstmt); - /* free the statement handle */ - SQLFreeHandle(SQL_HANDLE_STMT, hstmt); - - /* EXEC SQL DISCONNECT; */ - /* disconnect from the database */ - SQLDisconnect(hdbc); - /* free descriptor handle */ - SQLFreeHandle(SQL_HANDLE_DESC, hdesc); - /* free descriptor handle */ - SQLFreeHandle(SQL_HANDLE_DESC, hdesc1); - /* free descriptor handle */ - SQLFreeHandle(SQL_HANDLE_DESC, hdesc2); - /* free connection handle */ - SQLFreeHandle(SQL_HANDLE_DBC, hdbc); - /* free environment handle */ - SQLFreeHandle(SQL_HANDLE_ENV, henv); - - return(0); + SQLHENV henv; + SQLHDBC hdbc; + SQLHDESC hdesc; + SQLHDESC hdesc1; + SQLHDESC hdesc2; + SQLHSTMT hstmt; + SQLINTEGER id; + SQLSMALLINT idind; + SQLCHAR name[51]; + SQLINTEGER namelen; + SQLSMALLINT nameind; + + /* EXEC SQL CONNECT TO :server USER :uid; */ + + /* allocate an environment handle */ + SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &henv); + /* allocate a connection handle */ + SQLAllocHandle(SQL_HANDLE_DBC, henv, &hdbc); + + /* connect to database */ + if (SQLConnect(hdbc, server, SQL_NTS, uid, SQL_NTS, + authen, SQL_NTS) + != SQL_SUCCESS) + return (print_err(SQL_HANDLE_DBC, hdbc)); + + /* allocate a statement handle */ + SQLAllocHandle(SQL_HANDLE_STMT, hdbc, &hstmt); + + /* EXEC SQL CREATE TABLE NAMEID (ID integer, NAME varchar(50)); */ + { + SQLCHAR create[] = "CREATE TABLE NAMEID (ID integer," + " NAME varchar(50))"; + + /* execute the CREATE TABLE statement */ + if (SQLExecDirect(hstmt, create, SQL_NTS) != SQL_SUCCESS) + return (print_err(SQL_HANDLE_STMT, hstmt)); + } + + /* EXEC SQL COMMIT WORK; */ + /* commit CREATE TABLE */ + SQLEndTran(SQL_HANDLE_ENV, henv, SQL_COMMIT); + /* EXEC SQL INSERT INTO NAMEID VALUES ( :id, :name ); */ + { + SQLCHAR insert[] = "INSERT INTO NAMEID VALUES (?, ?)"; + + /* show the use of SQLPrepare/SQLExecute method */ + /* prepare the INSERT */ + if (SQLPrepare(hstmt, insert, SQL_NTS) != SQL_SUCCESS) + return (print_err(SQL_HANDLE_STMT, hstmt)); + /* application parameter descriptor */ + SQLGetStmtAttr(hstmt, SQL_ATTR_APP_PARAM_ + DESC, &hdesc1, 0L, + (SQLINTEGER *) NULL); + SQLSetDescRec(hdesc1, 1, SQL_INTEGER, 0, 0L, 0, 0, + (SQLPOINTER) & id, (SQLINTEGER *) NULL, (SQLSMALLINT *) NULL); + SQLSetDescRec(hdesc1, 2, SQL_CHAR, 0, 0L, 0, 0, + (SQLPOINTER) name, (SQLINTEGER *) NULL, + (SQLSMALLINT *) NULL); + /* implementation parameter descriptor */ + SQLGetStmtAttr(hstmt, SQL_ATTR_IMP_PARAM_ + DESC, &hdesc2, 0L, + (SQLINTEGER *) NULL); + SQLSetDescRec(hdesc2, 1, SQL_INTEGER, 0, 0L, 0, 0, + (SQLPOINTER) NULL, (SQLINTEGER *) NULL, + (SQLSMALLINT *) NULL); + SQLSetDescRec(hdesc2, 2, SQL_VARCHAR, 0, 50L, 0, 0, + (SQLPOINTER) NULL, (SQLINTEGER *) NULL, + (SQLSMALLINT *) NULL); + + /* assign parameter values and execute the INSERT */ + id = 500; + (void) strcpy(name, "Babbage"); + if (SQLExecute(hstmt) != SQL_SUCCESS) + return (print_err(SQL_HANDLE_STMT, hstmt)); + } + /* EXEC SQL COMMIT WORK; */ + SQLEndTran(SQL_HANDLE_ENV, henv, SQL_COMMIT); + /* commit inserts */ + + /* EXEC SQL DECLARE c1 CURSOR FOR SELECT ID, NAME FROM NAMEID; */ + /* EXEC SQL OPEN c1; */ + /* The application doesn't specify "declare c1 cursor for" */ + { + SQLCHAR select[] = "select ID, NAME from NAMEID"; + + if (SQLExecDirect(hstmt, select, SQL_NTS) != SQL_SUCCESS) + return (print_err(SQL_HANDLE_STMT, hstmt)); + } + + /* EXEC SQL FETCH c1 INTO :id, :name; */ + /* this time, explicitly allocate an application row descriptor */ + SQLAllocHandle(SQL_HANDLE_DESC, hdbc, &hdesc); + SQLSetDescRec(hdesc, 1, SQL_INTEGER, 0, 0L, 0, 0, + (SQLPOINTER) & id, (SQLINTEGER *) NULL, (SQLSMALLINT *) & idind); + + SQLSetDescRec(hdesc, 2, SQL_ + CHAR, 0, (SQLINTEGER) sizeof(name), + 0, 0, (SQLPOINTER) & name, (SQLINTEGER *) & namelen, + (SQLSMALLINT *) & nameind); + /* associate descriptor with statement handle */ + SQLSetStmtAttr(hstmt, SQL_ATTR_APP_ROW_DESC, &hdesc, 0); + /* execute the fetch */ + SQLFetch(hstmt); + + /* EXEC SQL COMMIT WORK; */ + /* commit the transaction */ + SQLEndTran(SQL_HANDLE_ENV, henv, SQL_COMMIT); + + /* EXEC SQL CLOSE c1; */ + SQLClose(hstmt); + /* free the statement handle */ + SQLFreeHandle(SQL_HANDLE_STMT, hstmt); + + /* EXEC SQL DISCONNECT; */ + /* disconnect from the database */ + SQLDisconnect(hdbc); + /* free descriptor handle */ + SQLFreeHandle(SQL_HANDLE_DESC, hdesc); + /* free descriptor handle */ + SQLFreeHandle(SQL_HANDLE_DESC, hdesc1); + /* free descriptor handle */ + SQLFreeHandle(SQL_HANDLE_DESC, hdesc2); + /* free connection handle */ + SQLFreeHandle(SQL_HANDLE_DBC, hdbc); + /* free environment handle */ + SQLFreeHandle(SQL_HANDLE_ENV, henv); + + return (0); } diff --git a/src/interfaces/cli/example2.c b/src/interfaces/cli/example2.c index e8822742213..d74b1e971a5 100644 --- a/src/interfaces/cli/example2.c +++ b/src/interfaces/cli/example2.c @@ -13,7 +13,7 @@ */ /* - * B.2 Interactive Query + * B.2 Interactive Query * * This sample function uses the concise CLI functions to * interactively execute a SQL statement supplied as an argument. @@ -38,158 +38,163 @@ #define max(a,b) (a>b?a:b) -int print_err(SQLSMALLINT handletype, SQLINTEGER handle); -int build_indicator_message(SQLCHAR *errmsg, - SQLPOINTER *data, - SQLINTEGER collen, - SQLINTEGER *outlen, - SQLSMALLINT colnum); +int print_err(SQLSMALLINT handletype, SQLINTEGER handle); +int build_indicator_message(SQLCHAR * errmsg, + SQLPOINTER * data, + SQLINTEGER collen, + SQLINTEGER * outlen, + SQLSMALLINT colnum); SQLINTEGER display_length(SQLSMALLINT coltype, - SQLINTEGER collen, - SQLCHAR *colname); + SQLINTEGER collen, + SQLCHAR * colname); -example2(SQLCHAR *server, SQLCHAR *uid, SQLCHAR *authen, SQLCHAR *sqlstr) +example2(SQLCHAR * server, SQLCHAR * uid, SQLCHAR * authen, SQLCHAR * sqlstr) { - int i; - SQLHENV henv; - SQLHDBC hdbc; - SQLHSTMT hstmt; - SQLCHAR errmsg[256]; - SQLCHAR colname[32]; - SQLSMALLINT coltype; - SQLSMALLINT colnamelen; - SQLSMALLINT nullable; - SQLINTEGER collen[MAXCOLS]; - SQLSMALLINT scale; - SQLINTEGER outlen[MAXCOLS]; - SQLCHAR *data[MAXCOLS]; - SQLSMALLINT nresultcols; - SQLINTEGER rowcount; - SQLINTEGER stmttype; - SQLRETURN rc; - - /* allocate an environment handle */ - SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &henv); - - /* allocate a connection handle */ - SQLAllocHandle(SQL_HANDLE_DBC, henv, &hdbc); - - /* connect to database */ - if (SQLConnect(hdbc, server, SQL_NTS, uid, SQL_NTS, authen, SQL_NTS) - != SQL_SUCCESS ) - return(print_err(SQL_HANDLE_DBC, hdbc)); - - /* allocate a statement handle */ - SQLAllocHandle(SQL_HANDLE_STMT, hdbc, &hstmt); - - /* execute the SQL statement */ - if (SQLExecDirect(hstmt, sqlstr, SQL_NTS) != SQL_SUCCESS) - return(print_err(SQL_HANDLE_STMT, hstmt)); - - /* see what kind of statement it was */ - SQLGetDiagField(SQL_HANDLE_STMT, hstmt, 0, - SQL_DIAG_DYNAMIC_FUNCTION_CODE, - (SQLPOINTER)&stmttype, 0, (SQLSMALLINT *)NULL); - - switch (stmttype) { - /* SELECT statement */ - case SQL_SELECT_CURSOR: - /* determine number of result columns */ - SQLNumResultCols(hstmt, &nresultcols); - /* display column names */ - for (i=0; i<nresultcols; i++) { - SQLDescribeCol(hstmt, i+1, colname, sizeof(colname), - &colnamelen, &coltype, &collen[i], &scale, &nullable); - - /* assume there is a display_length function which - computes correct length given the data type */ - collen[i] = display_length(coltype, collen[i], colname); - (void)printf("%*.*s", collen[i], collen[i], colname); - /* allocate memory to bind column */ - data[i] = (SQLCHAR *) malloc(collen[i]); - - /* bind columns to program vars, converting all types to CHAR */ - SQLBindCol(hstmt, i+1, SQL_CHAR, data[i], collen[i], - &outlen[i]); - } - /* display result rows */ - while ((rc=SQLFetch(hstmt))!=SQL_ERROR) { - errmsg[0] = '\0'; - if (rc == SQL_SUCCESS_WITH_INFO) { - for (i=0; i<nresultcols; i++) { - if (outlen[i] == SQL_NULL_DATA || outlen[i] >= collen[i]) - build_indicator_message(errmsg, - (SQLPOINTER *)&data[i], collen[i], - &outlen[i], i); - (void)printf("%*.*s ", outlen[i], outlen[i], - data[i]); - } /* for all columns in this row */ - /* print any truncation messages */ - (void)printf("\n%s", errmsg); - } - } /* while rows to fetch */ - SQLClose(hstmt); - break; - - /* searched DELETE, INSERT or searched UPDATE statement */ - case SQL_DELETE_WHERE: - case SQL_INSERT: - case SQL_UPDATE_WHERE: - /* check rowcount */ - SQLGetDiagField(SQL_HANDLE_STMT, hstmt, 0, - SQL_DIAG_ROW_COUNT, (SQLPOINTER)&rowcount, 0, - (SQLSMALLINT *)NULL); - if (SQLEndTran(SQL_HANDLE_ENV, henv, SQL_COMMIT) - == SQL_SUCCESS) { - (void) printf("Operation successful\n"); - } - else { - (void) printf("Operation failed\n"); - } - (void)printf("%ld rows affected\n", rowcount); - break; - - /* other statements */ - case SQL_ALTER_TABLE: - case SQL_CREATE_TABLE: - case SQL_CREATE_VIEW: - case SQL_DROP_TABLE: - case SQL_DROP_VIEW: - case SQL_DYNAMIC_DELETE_CURSOR: - case SQL_DYNAMIC_UPDATE_CURSOR: - case SQL_GRANT: - case SQL_REVOKE: - if (SQLEndTran(SQL_HANDLE_ENV, henv, SQL_COMMIT) - == SQL_SUCCESS) { - (void) printf("Operation successful\n"); - } - else { - (void) printf("Operation failed\n"); - } - break; - - /* implementation-defined statement */ - default: - (void)printf("Statement type=%ld\n", stmttype); - break; - } - - /* free data buffers */ - for (i=0; i<nresultcols; i++) { - (void)free(data[i]); - } - - /* free statement handle */ - SQLFreeHandle(SQL_HANDLE_STMT, hstmt); - /* disconnect from database */ - SQLDisconnect(hdbc); - /* free connection handle */ - SQLFreeHandle(SQL_HANDLE_DBC, hdbc); - /* free environment handle */ - SQLFreeHandle(SQL_HANDLE_ENV, henv); - - return(0); + int i; + SQLHENV henv; + SQLHDBC hdbc; + SQLHSTMT hstmt; + SQLCHAR errmsg[256]; + SQLCHAR colname[32]; + SQLSMALLINT coltype; + SQLSMALLINT colnamelen; + SQLSMALLINT nullable; + SQLINTEGER collen[MAXCOLS]; + SQLSMALLINT scale; + SQLINTEGER outlen[MAXCOLS]; + SQLCHAR *data[MAXCOLS]; + SQLSMALLINT nresultcols; + SQLINTEGER rowcount; + SQLINTEGER stmttype; + SQLRETURN rc; + + /* allocate an environment handle */ + SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &henv); + + /* allocate a connection handle */ + SQLAllocHandle(SQL_HANDLE_DBC, henv, &hdbc); + + /* connect to database */ + if (SQLConnect(hdbc, server, SQL_NTS, uid, SQL_NTS, authen, SQL_NTS) + != SQL_SUCCESS) + return (print_err(SQL_HANDLE_DBC, hdbc)); + + /* allocate a statement handle */ + SQLAllocHandle(SQL_HANDLE_STMT, hdbc, &hstmt); + + /* execute the SQL statement */ + if (SQLExecDirect(hstmt, sqlstr, SQL_NTS) != SQL_SUCCESS) + return (print_err(SQL_HANDLE_STMT, hstmt)); + + /* see what kind of statement it was */ + SQLGetDiagField(SQL_HANDLE_STMT, hstmt, 0, + SQL_DIAG_DYNAMIC_FUNCTION_CODE, + (SQLPOINTER) & stmttype, 0, (SQLSMALLINT *) NULL); + + switch (stmttype) + { + /* SELECT statement */ + case SQL_SELECT_CURSOR: + /* determine number of result columns */ + SQLNumResultCols(hstmt, &nresultcols); + /* display column names */ + for (i = 0; i < nresultcols; i++) + { + SQLDescribeCol(hstmt, i + 1, colname, sizeof(colname), + &colnamelen, &coltype, &collen[i], &scale, &nullable); + + /* + * assume there is a display_length function which + * computes correct length given the data type + */ + collen[i] = display_length(coltype, collen[i], colname); + (void) printf("%*.*s", collen[i], collen[i], colname); + /* allocate memory to bind column */ + data[i] = (SQLCHAR *) malloc(collen[i]); + + /* + * bind columns to program vars, converting all types to + * CHAR + */ + SQLBindCol(hstmt, i + 1, SQL_CHAR, data[i], collen[i], + &outlen[i]); + } + /* display result rows */ + while ((rc = SQLFetch(hstmt)) != SQL_ERROR) + { + errmsg[0] = '\0'; + if (rc == SQL_SUCCESS_WITH_INFO) + { + for (i = 0; i < nresultcols; i++) + { + if (outlen[i] == SQL_NULL_DATA || outlen[i] >= collen[i]) + build_indicator_message(errmsg, + (SQLPOINTER *) & data[i], collen[i], + &outlen[i], i); + (void) printf("%*.*s ", outlen[i], outlen[i], + data[i]); + } /* for all columns in this row */ + /* print any truncation messages */ + (void) printf("\n%s", errmsg); + } + } /* while rows to fetch */ + SQLClose(hstmt); + break; + + /* searched DELETE, INSERT or searched UPDATE statement */ + case SQL_DELETE_WHERE: + case SQL_INSERT: + case SQL_UPDATE_WHERE: + /* check rowcount */ + SQLGetDiagField(SQL_HANDLE_STMT, hstmt, 0, + SQL_DIAG_ROW_COUNT, (SQLPOINTER) & rowcount, 0, + (SQLSMALLINT *) NULL); + if (SQLEndTran(SQL_HANDLE_ENV, henv, SQL_COMMIT) + == SQL_SUCCESS) + (void) printf("Operation successful\n"); + else + (void) printf("Operation failed\n"); + (void) printf("%ld rows affected\n", rowcount); + break; + + /* other statements */ + case SQL_ALTER_TABLE: + case SQL_CREATE_TABLE: + case SQL_CREATE_VIEW: + case SQL_DROP_TABLE: + case SQL_DROP_VIEW: + case SQL_DYNAMIC_DELETE_CURSOR: + case SQL_DYNAMIC_UPDATE_CURSOR: + case SQL_GRANT: + case SQL_REVOKE: + if (SQLEndTran(SQL_HANDLE_ENV, henv, SQL_COMMIT) + == SQL_SUCCESS) + (void) printf("Operation successful\n"); + else + (void) printf("Operation failed\n"); + break; + + /* implementation-defined statement */ + default: + (void) printf("Statement type=%ld\n", stmttype); + break; + } + + /* free data buffers */ + for (i = 0; i < nresultcols; i++) + (void) free(data[i]); + + /* free statement handle */ + SQLFreeHandle(SQL_HANDLE_STMT, hstmt); + /* disconnect from database */ + SQLDisconnect(hdbc); + /* free connection handle */ + SQLFreeHandle(SQL_HANDLE_DBC, hdbc); + /* free environment handle */ + SQLFreeHandle(SQL_HANDLE_ENV, henv); + + return (0); } /*********************************************************** @@ -202,59 +207,64 @@ example2(SQLCHAR *server, SQLCHAR *uid, SQLCHAR *authen, SQLCHAR *sqlstr) /*#define max length of char string representation of no. as: = max(precision) + leading sign + E + exp sign + max exp length - = 15 + 1 + 1 + 1 + 2 + = 15 + 1 + 1 + 1 + 2 = 15 + 5 */ #define MAX_NUM_STRING_SIZE (MAX_NUM_PRECISION + 5) -SQLINTEGER display_length(SQLSMALLINT coltype, SQLINTEGER collen, - SQLCHAR *colname) +SQLINTEGER +display_length(SQLSMALLINT coltype, SQLINTEGER collen, + SQLCHAR * colname) { - switch (coltype) { - - case SQL_VARCHAR: - case SQL_CHAR: - return(max(collen,strlen((char *)colname))); - break; - - case SQL_FLOAT: - case SQL_DOUBLE: - case SQL_NUMERIC: - case SQL_REAL: - case SQL_DECIMAL: - return(max(MAX_NUM_STRING_SIZE,strlen((char *)colname))); - break; - - case SQL_DATETIME: - return(max(SQL_TIMESTAMP_LEN,strlen((char *)colname))); - break; - - case SQL_INTEGER: - return(max(10,strlen((char *)colname))); - break; - - case SQL_SMALLINT: - return(max(5,strlen((char *)colname))); - break; - - default: - (void)printf("Unknown datatype, %d\n", coltype); - return(0); - break; - } + switch (coltype) + { + + case SQL_VARCHAR: + case SQL_CHAR: + return (max(collen, strlen((char *) colname))); + break; + + case SQL_FLOAT: + case SQL_DOUBLE: + case SQL_NUMERIC: + case SQL_REAL: + case SQL_DECIMAL: + return (max(MAX_NUM_STRING_SIZE, strlen((char *) colname))); + break; + + case SQL_DATETIME: + return (max(SQL_TIMESTAMP_LEN, strlen((char *) colname))); + break; + + case SQL_INTEGER: + return (max(10, strlen((char *) colname))); + break; + + case SQL_SMALLINT: + return (max(5, strlen((char *) colname))); + break; + + default: + (void) printf("Unknown datatype, %d\n", coltype); + return (0); + break; + } } -int build_indicator_message(SQLCHAR *errmsg, SQLPOINTER *data, - SQLINTEGER collen, SQLINTEGER *outlen, SQLSMALLINT colnum) +int +build_indicator_message(SQLCHAR * errmsg, SQLPOINTER * data, + SQLINTEGER collen, SQLINTEGER * outlen, SQLSMALLINT colnum) { - if (*outlen == SQL_NULL_DATA) { - (void)strcpy((char *)data, "NULL"); - *outlen=4; - } - else { - sprintf((char *)errmsg+strlen((char *)errmsg), - "%d chars truncated, col %d\n", *outlen-collen+1, - colnum); - *outlen=255; - } + if (*outlen == SQL_NULL_DATA) + { + (void) strcpy((char *) data, "NULL"); + *outlen = 4; + } + else + { + sprintf((char *) errmsg + strlen((char *) errmsg), + "%d chars truncated, col %d\n", *outlen - collen + 1, + colnum); + *outlen = 255; + } } diff --git a/src/interfaces/cli/sqlcli.h b/src/interfaces/cli/sqlcli.h index 243a7cbe2b2..a9145495fc6 100644 --- a/src/interfaces/cli/sqlcli.h +++ b/src/interfaces/cli/sqlcli.h @@ -13,698 +13,698 @@ */ /* API declaration data types */ -typedef unsigned char SQLCHAR; -typedef long SQLINTEGER; -typedef short SQLSMALLINT; -typedef double SQLDOUBLE; -typedef float SQLREAL; -typedef void * SQLPOINTER; -typedef unsigned char SQLDATE; -typedef unsigned char SQLTIME; -typedef unsigned char SQLTIMESTAMP; -typedef unsigned char SQLDECIMAL; -typedef unsigned char SQLNUMERIC; +typedef unsigned char SQLCHAR; +typedef long SQLINTEGER; +typedef short SQLSMALLINT; +typedef double SQLDOUBLE; +typedef float SQLREAL; +typedef void *SQLPOINTER; +typedef unsigned char SQLDATE; +typedef unsigned char SQLTIME; +typedef unsigned char SQLTIMESTAMP; +typedef unsigned char SQLDECIMAL; +typedef unsigned char SQLNUMERIC; /* function return type */ -typedef SQLSMALLINT SQLRETURN; +typedef SQLSMALLINT SQLRETURN; /* generic data structures */ -typedef SQLINTEGER SQLHENV; /* environment handle */ -typedef SQLINTEGER SQLHDBC; /* connection handle */ -typedef SQLINTEGER SQLHSTMT; /* statement handle */ -typedef SQLINTEGER SQLHDESC; /* descriptor handle */ +typedef SQLINTEGER SQLHENV; /* environment handle */ +typedef SQLINTEGER SQLHDBC; /* connection handle */ +typedef SQLINTEGER SQLHSTMT; /* statement handle */ +typedef SQLINTEGER SQLHDESC; /* descriptor handle */ /* special length/indicator values */ -#define SQL_NULL_DATA -1 -#define SQL_DATA_AT_EXEC -2 +#define SQL_NULL_DATA -1 +#define SQL_DATA_AT_EXEC -2 /* return values from functions */ -#define SQL_SUCCESS 0 -#define SQL_SUCCESS_WITH_INFO 1 -#define SQL_NEED_DATA 99 -#define SQL_NO_DATA 100 -#define SQL_ERROR -1 -#define SQL_INVALID_HANDLE -2 +#define SQL_SUCCESS 0 +#define SQL_SUCCESS_WITH_INFO 1 +#define SQL_NEED_DATA 99 +#define SQL_NO_DATA 100 +#define SQL_ERROR -1 +#define SQL_INVALID_HANDLE -2 /* test for SQL_SUCCESS or SQL_SUCCESS_WITH_INFO */ #define SQL_SUCCEEDED(rc) (((rc)&(~1))==0) /* flags for null-terminated string */ -#define SQL_NTS -3 -#define SQL_NTSL -3L +#define SQL_NTS -3 +#define SQL_NTSL -3L /* maximum message length from Date and Darwen * was 255 in the August 1994 draft standard * - Thomas Lockhart 1999-06-17 */ -#define SQL_MAX_MESSAGE_LENGTH 512 +#define SQL_MAX_MESSAGE_LENGTH 512 /* maximum identifier length */ -#define SQL_MAX_ID_LENGTH 18 +#define SQL_MAX_ID_LENGTH 18 /* date/time length constants */ /* add p+1 for time and timestamp if precision is nonzero */ -#define SQL_DATE_LEN 10 -#define SQL_TIME_LEN 8 -#define SQL_TIMESTAMP_LEN 19 +#define SQL_DATE_LEN 10 +#define SQL_TIME_LEN 8 +#define SQL_TIMESTAMP_LEN 19 /* handle type identifiers */ -#define SQL_HANDLE_ENV 1 -#define SQL_HANDLE_DBC 2 -#define SQL_HANDLE_STMT 3 -#define SQL_HANDLE_DESC 4 +#define SQL_HANDLE_ENV 1 +#define SQL_HANDLE_DBC 2 +#define SQL_HANDLE_STMT 3 +#define SQL_HANDLE_DESC 4 /* environment attribute */ #define SQL_ATTR_OUTPUT_NTS 10001 /* connection attribute */ -#define SQL_ATTR_AUTO_IPD 10001 +#define SQL_ATTR_AUTO_IPD 10001 /* statement attributes */ -#define SQL_ATTR_APP_ROW_DESC 10010 -#define SQL_ATTR_APP_PARAM_DESC 10011 -#define SQL_ATTR_IMP_ROW_DESC 10012 -#define SQL_ATTR_IMP_PARAM_DESC 10013 -#define SQL_ATTR_CURSOR_SCROLLABLE -1 -#define SQL_ATTR_CURSOR_SENSITIVITY -2 +#define SQL_ATTR_APP_ROW_DESC 10010 +#define SQL_ATTR_APP_PARAM_DESC 10011 +#define SQL_ATTR_IMP_ROW_DESC 10012 +#define SQL_ATTR_IMP_PARAM_DESC 10013 +#define SQL_ATTR_CURSOR_SCROLLABLE -1 +#define SQL_ATTR_CURSOR_SENSITIVITY -2 /* identifiers of fields in the SQL descriptor */ /* These ran 1-99 in the August 1994 draft standard * - Thomas Lockhart 1999-06-17 */ -#define SQL_DESC_COUNT 1001 -#define SQL_DESC_TYPE 1002 -#define SQL_DESC_LENGTH 1003 -#define SQL_DESC_OCTET_LENGTH_POINTER 1004 -#define SQL_DESC_PRECISION 1005 -#define SQL_DESC_SCALE 1006 -#define SQL_DESC_DATETIME_INTERVAL_CODE 1007 -#define SQL_DESC_NULLABLE 1008 -#define SQL_DESC_INDICATOR_POINTER 1009 -#define SQL_DESC_DATA_POINTER 1010 -#define SQL_DESC_NAME 1011 -#define SQL_DESC_UNNAMED 1012 -#define SQL_DESC_OCTET_LENGTH 1013 +#define SQL_DESC_COUNT 1001 +#define SQL_DESC_TYPE 1002 +#define SQL_DESC_LENGTH 1003 +#define SQL_DESC_OCTET_LENGTH_POINTER 1004 +#define SQL_DESC_PRECISION 1005 +#define SQL_DESC_SCALE 1006 +#define SQL_DESC_DATETIME_INTERVAL_CODE 1007 +#define SQL_DESC_NULLABLE 1008 +#define SQL_DESC_INDICATOR_POINTER 1009 +#define SQL_DESC_DATA_POINTER 1010 +#define SQL_DESC_NAME 1011 +#define SQL_DESC_UNNAMED 1012 +#define SQL_DESC_OCTET_LENGTH 1013 #define SQL_DESC_DATETIME_INTERVAL_PRECISION 1014 -#define SQL_DESC_COLLATION_CATALOG 1015 -#define SQL_DESC_COLLATION_SCHEMA 1016 -#define SQL_DESC_COLLATION_NAME 1017 -#define SQL_DESC_CHARACTER_SET_CATALOG 1018 -#define SQL_DESC_CHARACTER_SET_SCHEMA 1019 -#define SQL_DESC_CHARACTER_SET_NAME 1020 -#define SQL_DESC_PARAMETER_MODE 1021 +#define SQL_DESC_COLLATION_CATALOG 1015 +#define SQL_DESC_COLLATION_SCHEMA 1016 +#define SQL_DESC_COLLATION_NAME 1017 +#define SQL_DESC_CHARACTER_SET_CATALOG 1018 +#define SQL_DESC_CHARACTER_SET_SCHEMA 1019 +#define SQL_DESC_CHARACTER_SET_NAME 1020 +#define SQL_DESC_PARAMETER_MODE 1021 #define SQL_DESC_PARAMETER_ORDINAL_POSITION 1022 #define SQL_DESC_PARAMETER_SPECIFIC_CATALOG 1023 -#define SQL_DESC_PARAMETER_SPECIFIC_SCHEMA 1024 -#define SQL_DESC_PARAMETER_SPECIFIC_NAME 1025 -#define SQL_DESC_ALLOC_TYPE 1099 +#define SQL_DESC_PARAMETER_SPECIFIC_SCHEMA 1024 +#define SQL_DESC_PARAMETER_SPECIFIC_NAME 1025 +#define SQL_DESC_ALLOC_TYPE 1099 /* identifiers of fields in the diagnostics area */ /* Many new definitions since August 1994 draft standard * - Thomas Lockhart 1999-06-17 */ -#define SQL_DIAG_RETURNCODE 1 -#define SQL_DIAG_NUMBER 2 -#define SQL_DIAG_ROW_COUNT 3 -#define SQL_DIAG_SQLSTATE 4 -#define SQL_DIAG_NATIVE 5 -#define SQL_DIAG_MESSAGE_TEXT 6 -#define SQL_DIAG_DYNAMIC_FUNCTION 7 -#define SQL_DIAG_CLASS_ORIGIN 8 -#define SQL_DIAG_SUBCLASS_ORIGIN 9 -#define SQL_DIAG_CONNECTION_NAME 10 -#define SQL_DIAG_SERVER_NAME 11 -#define SQL_DIAG_DYNAMIC_FUNCTION_CODE 12 -#define SQL_DIAG_MORE 13 -#define SQL_DIAG_CONDITION_NUMBER 14 -#define SQL_DIAG_CONSTRAINT_CATALOG 15 -#define SQL_DIAG_CONSTRAINT_SCHEMA 16 -#define SQL_DIAG_CONSTRAINT_NAME 17 -#define SQL_DIAG_CATALOG_NAME 18 -#define SQL_DIAG_SCHEMA_NAME 19 -#define SQL_DIAG_TABLE_NAME 20 -#define SQL_DIAG_COLUMN_NAME 21 -#define SQL_DIAG_CURSOR_NAME 22 -#define SQL_DIAG_MESSAGE_LENGTH 23 -#define SQL_DIAG_MESSAGE_OCTET_LENGTH 24 +#define SQL_DIAG_RETURNCODE 1 +#define SQL_DIAG_NUMBER 2 +#define SQL_DIAG_ROW_COUNT 3 +#define SQL_DIAG_SQLSTATE 4 +#define SQL_DIAG_NATIVE 5 +#define SQL_DIAG_MESSAGE_TEXT 6 +#define SQL_DIAG_DYNAMIC_FUNCTION 7 +#define SQL_DIAG_CLASS_ORIGIN 8 +#define SQL_DIAG_SUBCLASS_ORIGIN 9 +#define SQL_DIAG_CONNECTION_NAME 10 +#define SQL_DIAG_SERVER_NAME 11 +#define SQL_DIAG_DYNAMIC_FUNCTION_CODE 12 +#define SQL_DIAG_MORE 13 +#define SQL_DIAG_CONDITION_NUMBER 14 +#define SQL_DIAG_CONSTRAINT_CATALOG 15 +#define SQL_DIAG_CONSTRAINT_SCHEMA 16 +#define SQL_DIAG_CONSTRAINT_NAME 17 +#define SQL_DIAG_CATALOG_NAME 18 +#define SQL_DIAG_SCHEMA_NAME 19 +#define SQL_DIAG_TABLE_NAME 20 +#define SQL_DIAG_COLUMN_NAME 21 +#define SQL_DIAG_CURSOR_NAME 22 +#define SQL_DIAG_MESSAGE_LENGTH 23 +#define SQL_DIAG_MESSAGE_OCTET_LENGTH 24 /* dynamic function codes returned in diagnostics area */ -#define SQL_DIAG_ALTER_DOMAIN 3 -#define SQL_DIAG_ALTER_TABLE 4 -#define SQL_DIAG_CREATE_ASSERTION 6 -#define SQL_DIAG_CREATE_CHARACTER_SET 8 -#define SQL_DIAG_CREATE_COLLATION 10 -#define SQL_DIAG_CREATE_DOMAIN 23 -#define SQL_DIAG_CREATE_SCHEMA 64 -#define SQL_DIAG_CREATE_TABLE 77 -#define SQL_DIAG_CREATE_TRANSLATION 79 -#define SQL_DIAG_CREATE_VIEW 84 -#define SQL_DIAG_DELETE_WHERE 19 -#define SQL_DIAG_DROP_ASSERTION 24 -#define SQL_DIAG_DROP_CHARACTER_SET 25 -#define SQL_DIAG_DROP_COLLATION 26 -#define SQL_DIAG_DROP_DOMAIN 27 -#define SQL_DIAG_DROP_SCHEMA 31 -#define SQL_DIAG_DROP_TABLE 32 -#define SQL_DIAG_DROP_TRANSLATION 33 -#define SQL_DIAG_DROP_VIEW 36 -#define SQL_DIAG_DYNAMIC_DELETE_CURSOR 54 -#define SQL_DIAG_DYNAMIC_UPDATE_CURSOR 55 -#define SQL_DIAG_GRANT 48 -#define SQL_DIAG_INSERT 50 -#define SQL_DIAG_REVOKE 59 -#define SQL_DIAG_SELECT 41 -#define SQL_DIAG_SELECT_CURSOR 85 -#define SQL_DIAG_SET_CATALOG 66 -#define SQL_DIAG_SET_CONSTRAINT 68 -#define SQL_DIAG_SET_NAMES 72 -#define SQL_DIAG_SET_SCHEMA 74 -#define SQL_DIAG_SET_SESSION_AUTHORIZATION 76 -#define SQL_DIAG_SET_TIME_ZONE 71 -#define SQL_DIAG_SET_TRANSACTION 75 -#define SQL_DIAG_UNKNOWN_STATEMENT 0 -#define SQL_DIAG_UPDATE_WHERE 82 +#define SQL_DIAG_ALTER_DOMAIN 3 +#define SQL_DIAG_ALTER_TABLE 4 +#define SQL_DIAG_CREATE_ASSERTION 6 +#define SQL_DIAG_CREATE_CHARACTER_SET 8 +#define SQL_DIAG_CREATE_COLLATION 10 +#define SQL_DIAG_CREATE_DOMAIN 23 +#define SQL_DIAG_CREATE_SCHEMA 64 +#define SQL_DIAG_CREATE_TABLE 77 +#define SQL_DIAG_CREATE_TRANSLATION 79 +#define SQL_DIAG_CREATE_VIEW 84 +#define SQL_DIAG_DELETE_WHERE 19 +#define SQL_DIAG_DROP_ASSERTION 24 +#define SQL_DIAG_DROP_CHARACTER_SET 25 +#define SQL_DIAG_DROP_COLLATION 26 +#define SQL_DIAG_DROP_DOMAIN 27 +#define SQL_DIAG_DROP_SCHEMA 31 +#define SQL_DIAG_DROP_TABLE 32 +#define SQL_DIAG_DROP_TRANSLATION 33 +#define SQL_DIAG_DROP_VIEW 36 +#define SQL_DIAG_DYNAMIC_DELETE_CURSOR 54 +#define SQL_DIAG_DYNAMIC_UPDATE_CURSOR 55 +#define SQL_DIAG_GRANT 48 +#define SQL_DIAG_INSERT 50 +#define SQL_DIAG_REVOKE 59 +#define SQL_DIAG_SELECT 41 +#define SQL_DIAG_SELECT_CURSOR 85 +#define SQL_DIAG_SET_CATALOG 66 +#define SQL_DIAG_SET_CONSTRAINT 68 +#define SQL_DIAG_SET_NAMES 72 +#define SQL_DIAG_SET_SCHEMA 74 +#define SQL_DIAG_SET_SESSION_AUTHORIZATION 76 +#define SQL_DIAG_SET_TIME_ZONE 71 +#define SQL_DIAG_SET_TRANSACTION 75 +#define SQL_DIAG_UNKNOWN_STATEMENT 0 +#define SQL_DIAG_UPDATE_WHERE 82 /* SQL data type codes */ -#define SQL_CHAR 1 -#define SQL_NUMERIC 2 -#define SQL_DECIMAL 3 -#define SQL_INTEGER 4 -#define SQL_SMALLINT 5 -#define SQL_FLOAT 6 -#define SQL_REAL 7 -#define SQL_DOUBLE 8 -#define SQL_DATETIME 9 -#define SQL_INTERVAL 10 -#define SQL_VARCHAR 12 -#define SQL_BIT 14 +#define SQL_CHAR 1 +#define SQL_NUMERIC 2 +#define SQL_DECIMAL 3 +#define SQL_INTEGER 4 +#define SQL_SMALLINT 5 +#define SQL_FLOAT 6 +#define SQL_REAL 7 +#define SQL_DOUBLE 8 +#define SQL_DATETIME 9 +#define SQL_INTERVAL 10 +#define SQL_VARCHAR 12 +#define SQL_BIT 14 #define SQL_BIT_VARYING 15 /* One-parameter shortcuts for datetime data types */ -#define SQL_TYPE_DATE 91 -#define SQL_TYPE_TIME 92 -#define SQL_TYPE_TIME_WITH_TIMEZONE 93 -#define SQL_TYPE_TIMESTAMP 94 +#define SQL_TYPE_DATE 91 +#define SQL_TYPE_TIME 92 +#define SQL_TYPE_TIME_WITH_TIMEZONE 93 +#define SQL_TYPE_TIMESTAMP 94 #define SQL_TYPE_TIMESTAMP_WITH_TIMEZONE 95 -#define SQL_INTERVAL_DAY 103 -#define SQL_INTERVAL_DAY_TO_HOUR 108 -#define SQL_INTERVAL_DAY_TO_MINUTE 109 -#define SQL_INTERVAL_DAY_TO_SECOND 110 -#define SQL_INTERVAL_HOUR 104 -#define SQL_INTERVAL_HOUR_TO_MINUTE 111 -#define SQL_INTERVAL_HOUR_TO_SECOND 112 -#define SQL_INTERVAL_MINUTE 105 -#define SQL_INTERVAL_MINUTE_TO_SECOND 113 -#define SQL_INTERVAL_MONTH 102 -#define SQL_INTERVAL_SECOND 106 -#define SQL_INTERVAL_YEAR 101 -#define SQL_INTERVAL_YEAR_TO_MONTH 107 +#define SQL_INTERVAL_DAY 103 +#define SQL_INTERVAL_DAY_TO_HOUR 108 +#define SQL_INTERVAL_DAY_TO_MINUTE 109 +#define SQL_INTERVAL_DAY_TO_SECOND 110 +#define SQL_INTERVAL_HOUR 104 +#define SQL_INTERVAL_HOUR_TO_MINUTE 111 +#define SQL_INTERVAL_HOUR_TO_SECOND 112 +#define SQL_INTERVAL_MINUTE 105 +#define SQL_INTERVAL_MINUTE_TO_SECOND 113 +#define SQL_INTERVAL_MONTH 102 +#define SQL_INTERVAL_SECOND 106 +#define SQL_INTERVAL_YEAR 101 +#define SQL_INTERVAL_YEAR_TO_MONTH 107 /* GetTypeInfo request for all data types */ -#define SQL_ALL_TYPES 0 +#define SQL_ALL_TYPES 0 /* BindCol() and BindParam() default conversion code */ -#define SQL_DEFAULT 99 +#define SQL_DEFAULT 99 /* GetData code indicating that the application parameter */ /* descriptor specifies the data type */ -#define SQL_ARD_TYPE -99 +#define SQL_ARD_TYPE -99 /* date/time type subcodes */ -#define SQL_CODE_DATE 1 -#define SQL_CODE_TIME 2 -#define SQL_CODE_TIMESTAMP 3 -#define SQL_CODE_TIME_ZONE 4 +#define SQL_CODE_DATE 1 +#define SQL_CODE_TIME 2 +#define SQL_CODE_TIMESTAMP 3 +#define SQL_CODE_TIME_ZONE 4 #define SQL_CODE_TIMESTAMP_ZONE 5 /* interval qualifier codes */ -#define SQL_DAY 3 -#define SQL_DAY_TO_HOUR 8 -#define SQL_DAY_TO_MINUTE 9 -#define SQL_DAY_TO_SECOND 10 -#define SQL_HOUR 4 -#define SQL_HOUR_TO_MINUTE 11 -#define SQL_HOUR_TO_SECOND 12 -#define SQL_MINUTE 5 -#define SQL_MINUTE_TO_SECOND 13 -#define SQL_MONTH 2 -#define SQL_SECOND 6 -#define SQL_YEAR 1 -#define SQL_YEAR_TO_MONTH 7 +#define SQL_DAY 3 +#define SQL_DAY_TO_HOUR 8 +#define SQL_DAY_TO_MINUTE 9 +#define SQL_DAY_TO_SECOND 10 +#define SQL_HOUR 4 +#define SQL_HOUR_TO_MINUTE 11 +#define SQL_HOUR_TO_SECOND 12 +#define SQL_MINUTE 5 +#define SQL_MINUTE_TO_SECOND 13 +#define SQL_MONTH 2 +#define SQL_SECOND 6 +#define SQL_YEAR 1 +#define SQL_YEAR_TO_MONTH 7 /* CLI option values */ -#define SQL_FALSE 0 -#define SQL_TRUE 1 -#define SQL_NONSCROLLABLE 0 -#define SQL_SCROLLABLE 1 +#define SQL_FALSE 0 +#define SQL_TRUE 1 +#define SQL_NONSCROLLABLE 0 +#define SQL_SCROLLABLE 1 /* parameter modes */ -#define SQL_PARAM_MODE_IN 1 -#define SQL_PARAM_MODE_OUT 4 -#define SQL_PARAM_MODE_INOUT 2 -#define SQL_PARAM_MODE_NONE 0 +#define SQL_PARAM_MODE_IN 1 +#define SQL_PARAM_MODE_OUT 4 +#define SQL_PARAM_MODE_INOUT 2 +#define SQL_PARAM_MODE_NONE 0 /* values of NULLABLE field in descriptor */ -#define SQL_NO_NULLS 0 -#define SQL_NULLABLE 1 +#define SQL_NO_NULLS 0 +#define SQL_NULLABLE 1 -/* Values returned by GetTypeInfo for the SEARCHABLE column */ -#define SQL_PRED_NONE 0 -#define SQL_PRED_CHAR 1 -#define SQL_PRED_BASIC 2 +/* Values returned by GetTypeInfo for the SEARCHABLE column */ +#define SQL_PRED_NONE 0 +#define SQL_PRED_CHAR 1 +#define SQL_PRED_BASIC 2 /* values of UNNAMED field in descriptor */ -#define SQL_NAMED 0 -#define SQL_UNNAMED 1 +#define SQL_NAMED 0 +#define SQL_UNNAMED 1 /* values of ALLOC_TYPE field in descriptor */ -#define SQL_DESC_ALLOC_AUTO 1 -#define SQL_DESC_ALLOC_USER 2 +#define SQL_DESC_ALLOC_AUTO 1 +#define SQL_DESC_ALLOC_USER 2 /* EndTran() options */ -#define SQL_COMMIT 0 -#define SQL_ROLLBACK 1 +#define SQL_COMMIT 0 +#define SQL_ROLLBACK 1 /* FreeStmt() options */ -#define SQL_CLOSE 0 -#define SQL_DROP 1 -#define SQL_UNBIND 2 -#define SQL_RESET_PARAMS 3 +#define SQL_CLOSE 0 +#define SQL_DROP 1 +#define SQL_UNBIND 2 +#define SQL_RESET_PARAMS 3 /* null handles returned by AllocHandle() */ -#define SQL_NULL_HENV 0 -#define SQL_NULL_HDBC 0 -#define SQL_NULL_HSTMT 0 -#define SQL_NULL_HDESC 0 +#define SQL_NULL_HENV 0 +#define SQL_NULL_HDBC 0 +#define SQL_NULL_HSTMT 0 +#define SQL_NULL_HDESC 0 /* GetFunctions values to identify CLI routines */ -#define SQL_API_SQLALLOCCONNECT 1 -#define SQL_API_SQLALLOCENV 2 -#define SQL_API_SQLALLOCHANDLE 1001 -#define SQL_API_SQLALLOCSTMT 3 -#define SQL_API_SQLBINDCOL 4 -#define SQL_API_SQLBINDPARAM 1002 -#define SQL_API_SQLCANCEL 5 -#define SQL_API_SQLCLOSECURSOR 1003 -#define SQL_API_SQLCOLATTRIBUTE 6 -#define SQL_API_SQLCONNECT 7 -#define SQL_API_SQLCOPYDESC 1004 -#define SQL_API_SQLDATASOURCES 57 -#define SQL_API_SQLDESCRIBECOL 8 -#define SQL_API_SQLDISCONNECT 9 -#define SQL_API_SQLENDTRAN 1005 -#define SQL_API_SQLERROR 10 -#define SQL_API_SQLEXECDIRECT 11 -#define SQL_API_SQLEXECUTE 12 -#define SQL_API_SQLFETCH 13 -#define SQL_API_SQLFETCHSCROLL 1021 -#define SQL_API_SQLFREECONNECT 14 -#define SQL_API_SQLFREEENV 15 -#define SQL_API_SQLFREEHANDLE 1006 -#define SQL_API_SQLFREESTMT 16 -#define SQL_API_SQLGETCONNECTATTR 1007 -#define SQL_API_SQLGETCURSORNAME 17 -#define SQL_API_SQLGETDATA 43 -#define SQL_API_SQLGETDESCFIELD 1008 -#define SQL_API_SQLGETDESCREC 1009 -#define SQL_API_SQLGETDIAGFIELD 1010 -#define SQL_API_SQLGETDIAGREC 1011 -#define SQL_API_SQLGETENVATTR 1012 -#define SQL_API_SQLGETFUNCTIONS 44 -#define SQL_API_SQLGETINFO 45 -#define SQL_API_SQLGETSTMTATTR 1014 -#define SQL_API_SQLGETTYPEINFO 47 -#define SQL_API_SQLNUMRESULTCOLS 18 -#define SQL_API_SQLPARAMDATA 48 -#define SQL_API_SQLPREPARE 19 -#define SQL_API_SQLPUTDATA 49 -#define SQL_API_SQLRELEASEENV 1015 /* Obsolete? */ -#define SQL_API_SQLROWCOUNT 20 -#define SQL_API_SQLSCROLLFETCH 1021 /* Obsolete? */ -#define SQL_API_SQLSETCONNECTATTR 1016 -#define SQL_API_SQLSETCURSORNAME 21 -#define SQL_API_SQLSETDESCFIELD 1017 -#define SQL_API_SQLSETDESCREC 1018 -#define SQL_API_SQLSETENVATTR 1019 -#define SQL_API_SQLSETSTMTATTR 1020 +#define SQL_API_SQLALLOCCONNECT 1 +#define SQL_API_SQLALLOCENV 2 +#define SQL_API_SQLALLOCHANDLE 1001 +#define SQL_API_SQLALLOCSTMT 3 +#define SQL_API_SQLBINDCOL 4 +#define SQL_API_SQLBINDPARAM 1002 +#define SQL_API_SQLCANCEL 5 +#define SQL_API_SQLCLOSECURSOR 1003 +#define SQL_API_SQLCOLATTRIBUTE 6 +#define SQL_API_SQLCONNECT 7 +#define SQL_API_SQLCOPYDESC 1004 +#define SQL_API_SQLDATASOURCES 57 +#define SQL_API_SQLDESCRIBECOL 8 +#define SQL_API_SQLDISCONNECT 9 +#define SQL_API_SQLENDTRAN 1005 +#define SQL_API_SQLERROR 10 +#define SQL_API_SQLEXECDIRECT 11 +#define SQL_API_SQLEXECUTE 12 +#define SQL_API_SQLFETCH 13 +#define SQL_API_SQLFETCHSCROLL 1021 +#define SQL_API_SQLFREECONNECT 14 +#define SQL_API_SQLFREEENV 15 +#define SQL_API_SQLFREEHANDLE 1006 +#define SQL_API_SQLFREESTMT 16 +#define SQL_API_SQLGETCONNECTATTR 1007 +#define SQL_API_SQLGETCURSORNAME 17 +#define SQL_API_SQLGETDATA 43 +#define SQL_API_SQLGETDESCFIELD 1008 +#define SQL_API_SQLGETDESCREC 1009 +#define SQL_API_SQLGETDIAGFIELD 1010 +#define SQL_API_SQLGETDIAGREC 1011 +#define SQL_API_SQLGETENVATTR 1012 +#define SQL_API_SQLGETFUNCTIONS 44 +#define SQL_API_SQLGETINFO 45 +#define SQL_API_SQLGETSTMTATTR 1014 +#define SQL_API_SQLGETTYPEINFO 47 +#define SQL_API_SQLNUMRESULTCOLS 18 +#define SQL_API_SQLPARAMDATA 48 +#define SQL_API_SQLPREPARE 19 +#define SQL_API_SQLPUTDATA 49 +#define SQL_API_SQLRELEASEENV 1015 /* Obsolete? */ +#define SQL_API_SQLROWCOUNT 20 +#define SQL_API_SQLSCROLLFETCH 1021 /* Obsolete? */ +#define SQL_API_SQLSETCONNECTATTR 1016 +#define SQL_API_SQLSETCURSORNAME 21 +#define SQL_API_SQLSETDESCFIELD 1017 +#define SQL_API_SQLSETDESCREC 1018 +#define SQL_API_SQLSETENVATTR 1019 +#define SQL_API_SQLSETSTMTATTR 1020 /* information requested by GetInfo */ -#define SQL_MAXIMUM_DRIVER_CONNECTIONS 0 -#define SQL_MAXIMUM_CONCURRENT_ACTIVITIES 1 -#define SQL_DATA_SOURCE_NAME 2 -#define SQL_FETCH_DIRECTION 8 -#define SQL_SERVER_NAME 13 -#define SQL_DBMS_NAME 17 -#define SQL_DBMS_VERSION 18 -#define SQL_CURSOR_COMMIT_BEHAVIOR 23 -#define SQL_DATA_SOURCE_READ_ONLY 25 +#define SQL_MAXIMUM_DRIVER_CONNECTIONS 0 +#define SQL_MAXIMUM_CONCURRENT_ACTIVITIES 1 +#define SQL_DATA_SOURCE_NAME 2 +#define SQL_FETCH_DIRECTION 8 +#define SQL_SERVER_NAME 13 +#define SQL_DBMS_NAME 17 +#define SQL_DBMS_VERSION 18 +#define SQL_CURSOR_COMMIT_BEHAVIOR 23 +#define SQL_DATA_SOURCE_READ_ONLY 25 #define SQL_DEFAULT_TRANSACTION_ISOLATION 26 -#define SQL_IDENTIFIER_CASE 28 -#define SQL_MAXIMUM_COLUMN_NAME_LENGTH 30 -#define SQL_MAXIMUM_CURSOR_NAME_LENGTH 31 -#define SQL_MAXIMUM_SCHEMA_NAME_LENGTH 32 +#define SQL_IDENTIFIER_CASE 28 +#define SQL_MAXIMUM_COLUMN_NAME_LENGTH 30 +#define SQL_MAXIMUM_CURSOR_NAME_LENGTH 31 +#define SQL_MAXIMUM_SCHEMA_NAME_LENGTH 32 #define SQL_MAXIMUM_CATALOG_NAME_LENGTH 34 -#define SQL_MAXIMUM_TABLE_NAME_LENGTH 35 -#define SQL_SCROLL_CONCURRENCY 43 -#define SQL_TRANSACTION_CAPABLE 46 -#define SQL_USER_NAME 47 +#define SQL_MAXIMUM_TABLE_NAME_LENGTH 35 +#define SQL_SCROLL_CONCURRENCY 43 +#define SQL_TRANSACTION_CAPABLE 46 +#define SQL_USER_NAME 47 #define SQL_TRANSACTION_ISOLATION_OPTION 72 -#define SQL_INTEGRITY 73 -#define SQL_GETDATA_EXTENSIONS 81 -#define SQL_NULL_COLLATION 85 -#define SQL_ALTER_TABLE 86 -#define SQL_ORDER_BY_COLUMNS_IN_SELECT 90 -#define SQL_SPECIAL_CHARACTERS 94 +#define SQL_INTEGRITY 73 +#define SQL_GETDATA_EXTENSIONS 81 +#define SQL_NULL_COLLATION 85 +#define SQL_ALTER_TABLE 86 +#define SQL_ORDER_BY_COLUMNS_IN_SELECT 90 +#define SQL_SPECIAL_CHARACTERS 94 #define SQL_MAXIMUM_COLUMNS_IN_GROUP_BY 97 #define SQL_MAXIMUM_COLUMNS_IN_ORDER_BY 99 -#define SQL_MAXIMUM_COLUMNS_IN_SELECT 100 -#define SQL_MAXIMUM_COLUMNS_IN_TABLE 101 -#define SQL_MAXIMUM_STATEMENT_LENGTH 105 -#define SQL_MAXIMUM_TABLES_IN_SELECT 106 -#define SQL_MAXIMUM_USER_NAME_LENGTH 107 -#define SQL_OUTER_JOIN_CAPABILITIES 115 -#define SQL_CURSOR_SENSITIVITY 10001 -#define SQL_DESCRIBE_PARAMETER 10002 -#define SQL_CATALOG_NAME 10003 -#define SQL_COLLATING_SEQUENCE 10004 -#define SQL_MAXIMUM_IDENTIFIER_LENGTH 10005 +#define SQL_MAXIMUM_COLUMNS_IN_SELECT 100 +#define SQL_MAXIMUM_COLUMNS_IN_TABLE 101 +#define SQL_MAXIMUM_STATEMENT_LENGTH 105 +#define SQL_MAXIMUM_TABLES_IN_SELECT 106 +#define SQL_MAXIMUM_USER_NAME_LENGTH 107 +#define SQL_OUTER_JOIN_CAPABILITIES 115 +#define SQL_CURSOR_SENSITIVITY 10001 +#define SQL_DESCRIBE_PARAMETER 10002 +#define SQL_CATALOG_NAME 10003 +#define SQL_COLLATING_SEQUENCE 10004 +#define SQL_MAXIMUM_IDENTIFIER_LENGTH 10005 /* S-resource attribute values for cursor sensitivity */ -#define SQL_UNSPECIFIED 0x00000000L -#define SQL_INSENSITIVE 0x00000001L +#define SQL_UNSPECIFIED 0x00000000L +#define SQL_INSENSITIVE 0x00000001L /* null handle used when allocating HENV */ -#define SQL_NULL_HANDLE 0L +#define SQL_NULL_HANDLE 0L /* SQL_ALTER_TABLE bitmasks */ -#define SQL_AT_ADD_COLUMN 0x00000001L -#define SQL_AT_DROP_COLUMN 0x00000002L -#define SQL_AT_ALTER_COLUMN 0x00000004L -#define SQL_AT_ADD_CONSTRAINT 0x00000008L -#define SQL_AT_DROP_CONSTRAINT 0x00000010L +#define SQL_AT_ADD_COLUMN 0x00000001L +#define SQL_AT_DROP_COLUMN 0x00000002L +#define SQL_AT_ALTER_COLUMN 0x00000004L +#define SQL_AT_ADD_CONSTRAINT 0x00000008L +#define SQL_AT_DROP_CONSTRAINT 0x00000010L /* SQL_CURSOR_COMMIT_BEHAVIOR values */ -#define SQL_CB_DELETE 0 -#define SQL_CB_CLOSE 1 -#define SQL_CB_PRESERVE 2 +#define SQL_CB_DELETE 0 +#define SQL_CB_CLOSE 1 +#define SQL_CB_PRESERVE 2 /* SQL_FETCH_DIRECTION bitmasks */ -#define SQL_FD_FETCH_NEXT 0x00000001L -#define SQL_FD_FETCH_FIRST 0x00000002L -#define SQL_FD_FETCH_LAST 0x00000004L -#define SQL_FD_FETCH_PRIOR 0x00000008L -#define SQL_FD_FETCH_ABSOLUTE 0x00000010L -#define SQL_FD_FETCH_RELATIVE 0x00000020L +#define SQL_FD_FETCH_NEXT 0x00000001L +#define SQL_FD_FETCH_FIRST 0x00000002L +#define SQL_FD_FETCH_LAST 0x00000004L +#define SQL_FD_FETCH_PRIOR 0x00000008L +#define SQL_FD_FETCH_ABSOLUTE 0x00000010L +#define SQL_FD_FETCH_RELATIVE 0x00000020L /* SQL_GETDATA_EXTENSIONS bitmasks */ -#define SQL_GD_ANY_COLUMN 0x00000001L -#define SQL_FD_ANY_ORDER 0x00000002L +#define SQL_GD_ANY_COLUMN 0x00000001L +#define SQL_FD_ANY_ORDER 0x00000002L /* SQL_IDENTIFIER_CASE values */ -#define SQL_IC_UPPER 1 -#define SQL_IC_LOWER 2 -#define SQL_IC_SENSITIVE 3 -#define SQL_IC_MIXED 4 +#define SQL_IC_UPPER 1 +#define SQL_IC_LOWER 2 +#define SQL_IC_SENSITIVE 3 +#define SQL_IC_MIXED 4 /* SQL_IDENTIFIER_CASE values */ -#define SQL_NC_HIGH 1 -#define SQL_NC_LOW 2 +#define SQL_NC_HIGH 1 +#define SQL_NC_LOW 2 /* SQL_OUTER_JOIN_CAPABILITIES bitmasks */ -#define SQL_OUTER_JOIN_LEFT 0x00000001L -#define SQL_OUTER_JOIN_RIGHT 0x00000002L -#define SQL_OUTER_JOIN_FULL 0x00000004L -#define SQL_OUTER_JOIN_NESTED 0x00000008L -#define SQL_OUTER_JOIN_NOT_ORDERED 0x00000010L -#define SQL_OUTER_JOIN_INNER 0x00000020L -#define SQL_OUTER_JOIN_ALL_COMPARISION_OPS 0x00000040L +#define SQL_OUTER_JOIN_LEFT 0x00000001L +#define SQL_OUTER_JOIN_RIGHT 0x00000002L +#define SQL_OUTER_JOIN_FULL 0x00000004L +#define SQL_OUTER_JOIN_NESTED 0x00000008L +#define SQL_OUTER_JOIN_NOT_ORDERED 0x00000010L +#define SQL_OUTER_JOIN_INNER 0x00000020L +#define SQL_OUTER_JOIN_ALL_COMPARISION_OPS 0x00000040L /* SQL_SCROLL_CONCURRENCY bitmasks */ -#define SQL_SCCO_READ_ONLY 0x00000001L -#define SQL_SCCO_LOCK 0x00000002L -#define SQL_SCCO_OPT_ROWVER 0x00000004L -#define SQL_SCCO_OPT_VALUES 0x00000008L +#define SQL_SCCO_READ_ONLY 0x00000001L +#define SQL_SCCO_LOCK 0x00000002L +#define SQL_SCCO_OPT_ROWVER 0x00000004L +#define SQL_SCCO_OPT_VALUES 0x00000008L /* SQL_IDENTIFIER_CASE values */ -#define SQL_TC_NONE 0 -#define SQL_TC_DML 1 -#define SQL_TC_ALL 2 -#define SQL_TC_DDL_COMMIT 3 -#define SQL_TC_DDL_IGNORE 4 +#define SQL_TC_NONE 0 +#define SQL_TC_DML 1 +#define SQL_TC_ALL 2 +#define SQL_TC_DDL_COMMIT 3 +#define SQL_TC_DDL_IGNORE 4 /* SQL_TRANSACTION_ISOLATION bitmasks */ -#define SQL_TRANSACTION_READ_UNCOMMITTED 0x00000001L -#define SQL_TRANSACTION_READ_COMMITTED 0x00000002L +#define SQL_TRANSACTION_READ_UNCOMMITTED 0x00000001L +#define SQL_TRANSACTION_READ_COMMITTED 0x00000002L #define SQL_TRANSACTION_READ_REPEATABLE_READ 0x00000004L -#define SQL_TRANSACTION_READ_SERIALIZABLE 0x00000008L +#define SQL_TRANSACTION_READ_SERIALIZABLE 0x00000008L -#define SQL_TRANSACTION_READ_UNCOMMITTED 0x00000001L -#define SQL_TRANSACTION_READ_UNCOMMITTED 0x00000001L -#define SQL_FD_FETCH_NEXT 0x00000001L +#define SQL_TRANSACTION_READ_UNCOMMITTED 0x00000001L +#define SQL_TRANSACTION_READ_UNCOMMITTED 0x00000001L +#define SQL_FD_FETCH_NEXT 0x00000001L /* CLI function signatures */ -SQLRETURN SQLAllocConnect(SQLHENV EnvironmentHandle, - SQLHDBC *ConnectionHandle); +SQLRETURN SQLAllocConnect(SQLHENV EnvironmentHandle, + SQLHDBC * ConnectionHandle); -SQLRETURN SQLAllocEnv(SQLHENV *EnvironmentHandle); +SQLRETURN SQLAllocEnv(SQLHENV * EnvironmentHandle); -SQLRETURN SQLAllocHandle(SQLSMALLINT HandleType, - SQLINTEGER InputHandle, - SQLINTEGER *OutputHandle); +SQLRETURN SQLAllocHandle(SQLSMALLINT HandleType, + SQLINTEGER InputHandle, + SQLINTEGER * OutputHandle); -SQLRETURN SQLAllocStmt(SQLHDBC ConnectionHandle, - SQLSTMT *StatementHandle); +SQLRETURN SQLAllocStmt(SQLHDBC ConnectionHandle, + SQLSTMT * StatementHandle); -SQLRETURN SQLBindCol(SQLHSTMT StatementHandle, - SQLSMALLINT ColumnNumber, - SQLSMALLINT BufferType, - SQLPOINTER Data, - SQLINTEGER BufferLength, - SQLINTEGER *DataLength); +SQLRETURN SQLBindCol(SQLHSTMT StatementHandle, + SQLSMALLINT ColumnNumber, + SQLSMALLINT BufferType, + SQLPOINTER Data, + SQLINTEGER BufferLength, + SQLINTEGER * DataLength); -SQLRETURN SQLBindParam(SQLHSTMT StatementHandle, - SQLSMALLINT ParamNumber, - SQLSMALLINT BufferType, - SQLSMALLINT ParamType, - SQLINTEGER ParamLength, - SQLSMALLINT Scale, - SQLPOINTER Data, - SQLINTEGER *DataLength); - -SQLRETURN SQLCancel(SQLHSTMT StatementHandle); - -SQLRETURN SQLCloseCursor(SQLHSTMT StatementHandle); - -SQLRETURN SQLColAttribute(SQLHSTMT StatementHandle, +SQLRETURN SQLBindParam(SQLHSTMT StatementHandle, + SQLSMALLINT ParamNumber, + SQLSMALLINT BufferType, + SQLSMALLINT ParamType, + SQLINTEGER ParamLength, + SQLSMALLINT Scale, + SQLPOINTER Data, + SQLINTEGER * DataLength); + +SQLRETURN SQLCancel(SQLHSTMT StatementHandle); + +SQLRETURN SQLCloseCursor(SQLHSTMT StatementHandle); + +SQLRETURN SQLColAttribute(SQLHSTMT StatementHandle, + SQLSMALLINT ColumnNumber, + SQLSMALLINT FieldIdentifier, + SQLCHAR * CharacterAttribute, + SQLINTEGER BufferLength, + SQLINTEGER * AttributetLength, + SQLINTEGER * NumericAttribute); + +SQLRETURN SQLConnect(SQLHDBC ConnectionHandle, + SQLCHAR * ServerName, + SQLSMALLINT NameLength1, + SQLCHAR * UserName, + SQLSMALLINT NameLength2, + SQLCHAR * Authentication, + SQLSMALLINT NameLength3); + +SQLRETURN SQLCopyDesc(SQLHDESC SourceDescHandle, + SQLHDESC TargetDescHandle); + +SQLRETURN SQLDataSources(SQLHENV EnvironmentHandle, + SQLSMALLINT Direction, + SQLCHAR * ServerName, + SQLSMALLINT BufferLength1, + SQLSMALLINT * NameLength1, + SQLCHAR * Description, + SQLSMALLINT BufferLength2, + SQLSMALLINT * NameLength2); + +SQLRETURN SQLDescribeCol(SQLHSTMT StatementHandle, SQLSMALLINT ColumnNumber, - SQLSMALLINT FieldIdentifier, - SQLCHAR *CharacterAttribute, - SQLINTEGER BufferLength, - SQLINTEGER *AttributetLength, - SQLINTEGER *NumericAttribute); - -SQLRETURN SQLConnect(SQLHDBC ConnectionHandle, - SQLCHAR *ServerName, - SQLSMALLINT NameLength1, - SQLCHAR *UserName, - SQLSMALLINT NameLength2, - SQLCHAR *Authentication, - SQLSMALLINT NameLength3); - -SQLRETURN SQLCopyDesc(SQLHDESC SourceDescHandle, - SQLHDESC TargetDescHandle); - -SQLRETURN SQLDataSources(SQLHENV EnvironmentHandle, - SQLSMALLINT Direction, - SQLCHAR *ServerName, - SQLSMALLINT BufferLength1, - SQLSMALLINT *NameLength1, - SQLCHAR *Description, - SQLSMALLINT BufferLength2, - SQLSMALLINT *NameLength2); - -SQLRETURN SQLDescribeCol(SQLHSTMT StatementHandle, - SQLSMALLINT ColumnNumber, - SQLCHAR *ColumnName, + SQLCHAR * ColumnName, + SQLSMALLINT BufferLength, + SQLSMALLINT * ColumnNameLength, + SQLSMALLINT * ColumnType, + SQLINTEGER * ColumnLength, + SQLSMALLINT * ColumnScale, + SQLSMALLINT * Nullable); + +SQLRETURN SQLDisconnect(SQLHDBC ConnectionHandle); + +SQLRETURN SQLEndTran(SQLSMALLINT HandleType, + SQLHENV Handle, + SQLSMALLINT CompletionType); + +SQLRETURN SQLError(SQLHENV EnvironmentHandle, + SQLHDBC ConnectionHandle, + SQLSTMT StatementHandle, + SQLCHAR * Sqlstate, + SQLINTEGER * NativeError, + SQLCHAR * MessageText, + SQLINTEGER BufferLength, + SQLINTEGER * TextLength); + +SQLRETURN SQLExecDirect(SQLHSTMT StatementHandle, + SQLCHAR * StatementText, + SQLSMALLINT StringLength); + +SQLRETURN SQLExecute(SQLHSTMT StatementHandle); + +SQLRETURN SQLFetch(SQLHSTMT StatementHandle); + +SQLRETURN SQLFetchScroll(SQLHSTMT StatementHandle, + SQLSMALLINT FetchOrientation, + SQLINTEGER FetchOffset); + +SQLRETURN SQLFreeConnect(SQLHDBC ConnectionHandle); + +SQLRETURN SQLFreeEnv(SQLHENV EnvironmentHandle); + +SQLRETURN SQLFreeHandle(SQLSMALLINT HandleType, + SQLINTEGER Handle); + +SQLRETURN SQLFreeStmt(SQLHSTMT StatementHandle); + +SQLRETURN SQLGetConnectAttr(SQLHDBC ConnectionHandle, + SQLINTEGER Attribute, + SQLPOINTER Value, + SQLINTEGER BufferLength, + SQLINTEGER * StringLength); + +SQLRETURN SQLGetCursorName(SQLHSTMT StatementHandle, + SQLCHAR * CursorName, + SQLSMALLINT BufferLength, + SQLSMALLINT * NameLength); + +SQLRETURN SQLGetData(SQLHSTMT StatementHandle, + SQLSMALLINT ColumnNumber, + SQLSMALLINT TargetType, + SQLPOINTER TargetValue, + SQLINTEGER BufferLength, + SQLINTEGER * IndicatorValue); + +SQLRETURN SQLGetDescField(SQLHDESC DescriptorHandle, + SQLSMALLINT RecordNumber, + SQLSMALLINT FieldIdentifier, + SQLPOINTER Value, + SQLINTEGER BufferLength, + SQLINTEGER * StringLength); + +SQLRETURN SQLGetDescRec(SQLHDESC DescriptorHandle, + SQLSMALLINT RecordNumber, + SQLCHAR * Name, SQLSMALLINT BufferLength, - SQLSMALLINT *ColumnNameLength, - SQLSMALLINT *ColumnType, - SQLINTEGER *ColumnLength, - SQLSMALLINT *ColumnScale, - SQLSMALLINT *Nullable); - -SQLRETURN SQLDisconnect(SQLHDBC ConnectionHandle); - -SQLRETURN SQLEndTran(SQLSMALLINT HandleType, - SQLHENV Handle, - SQLSMALLINT CompletionType); - -SQLRETURN SQLError(SQLHENV EnvironmentHandle, - SQLHDBC ConnectionHandle, - SQLSTMT StatementHandle, - SQLCHAR *Sqlstate, - SQLINTEGER *NativeError, - SQLCHAR *MessageText, - SQLINTEGER BufferLength, - SQLINTEGER *TextLength); - -SQLRETURN SQLExecDirect(SQLHSTMT StatementHandle, - SQLCHAR *StatementText, - SQLSMALLINT StringLength); - -SQLRETURN SQLExecute(SQLHSTMT StatementHandle); - -SQLRETURN SQLFetch(SQLHSTMT StatementHandle); - -SQLRETURN SQLFetchScroll(SQLHSTMT StatementHandle, - SQLSMALLINT FetchOrientation, - SQLINTEGER FetchOffset); - -SQLRETURN SQLFreeConnect(SQLHDBC ConnectionHandle); - -SQLRETURN SQLFreeEnv(SQLHENV EnvironmentHandle); - -SQLRETURN SQLFreeHandle(SQLSMALLINT HandleType, - SQLINTEGER Handle); - -SQLRETURN SQLFreeStmt(SQLHSTMT StatementHandle); + SQLSMALLINT * StringLength, + SQLSMALLINT * Type, + SQLSMALLINT * SubType, + SQLINTEGER * Length, + SQLSMALLINT * Precision, + SQLSMALLINT * Scale, + SQLSMALLINT * Nullable); + +SQLRETURN SQLGetDiagField(SQLSMALLINT HandleType, + SQLINTEGER Handle, + SQLSMALLINT RecordNumber, + SQLSMALLINT DiagIdentifier, + SQLPOINTER DiagInfo, + SQLSMALLINT BufferLength, + SQLSMALLINT * StringLength); + + +SQLRETURN SQLGetDiagRec(SQLSMALLINT HandleType, + SQLINTEGER Handle, + SQLSMALLINT RecordNumber, + SQLCHAR * Sqlstate, + SQLINTEGER * NativeError, + SQLCHAR * MessageText, + SQLSMALLINT BufferLength, + SQLSMALLINT * StringLength); -SQLRETURN SQLGetConnectAttr(SQLHDBC ConnectionHandle, - SQLINTEGER Attribute, - SQLPOINTER Value, - SQLINTEGER BufferLength, - SQLINTEGER *StringLength); +SQLRETURN SQLGetEnvAttr(SQLHENV EnvironmentHandle, + SQLINTEGER Attribute, + SQLPOINTER Value, + SQLINTEGER BufferLength, + SQLINTEGER * StringLength); -SQLRETURN SQLGetCursorName(SQLHSTMT StatementHandle, - SQLCHAR *CursorName, - SQLSMALLINT BufferLength, - SQLSMALLINT *NameLength); +SQLRETURN SQLGetFunctions(SQLHDBC ConnectionHandle, + SQLSMALLINT FunctionId, + SQLSMALLINT * Supported); -SQLRETURN SQLGetData(SQLHSTMT StatementHandle, - SQLSMALLINT ColumnNumber, - SQLSMALLINT TargetType, - SQLPOINTER TargetValue, - SQLINTEGER BufferLength, - SQLINTEGER *IndicatorValue); +SQLRETURN SQLGetInfo(SQLHDBC ConnectionHandle, + SQLSMALLINT InfoType, + SQLPOINTER InfoValue, + SQLSMALLINT BufferLength, + SQLSMALLINT * StringLength); -SQLRETURN SQLGetDescField(SQLHDESC DescriptorHandle, - SQLSMALLINT RecordNumber, - SQLSMALLINT FieldIdentifier, +SQLRETURN SQLGetStmtAttr(SQLHSTMT StatementHandle, + SQLINTEGER Attribute, SQLPOINTER Value, SQLINTEGER BufferLength, - SQLINTEGER *StringLength); - -SQLRETURN SQLGetDescRec(SQLHDESC DescriptorHandle, - SQLSMALLINT RecordNumber, - SQLCHAR *Name, - SQLSMALLINT BufferLength, - SQLSMALLINT *StringLength, - SQLSMALLINT *Type, - SQLSMALLINT *SubType, - SQLINTEGER *Length, - SQLSMALLINT *Precision, - SQLSMALLINT *Scale, - SQLSMALLINT *Nullable); - -SQLRETURN SQLGetDiagField(SQLSMALLINT HandleType, - SQLINTEGER Handle, - SQLSMALLINT RecordNumber, - SQLSMALLINT DiagIdentifier, - SQLPOINTER DiagInfo, - SQLSMALLINT BufferLength, - SQLSMALLINT *StringLength); - - -SQLRETURN SQLGetDiagRec(SQLSMALLINT HandleType, - SQLINTEGER Handle, - SQLSMALLINT RecordNumber, - SQLCHAR *Sqlstate, - SQLINTEGER *NativeError, - SQLCHAR *MessageText, - SQLSMALLINT BufferLength, - SQLSMALLINT *StringLength); - -SQLRETURN SQLGetEnvAttr(SQLHENV EnvironmentHandle, - SQLINTEGER Attribute, - SQLPOINTER Value, - SQLINTEGER BufferLength, - SQLINTEGER *StringLength); - -SQLRETURN SQLGetFunctions(SQLHDBC ConnectionHandle, - SQLSMALLINT FunctionId, - SQLSMALLINT *Supported); - -SQLRETURN SQLGetInfo(SQLHDBC ConnectionHandle, - SQLSMALLINT InfoType, - SQLPOINTER InfoValue, - SQLSMALLINT BufferLength, - SQLSMALLINT *StringLength); - -SQLRETURN SQLGetStmtAttr(SQLHSTMT StatementHandle, - SQLINTEGER Attribute, - SQLPOINTER Value, - SQLINTEGER BufferLength, - SQLINTEGER *StringLength); + SQLINTEGER * StringLength); -SQLRETURN SQLGetTypeInfo(SQLHSTMT StatementHandle, - SQLSMALLINT DataType); +SQLRETURN SQLGetTypeInfo(SQLHSTMT StatementHandle, + SQLSMALLINT DataType); -SQLRETURN SQLNumResultCols(SQLHSTMT StatementHandle, - SQLINTEGER *ColumnCount); +SQLRETURN SQLNumResultCols(SQLHSTMT StatementHandle, + SQLINTEGER * ColumnCount); -SQLRETURN SQLParamData(SQLHSTMT StatementHandle, - SQLPOINTER *Value); +SQLRETURN SQLParamData(SQLHSTMT StatementHandle, + SQLPOINTER * Value); -SQLRETURN SQLPrepare(SQLHSTMT StatementHandle, - SQLCHAR *StatementText, - SQLSMALLINT StringLength); +SQLRETURN SQLPrepare(SQLHSTMT StatementHandle, + SQLCHAR * StatementText, + SQLSMALLINT StringLength); -SQLRETURN SQLPutData(SQLHSTMT StatementHandle, - SQLPOINTER Data, - SQLINTEGER StringLength); +SQLRETURN SQLPutData(SQLHSTMT StatementHandle, + SQLPOINTER Data, + SQLINTEGER StringLength); -SQLRETURN SQLRowCount(SQLHSTMT StatementHandle, - SQLINTEGER *RowCount); +SQLRETURN SQLRowCount(SQLHSTMT StatementHandle, + SQLINTEGER * RowCount); -SQLRETURN SQLSetConnectAttr(SQLHDBC ConnectionHandle, - SQLINTEGER AttributeCursorName, - SQLPOINTER Value, - SQLINTEGER StringLength); +SQLRETURN SQLSetConnectAttr(SQLHDBC ConnectionHandle, + SQLINTEGER AttributeCursorName, + SQLPOINTER Value, + SQLINTEGER StringLength); -SQLRETURN SQLSetCursorName(SQLHSTMT StatementHandle, - SQLCHAR *CursorName, - SQLSMALLINT NameLength); +SQLRETURN SQLSetCursorName(SQLHSTMT StatementHandle, + SQLCHAR * CursorName, + SQLSMALLINT NameLength); -SQLRETURN SQLSetDescField(SQLHDESC DescriptorHandle, - SQLSMALLINT RecordNumber, - SQLSMALLINT FieldIdentifier, - SQLPOINTER Value, SQLINTEGER BufferLength); +SQLRETURN SQLSetDescField(SQLHDESC DescriptorHandle, + SQLSMALLINT RecordNumber, + SQLSMALLINT FieldIdentifier, + SQLPOINTER Value, SQLINTEGER BufferLength); -SQLRETURN SQLSetDescRec(SQLHDESC DescriptorHandle, - SQLSMALLINT RecordNumber, - SQLSMALLINT Type, - SQLSMALLINT SubType, - SQLINTEGER Length, - SQLSMALLINT Precision, - SQLSMALLINT Scale, - SQLPOINTER Data, - SQLINTEGER *StringLength, - SQLSMALLINT *Indicator); +SQLRETURN SQLSetDescRec(SQLHDESC DescriptorHandle, + SQLSMALLINT RecordNumber, + SQLSMALLINT Type, + SQLSMALLINT SubType, + SQLINTEGER Length, + SQLSMALLINT Precision, + SQLSMALLINT Scale, + SQLPOINTER Data, + SQLINTEGER * StringLength, + SQLSMALLINT * Indicator); -SQLRETURN SQLSetEnvAttr(SQLHENV EnvironmentHandle, - SQLINTEGER Attribute, - SQLPOINTER Value, - SQLINTEGER StringLength); - -SQLRETURN SQLSetStmtAttr(SQLHSTMT StatementHandle, +SQLRETURN SQLSetEnvAttr(SQLHENV EnvironmentHandle, SQLINTEGER Attribute, SQLPOINTER Value, SQLINTEGER StringLength); +SQLRETURN SQLSetStmtAttr(SQLHSTMT StatementHandle, + SQLINTEGER Attribute, + SQLPOINTER Value, + SQLINTEGER StringLength); + /* These are in SQL3 from August 1994 * but not in Date and Darwen, 1997 * - Thomas Lockhart 1999-06-17 diff --git a/src/interfaces/ecpg/include/ecpgerrno.h b/src/interfaces/ecpg/include/ecpgerrno.h index 37443badcd2..2a826988be5 100644 --- a/src/interfaces/ecpg/include/ecpgerrno.h +++ b/src/interfaces/ecpg/include/ecpgerrno.h @@ -14,7 +14,7 @@ /* first we have a set of ecpg messages, they start at 200 */ #define ECPG_UNSUPPORTED -200 -#define ECPG_TOO_MANY_ARGUMENTS -201 +#define ECPG_TOO_MANY_ARGUMENTS -201 #define ECPG_TOO_FEW_ARGUMENTS -202 #define ECPG_TOO_MANY_MATCHES -203 #define ECPG_INT_FORMAT -204 diff --git a/src/interfaces/ecpg/include/ecpglib.h b/src/interfaces/ecpg/include/ecpglib.h index 8b8dd3f3b5c..8b7e1ecd403 100644 --- a/src/interfaces/ecpg/include/ecpglib.h +++ b/src/interfaces/ecpg/include/ecpglib.h @@ -17,27 +17,27 @@ extern "C" bool ECPGprepare(int, char *, char *); bool ECPGdeallocate(int, char *); bool ECPGdeallocate_all(int); - char *ECPGprepared_statement(char *); - + char *ECPGprepared_statement(char *); + void ECPGlog(const char *format,...); - + /* print an error message */ void sqlprint(void); - + /* define this for simplicity as well as compatibility */ #define SQLCODE sqlca.sqlcode /* dynamic SQL */ - bool ECPGdo_descriptor(int line,const char *connection, - const char *descriptor,const char *query); - bool ECPGdeallocate_desc(int line,const char *name); - bool ECPGallocate_desc(int line,const char *name); + bool ECPGdo_descriptor(int line, const char *connection, + const char *descriptor, const char *query); + bool ECPGdeallocate_desc(int line, const char *name); + bool ECPGallocate_desc(int line, const char *name); void ECPGraise(int line, int code, char *str); bool ECPGget_desc_header(int, char *, int *); - bool ECPGget_desc(int, char *, int, ...); - + bool ECPGget_desc(int, char *, int,...); + #ifdef __cplusplus } diff --git a/src/interfaces/ecpg/include/ecpgtype.h b/src/interfaces/ecpg/include/ecpgtype.h index b19ba177c0c..8268e5495bd 100644 --- a/src/interfaces/ecpg/include/ecpgtype.h +++ b/src/interfaces/ecpg/include/ecpgtype.h @@ -50,7 +50,7 @@ extern "C" ECPGt_NO_INDICATOR /* no indicator */ }; - /* descriptor items */ + /* descriptor items */ enum ECPGdtype { ECPGd_count, diff --git a/src/interfaces/ecpg/include/sql3types.h b/src/interfaces/ecpg/include/sql3types.h index 3aa86f50f09..e7e153f34ca 100644 --- a/src/interfaces/ecpg/include/sql3types.h +++ b/src/interfaces/ecpg/include/sql3types.h @@ -2,12 +2,14 @@ * * Copyright (c) 2000, Christof Petig <christof.petig@wtal.de> * - * $Header: /cvsroot/pgsql/src/interfaces/ecpg/include/sql3types.h,v 1.3 2000/03/17 23:26:30 tgl Exp $ + * $Header: /cvsroot/pgsql/src/interfaces/ecpg/include/sql3types.h,v 1.4 2000/04/12 17:17:01 momjian Exp $ */ /* chapter 13.1 table 2: Codes used for SQL data types in Dynamic SQL */ -enum { SQL3_CHARACTER=1, +enum +{ + SQL3_CHARACTER = 1, SQL3_NUMERIC, SQL3_DECIMAL, SQL3_INTEGER, @@ -16,23 +18,26 @@ enum { SQL3_CHARACTER=1, SQL3_REAL, SQL3_DOUBLE_PRECISION, SQL3_DATE_TIME_TIMESTAMP, - SQL3_INTERVAL, /* 10 */ - SQL3_CHARACTER_VARYING=12, + SQL3_INTERVAL, /* 10 */ + SQL3_CHARACTER_VARYING = 12, SQL3_ENUMERATED, SQL3_BIT, SQL3_BIT_VARYING, SQL3_BOOLEAN, SQL3_abstract /* the rest is xLOB stuff */ - }; +}; /* chapter 13.1 table 3: Codes associated with datetime data types in Dynamic SQL */ -enum { SQL3_DDT_DATE=1, +enum +{ + SQL3_DDT_DATE = 1, SQL3_DDT_TIME, SQL3_DDT_TIMESTAMP, SQL3_DDT_TIME_WITH_TIME_ZONE, SQL3_DDT_TIMESTAMP_WITH_TIME_ZONE, - - SQL3_DDT_ILLEGAL /* not a datetime data type (not part of standard) */ - }; + + SQL3_DDT_ILLEGAL /* not a datetime data type (not part of + * standard) */ +}; diff --git a/src/interfaces/ecpg/include/sqlca.h b/src/interfaces/ecpg/include/sqlca.h index 0fa4a624181..71987648b4d 100644 --- a/src/interfaces/ecpg/include/sqlca.h +++ b/src/interfaces/ecpg/include/sqlca.h @@ -21,7 +21,7 @@ extern "C" char sqlerrp[8]; long sqlerrd[6]; /* Element 0: empty */ - /* 1: OID of processed tuple if applicable */ + /* 1: OID of processed tuple if applicable */ /* 2: number of rows processed */ /* after an INSERT, UPDATE or */ /* DELETE statement */ @@ -48,6 +48,7 @@ extern "C" #ifdef __cplusplus } + #endif #endif diff --git a/src/interfaces/ecpg/lib/connect.c b/src/interfaces/ecpg/lib/connect.c index 0a4d915c3e9..8452271926e 100644 --- a/src/interfaces/ecpg/lib/connect.c +++ b/src/interfaces/ecpg/lib/connect.c @@ -4,7 +4,8 @@ #include "extern.h" #include <sqlca.h> -static struct connection *all_connections = NULL, *actual_connection = NULL; +static struct connection *all_connections = NULL, + *actual_connection = NULL; struct connection * get_connection(const char *connection_name) @@ -58,10 +59,10 @@ ECPGsetcommit(int lineno, const char *mode, const char *connection_name) PGresult *results; if (!ecpg_init(con, connection_name, lineno)) - return(false); + return (false); ECPGlog("ECPGsetcommit line %d action = %s connection = %s\n", lineno, mode, con->name); - + if (con->autocommit == true && strncmp(mode, "off", strlen("off")) == 0) { if (con->committed) @@ -100,7 +101,7 @@ ECPGsetconn(int lineno, const char *connection_name) struct connection *con = get_connection(connection_name); if (!ecpg_init(con, connection_name, lineno)) - return(false); + return (false); actual_connection = con; return true; @@ -112,7 +113,7 @@ ECPGconnect(int lineno, const char *dbname, const char *user, const char *passwd struct connection *this; init_sqlca(); - + if ((this = (struct connection *) ecpg_alloc(sizeof(struct connection), lineno)) == NULL) return false; @@ -171,7 +172,7 @@ ECPGdisconnect(int lineno, const char *connection_name) con = get_connection(connection_name); if (!ecpg_init(con, connection_name, lineno)) - return(false); + return (false); else ecpg_finish(con); } diff --git a/src/interfaces/ecpg/lib/data.c b/src/interfaces/ecpg/lib/data.c index b7398caf6d7..1b97478e20d 100644 --- a/src/interfaces/ecpg/lib/data.c +++ b/src/interfaces/ecpg/lib/data.c @@ -8,11 +8,11 @@ bool get_data(PGresult *results, int act_tuple, int act_field, int lineno, - enum ECPGttype type, enum ECPGttype ind_type, - void *var, void *ind, long varcharsize, long offset, - bool isarray) + enum ECPGttype type, enum ECPGttype ind_type, + void *var, void *ind, long varcharsize, long offset, + bool isarray) { - char *pval = (char *)PQgetvalue(results, act_tuple, act_field); + char *pval = (char *) PQgetvalue(results, act_tuple, act_field); ECPGlog("get_data line %d: RESULT: %s\n", lineno, pval ? pval : ""); @@ -20,20 +20,20 @@ get_data(PGresult *results, int act_tuple, int act_field, int lineno, /* let's check is it really is an array if it should be */ if (isarray) { - if (*pval != '{') + if (*pval != '{') { ECPGlog("get_data data entry does not look like an array in line %d\n", lineno); ECPGraise(lineno, ECPG_DATA_NOT_ARRAY, NULL); - return(false); + return (false); } - else ++pval; + else + ++pval; } /* We will have to decode the value */ /* - * check for null value and set indicator - * accordingly + * check for null value and set indicator accordingly */ switch (ind_type) { @@ -61,226 +61,226 @@ get_data(PGresult *results, int act_tuple, int act_field, int lineno, return (false); break; } - + do - { - switch (type) - { - long res; - unsigned long ures; - double dres; - char *scan_length; + { + switch (type) + { + long res; + unsigned long ures; + double dres; + char *scan_length; - case ECPGt_short: - case ECPGt_int: - case ECPGt_long: - if (pval) - { - res = strtol(pval, &scan_length, 10); - if ((isarray && *scan_length != ',' && *scan_length != '}') - || (!isarray && *scan_length != '\0')) /* Garbage left */ + case ECPGt_short: + case ECPGt_int: + case ECPGt_long: + if (pval) { - ECPGraise(lineno, ECPG_INT_FORMAT, pval); - return (false); - res = 0L; + res = strtol(pval, &scan_length, 10); + if ((isarray && *scan_length != ',' && *scan_length != '}') + || (!isarray && *scan_length != '\0')) /* Garbage left */ + { + ECPGraise(lineno, ECPG_INT_FORMAT, pval); + return (false); + res = 0L; + } } - } - else - res = 0L; - - switch (type) - { - case ECPGt_short: - ((short *) var)[act_tuple] = (short) res; - break; - case ECPGt_int: - ((int *) var)[act_tuple] = (int) res; - break; - case ECPGt_long: - ((long *) var)[act_tuple] = res; - break; - default: - /* Cannot happen */ - break; - } - break; + else + res = 0L; - case ECPGt_unsigned_short: - case ECPGt_unsigned_int: - case ECPGt_unsigned_long: - if (pval) - { - ures = strtoul(pval, &scan_length, 10); - if ((isarray && *scan_length != ',' && *scan_length != '}') - || (!isarray && *scan_length != '\0')) /* Garbage left */ + switch (type) { - ECPGraise(lineno, ECPG_UINT_FORMAT, pval); - return (false); - ures = 0L; + case ECPGt_short: + ((short *) var)[act_tuple] = (short) res; + break; + case ECPGt_int: + ((int *) var)[act_tuple] = (int) res; + break; + case ECPGt_long: + ((long *) var)[act_tuple] = res; + break; + default: + /* Cannot happen */ + break; } - } - else - ures = 0L; - - switch (type) - { - case ECPGt_unsigned_short: - ((unsigned short *) var)[act_tuple] = (unsigned short) ures; - break; - case ECPGt_unsigned_int: - ((unsigned int *) var)[act_tuple] = (unsigned int) ures; - break; - case ECPGt_unsigned_long: - ((unsigned long *) var)[act_tuple] = ures; - break; - default: - /* Cannot happen */ - break; - } - break; + break; + case ECPGt_unsigned_short: + case ECPGt_unsigned_int: + case ECPGt_unsigned_long: + if (pval) + { + ures = strtoul(pval, &scan_length, 10); + if ((isarray && *scan_length != ',' && *scan_length != '}') + || (!isarray && *scan_length != '\0')) /* Garbage left */ + { + ECPGraise(lineno, ECPG_UINT_FORMAT, pval); + return (false); + ures = 0L; + } + } + else + ures = 0L; - case ECPGt_float: - case ECPGt_double: - if (pval) - { - dres = strtod(pval, &scan_length); - if ((isarray && *scan_length != ',' && *scan_length != '}') - || (!isarray && *scan_length != '\0')) /* Garbage left */ + switch (type) { - ECPGraise(lineno, ECPG_FLOAT_FORMAT, pval); - return (false); - dres = 0.0; + case ECPGt_unsigned_short: + ((unsigned short *) var)[act_tuple] = (unsigned short) ures; + break; + case ECPGt_unsigned_int: + ((unsigned int *) var)[act_tuple] = (unsigned int) ures; + break; + case ECPGt_unsigned_long: + ((unsigned long *) var)[act_tuple] = ures; + break; + default: + /* Cannot happen */ + break; } - } - else - dres = 0.0; + break; - switch (type) - { - case ECPGt_float: - ((float *) var)[act_tuple] = dres; - break; - case ECPGt_double: - ((double *) var)[act_tuple] = dres; - break; - default: - /* Cannot happen */ - break; - } - break; - case ECPGt_bool: - if (pval) - { - if (pval[0] == 'f' && pval[1] == '\0') + case ECPGt_float: + case ECPGt_double: + if (pval) { - ((char *) var)[act_tuple] = false; - break; + dres = strtod(pval, &scan_length); + if ((isarray && *scan_length != ',' && *scan_length != '}') + || (!isarray && *scan_length != '\0')) /* Garbage left */ + { + ECPGraise(lineno, ECPG_FLOAT_FORMAT, pval); + return (false); + dres = 0.0; + } } - else if (pval[0] == 't' && pval[1] == '\0') + else + dres = 0.0; + + switch (type) { - ((char *) var)[act_tuple] = true; - break; + case ECPGt_float: + ((float *) var)[act_tuple] = dres; + break; + case ECPGt_double: + ((double *) var)[act_tuple] = dres; + break; + default: + /* Cannot happen */ + break; } - else if (pval[0] == '\0' && PQgetisnull(results, act_tuple, act_field)) + break; + + case ECPGt_bool: + if (pval) { - /* NULL is valid */ - break; + if (pval[0] == 'f' && pval[1] == '\0') + { + ((char *) var)[act_tuple] = false; + break; + } + else if (pval[0] == 't' && pval[1] == '\0') + { + ((char *) var)[act_tuple] = true; + break; + } + else if (pval[0] == '\0' && PQgetisnull(results, act_tuple, act_field)) + { + /* NULL is valid */ + break; + } } - } - ECPGraise(lineno, ECPG_CONVERT_BOOL, pval); - return (false); - break; + ECPGraise(lineno, ECPG_CONVERT_BOOL, pval); + return (false); + break; - case ECPGt_char: - case ECPGt_unsigned_char: - { - strncpy((char *) ((long) var + offset * act_tuple), pval, varcharsize); - if (varcharsize && varcharsize < strlen(pval)) + case ECPGt_char: + case ECPGt_unsigned_char: { - /* truncation */ - switch (ind_type) + strncpy((char *) ((long) var + offset * act_tuple), pval, varcharsize); + if (varcharsize && varcharsize < strlen(pval)) { - case ECPGt_short: - case ECPGt_unsigned_short: - ((short *) ind)[act_tuple] = varcharsize; - break; - case ECPGt_int: - case ECPGt_unsigned_int: - ((int *) ind)[act_tuple] = varcharsize; - break; - case ECPGt_long: - case ECPGt_unsigned_long: - ((long *) ind)[act_tuple] = varcharsize; - break; - default: - break; + /* truncation */ + switch (ind_type) + { + case ECPGt_short: + case ECPGt_unsigned_short: + ((short *) ind)[act_tuple] = varcharsize; + break; + case ECPGt_int: + case ECPGt_unsigned_int: + ((int *) ind)[act_tuple] = varcharsize; + break; + case ECPGt_long: + case ECPGt_unsigned_long: + ((long *) ind)[act_tuple] = varcharsize; + break; + default: + break; + } + sqlca.sqlwarn[0] = sqlca.sqlwarn[1] = 'W'; } - sqlca.sqlwarn[0] = sqlca.sqlwarn[1] = 'W'; } - } - break; + break; - case ECPGt_varchar: - { - struct ECPGgeneric_varchar *variable = - (struct ECPGgeneric_varchar *) ((long) var + offset * act_tuple); + case ECPGt_varchar: + { + struct ECPGgeneric_varchar *variable = + (struct ECPGgeneric_varchar *) ((long) var + offset * act_tuple); - if (varcharsize == 0) - strncpy(variable->arr, pval, strlen(pval)); - else - strncpy(variable->arr, pval, varcharsize); + if (varcharsize == 0) + strncpy(variable->arr, pval, strlen(pval)); + else + strncpy(variable->arr, pval, varcharsize); - variable->len = strlen(pval); - if (varcharsize > 0 && variable->len > varcharsize) - { - /* truncation */ - switch (ind_type) + variable->len = strlen(pval); + if (varcharsize > 0 && variable->len > varcharsize) { - case ECPGt_short: - case ECPGt_unsigned_short: - ((short *) ind)[act_tuple] = varcharsize; - break; - case ECPGt_int: - case ECPGt_unsigned_int: - ((int *) ind)[act_tuple] = varcharsize; - break; - case ECPGt_long: - case ECPGt_unsigned_long: - ((long *) ind)[act_tuple] = varcharsize; - break; - default: - break; - } - sqlca.sqlwarn[0] = sqlca.sqlwarn[1] = 'W'; + /* truncation */ + switch (ind_type) + { + case ECPGt_short: + case ECPGt_unsigned_short: + ((short *) ind)[act_tuple] = varcharsize; + break; + case ECPGt_int: + case ECPGt_unsigned_int: + ((int *) ind)[act_tuple] = varcharsize; + break; + case ECPGt_long: + case ECPGt_unsigned_long: + ((long *) ind)[act_tuple] = varcharsize; + break; + default: + break; + } + sqlca.sqlwarn[0] = sqlca.sqlwarn[1] = 'W'; - variable->len = varcharsize; + variable->len = varcharsize; + } } - } - break; + break; - default: - ECPGraise(lineno, ECPG_UNSUPPORTED, ECPGtype_name(type)); - return (false); - break; - } - if (isarray) - { - bool string = false; - - /* set array to next entry */ - ++act_tuple; - - /* set pval to the next entry */ - for (; string || (*pval != ',' && *pval != '}'); ++pval) - if (*pval == '"') - string = string ? false : true; - - if (*pval == ',') - ++pval; - } + default: + ECPGraise(lineno, ECPG_UNSUPPORTED, ECPGtype_name(type)); + return (false); + break; + } + if (isarray) + { + bool string = false; + + /* set array to next entry */ + ++act_tuple; + + /* set pval to the next entry */ + for (; string || (*pval != ',' && *pval != '}'); ++pval) + if (*pval == '"') + string = string ? false : true; + + if (*pval == ',') + ++pval; + } } while (isarray && *pval != '}'); return (true); diff --git a/src/interfaces/ecpg/lib/descriptor.c b/src/interfaces/ecpg/lib/descriptor.c index b1fe2b79d04..c79baf799ac 100644 --- a/src/interfaces/ecpg/lib/descriptor.c +++ b/src/interfaces/ecpg/lib/descriptor.c @@ -6,265 +6,270 @@ struct descriptor { - char *name; - PGresult *result; - struct descriptor *next; -} *all_descriptors = NULL; - + char *name; + PGresult *result; + struct descriptor *next; +} *all_descriptors = NULL; + static PGresult -*ECPGresultByDescriptor(int line,const char *name) + * +ECPGresultByDescriptor(int line, const char *name) { struct descriptor *i; - + for (i = all_descriptors; i != NULL; i = i->next) { - if (!strcmp(name, i->name)) return i->result; + if (!strcmp(name, i->name)) + return i->result; } - + ECPGraise(line, ECPG_UNKNOWN_DESCRIPTOR, name); - + return NULL; -} +} static unsigned int ECPGDynamicType_DDT(Oid type) { - switch(type) - { - case 1082: return SQL3_DDT_DATE; /* date */ - case 1083: return SQL3_DDT_TIME; /* time */ - case 1184: return SQL3_DDT_TIMESTAMP_WITH_TIME_ZONE; /* datetime */ - case 1296: return SQL3_DDT_TIMESTAMP_WITH_TIME_ZONE; /* timestamp */ + switch (type) + { + case 1082:return SQL3_DDT_DATE; /* date */ + case 1083: + return SQL3_DDT_TIME; /* time */ + case 1184: + return SQL3_DDT_TIMESTAMP_WITH_TIME_ZONE; /* datetime */ + case 1296: + return SQL3_DDT_TIMESTAMP_WITH_TIME_ZONE; /* timestamp */ default: return SQL3_DDT_ILLEGAL; } } bool -ECPGget_desc_header(int lineno, char * desc_name, int *count) +ECPGget_desc_header(int lineno, char *desc_name, int *count) { - PGresult *ECPGresult = ECPGresultByDescriptor(lineno, desc_name); - + PGresult *ECPGresult = ECPGresultByDescriptor(lineno, desc_name); + if (!ECPGresult) return false; *count = PQnfields(ECPGresult); ECPGlog("ECPGget_desc_header: found %d attributes.\n", *count); return true; -} +} static bool get_int_item(int lineno, void *var, enum ECPGdtype vartype, int value) { switch (vartype) - { - case ECPGt_short: - *(short *)var = value; - break; + { + case ECPGt_short: + *(short *) var = value; + break; case ECPGt_int: - *(int *)var = value; - break; - case ECPGt_long: - *(long *)var = value; - break; - case ECPGt_unsigned_short: - *(unsigned short *)var = value; - break; + *(int *) var = value; + break; + case ECPGt_long: + *(long *) var = value; + break; + case ECPGt_unsigned_short: + *(unsigned short *) var = value; + break; case ECPGt_unsigned_int: - *(unsigned int *)var = value; - break; - case ECPGt_unsigned_long: - *(unsigned long *)var = value; - break; - case ECPGt_float: - *(float *)var = value; - break; - case ECPGt_double: - *(double *)var = value; - break; - default: - ECPGraise(lineno, ECPG_VAR_NOT_NUMERIC, NULL); - return (false); + *(unsigned int *) var = value; + break; + case ECPGt_unsigned_long: + *(unsigned long *) var = value; + break; + case ECPGt_float: + *(float *) var = value; + break; + case ECPGt_double: + *(double *) var = value; + break; + default: + ECPGraise(lineno, ECPG_VAR_NOT_NUMERIC, NULL); + return (false); } - - return(true); + + return (true); } static bool get_char_item(int lineno, void *var, enum ECPGdtype vartype, char *value, int varcharsize) { switch (vartype) - { - case ECPGt_char: - case ECPGt_unsigned_char: - strncpy((char *) var, value, varcharsize); - break; - case ECPGt_varchar: - { - struct ECPGgeneric_varchar *variable = - (struct ECPGgeneric_varchar *) var; - - if (varcharsize == 0) + { + case ECPGt_char: + case ECPGt_unsigned_char: + strncpy((char *) var, value, varcharsize); + break; + case ECPGt_varchar: + { + struct ECPGgeneric_varchar *variable = + (struct ECPGgeneric_varchar *) var; + + if (varcharsize == 0) strncpy(variable->arr, value, strlen(value)); - else - strncpy(variable->arr, value, varcharsize); - - variable->len = strlen(value); - if (varcharsize > 0 && variable->len > varcharsize) - variable->len = varcharsize; - } - break; - default: - ECPGraise(lineno, ECPG_VAR_NOT_CHAR, NULL); - return (false); + else + strncpy(variable->arr, value, varcharsize); + + variable->len = strlen(value); + if (varcharsize > 0 && variable->len > varcharsize) + variable->len = varcharsize; + } + break; + default: + ECPGraise(lineno, ECPG_VAR_NOT_CHAR, NULL); + return (false); } - - return(true); + + return (true); } bool -ECPGget_desc(int lineno, char *desc_name, int index, ...) +ECPGget_desc(int lineno, char *desc_name, int index,...) { - va_list args; - PGresult *ECPGresult = ECPGresultByDescriptor(lineno, desc_name); - enum ECPGdtype type; + va_list args; + PGresult *ECPGresult = ECPGresultByDescriptor(lineno, desc_name); + enum ECPGdtype type; bool DataButNoIndicator = false; - + va_start(args, index); - if (!ECPGresult) - return (false); - - if (PQntuples(ECPGresult) < 1) - { - ECPGraise(lineno, ECPG_NOT_FOUND, NULL); - return (false); - } - - if (index < 1 || index >PQnfields(ECPGresult)) - { - ECPGraise(lineno, ECPG_INVALID_DESCRIPTOR_INDEX, NULL); - return (false); - } + if (!ECPGresult) + return (false); + + if (PQntuples(ECPGresult) < 1) + { + ECPGraise(lineno, ECPG_NOT_FOUND, NULL); + return (false); + } + + if (index < 1 || index > PQnfields(ECPGresult)) + { + ECPGraise(lineno, ECPG_INVALID_DESCRIPTOR_INDEX, NULL); + return (false); + } ECPGlog("ECPGget_desc: reading items for tuple %d\n", index); - --index; - - type = va_arg(args, enum ECPGdtype); - - while (type != ECPGd_EODT) - { - char type_str[20]; - long varcharsize; - long offset; - long arrsize; - enum ECPGttype vartype; - void *var; - - vartype = va_arg(args, enum ECPGttype); - var = va_arg(args, void *); - varcharsize = va_arg(args, long); - arrsize = va_arg(args, long); + --index; + + type = va_arg(args, enum ECPGdtype); + + while (type != ECPGd_EODT) + { + char type_str[20]; + long varcharsize; + long offset; + long arrsize; + enum ECPGttype vartype; + void *var; + + vartype = va_arg(args, enum ECPGttype); + var = va_arg(args, void *); + varcharsize = va_arg(args, long); + arrsize = va_arg(args, long); offset = va_arg(args, long); - - switch (type) - { - case (ECPGd_indicator): - if (!get_int_item(lineno, var, vartype, -PQgetisnull(ECPGresult, 0, index))) - return (false); - - ECPGlog("ECPGget_desc: INDICATOR = %d\n", -PQgetisnull(ECPGresult, 0, index)); - break; - - case ECPGd_name: - if (!get_char_item(lineno, var, vartype, PQfname(ECPGresult, index), varcharsize)) - return(false); - - ECPGlog("ECPGget_desc: NAME = %s\n", PQfname(ECPGresult, index)); - break; - - case ECPGd_nullable: - if (!get_int_item(lineno, var, vartype, 1)) - return (false); - - break; - - case ECPGd_key_member: - if (!get_int_item(lineno, var, vartype, 0)) - return (false); - - break; - - case ECPGd_scale: - if (!get_int_item(lineno, var, vartype, (PQfmod(ECPGresult, index) - VARHDRSZ) & 0xffff)) - return (false); - - ECPGlog("ECPGget_desc: SCALE = %d\n", (PQfmod(ECPGresult, index) - VARHDRSZ) & 0xffff); - break; - - case ECPGd_precision: - if (!get_int_item(lineno, var, vartype, PQfmod(ECPGresult, index) >> 16)) - return (false); - - ECPGlog("ECPGget_desc: PRECISION = %d\n", PQfmod(ECPGresult, index) >> 16); - break; - - case ECPGd_ret_length: + + switch (type) + { + case (ECPGd_indicator): + if (!get_int_item(lineno, var, vartype, -PQgetisnull(ECPGresult, 0, index))) + return (false); + + ECPGlog("ECPGget_desc: INDICATOR = %d\n", -PQgetisnull(ECPGresult, 0, index)); + break; + + case ECPGd_name: + if (!get_char_item(lineno, var, vartype, PQfname(ECPGresult, index), varcharsize)) + return (false); + + ECPGlog("ECPGget_desc: NAME = %s\n", PQfname(ECPGresult, index)); + break; + + case ECPGd_nullable: + if (!get_int_item(lineno, var, vartype, 1)) + return (false); + + break; + + case ECPGd_key_member: + if (!get_int_item(lineno, var, vartype, 0)) + return (false); + + break; + + case ECPGd_scale: + if (!get_int_item(lineno, var, vartype, (PQfmod(ECPGresult, index) - VARHDRSZ) & 0xffff)) + return (false); + + ECPGlog("ECPGget_desc: SCALE = %d\n", (PQfmod(ECPGresult, index) - VARHDRSZ) & 0xffff); + break; + + case ECPGd_precision: + if (!get_int_item(lineno, var, vartype, PQfmod(ECPGresult, index) >> 16)) + return (false); + + ECPGlog("ECPGget_desc: PRECISION = %d\n", PQfmod(ECPGresult, index) >> 16); + break; + + case ECPGd_ret_length: case ECPGd_ret_octet: if (!get_int_item(lineno, var, vartype, PQgetlength(ECPGresult, 0, index))) - return (false); - - ECPGlog("ECPGget_desc: RETURNED = %d\n", PQgetlength(ECPGresult, 0, index)); - break; - + return (false); + + ECPGlog("ECPGget_desc: RETURNED = %d\n", PQgetlength(ECPGresult, 0, index)); + break; + case ECPGd_octet: if (!get_int_item(lineno, var, vartype, PQfsize(ECPGresult, index))) - return (false); - - ECPGlog("ECPGget_desc: OCTET_LENGTH = %d\n", PQfsize(ECPGresult, index)); - break; + return (false); + + ECPGlog("ECPGget_desc: OCTET_LENGTH = %d\n", PQfsize(ECPGresult, index)); + break; case ECPGd_length: if (!get_int_item(lineno, var, vartype, PQfmod(ECPGresult, index) - VARHDRSZ)) - return (false); - - ECPGlog("ECPGget_desc: LENGTH = %d\n", PQfmod(ECPGresult, index) - VARHDRSZ); + return (false); + + ECPGlog("ECPGget_desc: LENGTH = %d\n", PQfmod(ECPGresult, index) - VARHDRSZ); + break; + + case ECPGd_type: + if (!get_int_item(lineno, var, vartype, ECPGDynamicType(PQftype(ECPGresult, index)))) + return (false); + + ECPGlog("ECPGget_desc: TYPE = %d\n", ECPGDynamicType(PQftype(ECPGresult, index))); + break; + + case ECPGd_di_code: + if (!get_int_item(lineno, var, vartype, ECPGDynamicType_DDT(PQftype(ECPGresult, index)))) + return (false); + + ECPGlog("ECPGget_desc: TYPE = %d\n", ECPGDynamicType_DDT(PQftype(ECPGresult, index))); break; - - case ECPGd_type: - if (!get_int_item(lineno, var, vartype, ECPGDynamicType(PQftype(ECPGresult, index)))) - return (false); - - ECPGlog("ECPGget_desc: TYPE = %d\n", ECPGDynamicType(PQftype(ECPGresult, index))); - break; - - case ECPGd_di_code: - if (!get_int_item(lineno, var, vartype, ECPGDynamicType_DDT(PQftype(ECPGresult, index)))) - return (false); - - ECPGlog("ECPGget_desc: TYPE = %d\n", ECPGDynamicType_DDT(PQftype(ECPGresult, index))); - break; case ECPGd_data: if (!get_data(ECPGresult, 0, index, lineno, vartype, ECPGt_NO_INDICATOR, var, NULL, varcharsize, offset, false)) - return (false); - + return (false); + break; - - default: - snprintf(type_str, sizeof(type_str), "%d", type); - ECPGraise(lineno, ECPG_UNKNOWN_DESCRIPTOR_ITEM, type_str); - return(false); + + default: + snprintf(type_str, sizeof(type_str), "%d", type); + ECPGraise(lineno, ECPG_UNKNOWN_DESCRIPTOR_ITEM, type_str); + return (false); } - - type = va_arg(args, enum ECPGdtype); + + type = va_arg(args, enum ECPGdtype); + } + + if (DataButNoIndicator && PQgetisnull(ECPGresult, 0, index)) + { + ECPGraise(lineno, ECPG_MISSING_INDICATOR, NULL); + return (false); } - - if (DataButNoIndicator && PQgetisnull(ECPGresult, 0, index)) - { - ECPGraise(lineno, ECPG_MISSING_INDICATOR, NULL); - return (false); - } - - return (true); + + return (true); } bool @@ -272,7 +277,7 @@ ECPGdeallocate_desc(int line, const char *name) { struct descriptor *i; struct descriptor **lastptr = &all_descriptors; - + for (i = all_descriptors; i; lastptr = &i->next, i = i->next) { if (!strcmp(name, i->name)) @@ -286,15 +291,15 @@ ECPGdeallocate_desc(int line, const char *name) } ECPGraise(line, ECPG_UNKNOWN_DESCRIPTOR, name); return false; -} +} bool -ECPGallocate_desc(int line,const char *name) +ECPGallocate_desc(int line, const char *name) { - struct descriptor *new = (struct descriptor *)malloc(sizeof(struct descriptor)); - + struct descriptor *new = (struct descriptor *) malloc(sizeof(struct descriptor)); + new->next = all_descriptors; - new->name = malloc(strlen(name)+1); + new->name = malloc(strlen(name) + 1); new->result = PQmakeEmptyPGresult(NULL, 0); strcpy(new->name, name); all_descriptors = new; diff --git a/src/interfaces/ecpg/lib/error.c b/src/interfaces/ecpg/lib/error.c index e7e976116b8..e2da331757a 100644 --- a/src/interfaces/ecpg/lib/error.c +++ b/src/interfaces/ecpg/lib/error.c @@ -10,143 +10,143 @@ void ECPGraise(int line, int code, char *str) { sqlca.sqlcode = code; - + switch (code) - { - case ECPG_NOT_FOUND: - snprintf(sqlca.sqlerrm.sqlerrmc,sizeof(sqlca.sqlerrm.sqlerrmc), - "No data found in line %d.", line); - break; - - case ECPG_OUT_OF_MEMORY: - snprintf(sqlca.sqlerrm.sqlerrmc,sizeof(sqlca.sqlerrm.sqlerrmc), - "Out of memory in line %d.", line); - break; - - case ECPG_UNSUPPORTED: - snprintf(sqlca.sqlerrm.sqlerrmc,sizeof(sqlca.sqlerrm.sqlerrmc), - "Unsupported type %s in line %d.", str, line); - break; - - case ECPG_TOO_MANY_ARGUMENTS: - snprintf(sqlca.sqlerrm.sqlerrmc,sizeof(sqlca.sqlerrm.sqlerrmc), - "Too many arguments in line %d.", line); - break; - - case ECPG_TOO_FEW_ARGUMENTS: - snprintf(sqlca.sqlerrm.sqlerrmc,sizeof(sqlca.sqlerrm.sqlerrmc), - "Too few arguments in line %d.", line); - break; - - case ECPG_INT_FORMAT: - snprintf(sqlca.sqlerrm.sqlerrmc,sizeof(sqlca.sqlerrm.sqlerrmc), - "Not correctly formatted int type: %s line %d.", str, line); - break; - - case ECPG_UINT_FORMAT: - snprintf(sqlca.sqlerrm.sqlerrmc,sizeof(sqlca.sqlerrm.sqlerrmc), - "Not correctly formatted unsigned type: %s in line %d.", str, line); - break; - - case ECPG_FLOAT_FORMAT: - snprintf(sqlca.sqlerrm.sqlerrmc,sizeof(sqlca.sqlerrm.sqlerrmc), - "Not correctly formatted floating point type: %s in line %d.", str, line); - break; - - case ECPG_CONVERT_BOOL: - snprintf(sqlca.sqlerrm.sqlerrmc,sizeof(sqlca.sqlerrm.sqlerrmc), - "Unable to convert %s to bool on line %d.", str, line); - break; - - case ECPG_EMPTY: - snprintf(sqlca.sqlerrm.sqlerrmc,sizeof(sqlca.sqlerrm.sqlerrmc), - "Empty query in line %d.", line); - break; - - case ECPG_MISSING_INDICATOR: - snprintf(sqlca.sqlerrm.sqlerrmc,sizeof(sqlca.sqlerrm.sqlerrmc), - "NULL value without indicator in line %d.", line); - break; - - case ECPG_NO_ARRAY: - snprintf(sqlca.sqlerrm.sqlerrmc,sizeof(sqlca.sqlerrm.sqlerrmc), - "variable is not an array in line %d.", line); - break; - - case ECPG_DATA_NOT_ARRAY: - snprintf(sqlca.sqlerrm.sqlerrmc,sizeof(sqlca.sqlerrm.sqlerrmc), - "data read from backend is not an array in line %d.", line); - break; - - case ECPG_NO_CONN: - snprintf(sqlca.sqlerrm.sqlerrmc,sizeof(sqlca.sqlerrm.sqlerrmc), - "No such connection %s in line %d.", str, line); - break; - - case ECPG_NOT_CONN: - snprintf(sqlca.sqlerrm.sqlerrmc,sizeof(sqlca.sqlerrm.sqlerrmc), - "Not connected in line %d.", line); - break; - - case ECPG_INVALID_STMT: - snprintf(sqlca.sqlerrm.sqlerrmc,sizeof(sqlca.sqlerrm.sqlerrmc), - "Invalid statement name in line %d.", line); - break; - - case ECPG_UNKNOWN_DESCRIPTOR: - snprintf(sqlca.sqlerrm.sqlerrmc,sizeof(sqlca.sqlerrm.sqlerrmc), - "Sescriptor %s not found in line %d.", str, line); - break; - - case ECPG_INVALID_DESCRIPTOR_INDEX: - snprintf(sqlca.sqlerrm.sqlerrmc,sizeof(sqlca.sqlerrm.sqlerrmc), - "Sescriptor index out of range in line %d.", line); - break; - - case ECPG_UNKNOWN_DESCRIPTOR_ITEM: - snprintf(sqlca.sqlerrm.sqlerrmc,sizeof(sqlca.sqlerrm.sqlerrmc), - "Unknown descriptor item %s in line %d.", str, line); - break; - - case ECPG_VAR_NOT_NUMERIC: - snprintf(sqlca.sqlerrm.sqlerrmc,sizeof(sqlca.sqlerrm.sqlerrmc), - "Variable is not a numeric type in line %d.", line); - break; - - case ECPG_VAR_NOT_CHAR: - snprintf(sqlca.sqlerrm.sqlerrmc,sizeof(sqlca.sqlerrm.sqlerrmc), - "Variable is not a character type in line %d.", line); + { + case ECPG_NOT_FOUND: + snprintf(sqlca.sqlerrm.sqlerrmc, sizeof(sqlca.sqlerrm.sqlerrmc), + "No data found in line %d.", line); + break; + + case ECPG_OUT_OF_MEMORY: + snprintf(sqlca.sqlerrm.sqlerrmc, sizeof(sqlca.sqlerrm.sqlerrmc), + "Out of memory in line %d.", line); + break; + + case ECPG_UNSUPPORTED: + snprintf(sqlca.sqlerrm.sqlerrmc, sizeof(sqlca.sqlerrm.sqlerrmc), + "Unsupported type %s in line %d.", str, line); + break; + + case ECPG_TOO_MANY_ARGUMENTS: + snprintf(sqlca.sqlerrm.sqlerrmc, sizeof(sqlca.sqlerrm.sqlerrmc), + "Too many arguments in line %d.", line); + break; + + case ECPG_TOO_FEW_ARGUMENTS: + snprintf(sqlca.sqlerrm.sqlerrmc, sizeof(sqlca.sqlerrm.sqlerrmc), + "Too few arguments in line %d.", line); + break; + + case ECPG_INT_FORMAT: + snprintf(sqlca.sqlerrm.sqlerrmc, sizeof(sqlca.sqlerrm.sqlerrmc), + "Not correctly formatted int type: %s line %d.", str, line); + break; + + case ECPG_UINT_FORMAT: + snprintf(sqlca.sqlerrm.sqlerrmc, sizeof(sqlca.sqlerrm.sqlerrmc), + "Not correctly formatted unsigned type: %s in line %d.", str, line); + break; + + case ECPG_FLOAT_FORMAT: + snprintf(sqlca.sqlerrm.sqlerrmc, sizeof(sqlca.sqlerrm.sqlerrmc), + "Not correctly formatted floating point type: %s in line %d.", str, line); + break; + + case ECPG_CONVERT_BOOL: + snprintf(sqlca.sqlerrm.sqlerrmc, sizeof(sqlca.sqlerrm.sqlerrmc), + "Unable to convert %s to bool on line %d.", str, line); + break; + + case ECPG_EMPTY: + snprintf(sqlca.sqlerrm.sqlerrmc, sizeof(sqlca.sqlerrm.sqlerrmc), + "Empty query in line %d.", line); + break; + + case ECPG_MISSING_INDICATOR: + snprintf(sqlca.sqlerrm.sqlerrmc, sizeof(sqlca.sqlerrm.sqlerrmc), + "NULL value without indicator in line %d.", line); + break; + + case ECPG_NO_ARRAY: + snprintf(sqlca.sqlerrm.sqlerrmc, sizeof(sqlca.sqlerrm.sqlerrmc), + "variable is not an array in line %d.", line); + break; + + case ECPG_DATA_NOT_ARRAY: + snprintf(sqlca.sqlerrm.sqlerrmc, sizeof(sqlca.sqlerrm.sqlerrmc), + "data read from backend is not an array in line %d.", line); break; - + + case ECPG_NO_CONN: + snprintf(sqlca.sqlerrm.sqlerrmc, sizeof(sqlca.sqlerrm.sqlerrmc), + "No such connection %s in line %d.", str, line); + break; + + case ECPG_NOT_CONN: + snprintf(sqlca.sqlerrm.sqlerrmc, sizeof(sqlca.sqlerrm.sqlerrmc), + "Not connected in line %d.", line); + break; + + case ECPG_INVALID_STMT: + snprintf(sqlca.sqlerrm.sqlerrmc, sizeof(sqlca.sqlerrm.sqlerrmc), + "Invalid statement name in line %d.", line); + break; + + case ECPG_UNKNOWN_DESCRIPTOR: + snprintf(sqlca.sqlerrm.sqlerrmc, sizeof(sqlca.sqlerrm.sqlerrmc), + "Sescriptor %s not found in line %d.", str, line); + break; + + case ECPG_INVALID_DESCRIPTOR_INDEX: + snprintf(sqlca.sqlerrm.sqlerrmc, sizeof(sqlca.sqlerrm.sqlerrmc), + "Sescriptor index out of range in line %d.", line); + break; + + case ECPG_UNKNOWN_DESCRIPTOR_ITEM: + snprintf(sqlca.sqlerrm.sqlerrmc, sizeof(sqlca.sqlerrm.sqlerrmc), + "Unknown descriptor item %s in line %d.", str, line); + break; + + case ECPG_VAR_NOT_NUMERIC: + snprintf(sqlca.sqlerrm.sqlerrmc, sizeof(sqlca.sqlerrm.sqlerrmc), + "Variable is not a numeric type in line %d.", line); + break; + + case ECPG_VAR_NOT_CHAR: + snprintf(sqlca.sqlerrm.sqlerrmc, sizeof(sqlca.sqlerrm.sqlerrmc), + "Variable is not a character type in line %d.", line); + break; + case ECPG_PGSQL: /* strip trailing newline */ - if (str[strlen(str)-1] == '\n') - str[strlen(str)-1] = '\0'; - - snprintf(sqlca.sqlerrm.sqlerrmc,sizeof(sqlca.sqlerrm.sqlerrmc), - "'%s' in line %d.", str, line); - break; - - case ECPG_TRANS: - snprintf(sqlca.sqlerrm.sqlerrmc,sizeof(sqlca.sqlerrm.sqlerrmc), - "Error in transaction processing in line %d.", line); - break; - - case ECPG_CONNECT: - snprintf(sqlca.sqlerrm.sqlerrmc,sizeof(sqlca.sqlerrm.sqlerrmc), - "Could not connect to database %s in line %d.", str, line); - break; - + if (str[strlen(str) - 1] == '\n') + str[strlen(str) - 1] = '\0'; + + snprintf(sqlca.sqlerrm.sqlerrmc, sizeof(sqlca.sqlerrm.sqlerrmc), + "'%s' in line %d.", str, line); + break; + + case ECPG_TRANS: + snprintf(sqlca.sqlerrm.sqlerrmc, sizeof(sqlca.sqlerrm.sqlerrmc), + "Error in transaction processing in line %d.", line); + break; + + case ECPG_CONNECT: + snprintf(sqlca.sqlerrm.sqlerrmc, sizeof(sqlca.sqlerrm.sqlerrmc), + "Could not connect to database %s in line %d.", str, line); + break; + default: - snprintf(sqlca.sqlerrm.sqlerrmc,sizeof(sqlca.sqlerrm.sqlerrmc), - "SQL error #%d in line %d.", code, line); + snprintf(sqlca.sqlerrm.sqlerrmc, sizeof(sqlca.sqlerrm.sqlerrmc), + "SQL error #%d in line %d.", code, line); break; } - + sqlca.sqlerrm.sqlerrml = strlen(sqlca.sqlerrm.sqlerrmc); - /* free all memory we have allocated for the user */ - free_auto_mem(); + /* free all memory we have allocated for the user */ + free_auto_mem(); } /* print out an error message */ diff --git a/src/interfaces/ecpg/lib/execute.c b/src/interfaces/ecpg/lib/execute.c index f8910aa7e8f..43b7a603876 100644 --- a/src/interfaces/ecpg/lib/execute.c +++ b/src/interfaces/ecpg/lib/execute.c @@ -54,9 +54,9 @@ struct variable /* keep a list of memory we allocated for the user */ static struct auto_mem { - void *pointer; - struct auto_mem *next; -} *auto_allocs = NULL; + void *pointer; + struct auto_mem *next; +} *auto_allocs = NULL; static void add_mem(void *ptr, int lineno) @@ -67,20 +67,21 @@ add_mem(void *ptr, int lineno) auto_allocs = am; } -void free_auto_mem(void) +void +free_auto_mem(void) { struct auto_mem *am; - - /* free all memory we have allocated for the user */ - for (am = auto_allocs; am;) - { - struct auto_mem *act = am; - - am = am->next; - free(act->pointer); - free(act); + + /* free all memory we have allocated for the user */ + for (am = auto_allocs; am;) + { + struct auto_mem *act = am; + + am = am->next; + free(act->pointer); + free(act); } - + auto_allocs = NULL; } @@ -245,7 +246,7 @@ next_insert(char *text) bool string = false; for (; *ptr != '\0' && (*ptr != '?' || string); ptr++) - if (*ptr == '\'' && *(ptr-1) != '\\') + if (*ptr == '\'' && *(ptr - 1) != '\\') string = string ? false : true; return (*ptr == '\0') ? NULL : ptr; @@ -256,7 +257,8 @@ ECPGexecute(struct statement * stmt) { bool status = false; char *copiedquery; - PGresult *results, *query; + PGresult *results, + *query; PGnotify *notify; struct variable *var; @@ -275,7 +277,7 @@ ECPGexecute(struct statement * stmt) char *mallocedval = NULL; char *tobeinserted = NULL; char *p; - char buff[20]; + char buff[20]; /* * Some special treatment is needed for records since we want @@ -311,20 +313,20 @@ ECPGexecute(struct statement * stmt) { switch (var->type) { - int element; - + int element; + case ECPGt_short: if (!(mallocedval = ecpg_alloc(var->arrsize * 20, stmt->lineno))) return false; if (var->arrsize > 1) { - strncpy(mallocedval, "'{", sizeof("'{")); - + strncpy(mallocedval, "'{", sizeof("'{")); + for (element = 0; element < var->arrsize; element++) sprintf(mallocedval + strlen(mallocedval), "%hd,", ((short *) var->value)[element]); - - strncpy(mallocedval + strlen(mallocedval) - 1, "}'", sizeof("}'")); + + strncpy(mallocedval + strlen(mallocedval) - 1, "}'", sizeof("}'")); } else sprintf(mallocedval, "%hd", *((short *) var->value)); @@ -338,12 +340,12 @@ ECPGexecute(struct statement * stmt) if (var->arrsize > 1) { - strncpy(mallocedval, "'{", sizeof("'{")); - + strncpy(mallocedval, "'{", sizeof("'{")); + for (element = 0; element < var->arrsize; element++) sprintf(mallocedval + strlen(mallocedval), "%d,", ((int *) var->value)[element]); - - strncpy(mallocedval + strlen(mallocedval) - 1, "}'", sizeof("}'")); + + strncpy(mallocedval + strlen(mallocedval) - 1, "}'", sizeof("}'")); } else sprintf(mallocedval, "%d", *((int *) var->value)); @@ -357,12 +359,12 @@ ECPGexecute(struct statement * stmt) if (var->arrsize > 1) { - strncpy(mallocedval, "'{", sizeof("'{")); - + strncpy(mallocedval, "'{", sizeof("'{")); + for (element = 0; element < var->arrsize; element++) sprintf(mallocedval + strlen(mallocedval), "%hu,", ((unsigned short *) var->value)[element]); - - strncpy(mallocedval + strlen(mallocedval) - 1, "}'", sizeof("}'")); + + strncpy(mallocedval + strlen(mallocedval) - 1, "}'", sizeof("}'")); } else sprintf(mallocedval, "%hu", *((unsigned short *) var->value)); @@ -376,12 +378,12 @@ ECPGexecute(struct statement * stmt) if (var->arrsize > 1) { - strncpy(mallocedval, "'{", sizeof("'{")); - + strncpy(mallocedval, "'{", sizeof("'{")); + for (element = 0; element < var->arrsize; element++) sprintf(mallocedval + strlen(mallocedval), "%u,", ((unsigned int *) var->value)[element]); - - strncpy(mallocedval + strlen(mallocedval) - 1, "}'", sizeof("}'")); + + strncpy(mallocedval + strlen(mallocedval) - 1, "}'", sizeof("}'")); } else sprintf(mallocedval, "%u", *((unsigned int *) var->value)); @@ -392,15 +394,15 @@ ECPGexecute(struct statement * stmt) case ECPGt_long: if (!(mallocedval = ecpg_alloc(var->arrsize * 20, stmt->lineno))) return false; - + if (var->arrsize > 1) { - strncpy(mallocedval, "'{", sizeof("'{")); - + strncpy(mallocedval, "'{", sizeof("'{")); + for (element = 0; element < var->arrsize; element++) sprintf(mallocedval + strlen(mallocedval), "%ld,", ((long *) var->value)[element]); - - strncpy(mallocedval + strlen(mallocedval) - 1, "}'", sizeof("}'")); + + strncpy(mallocedval + strlen(mallocedval) - 1, "}'", sizeof("}'")); } else sprintf(mallocedval, "%ld", *((long *) var->value)); @@ -414,12 +416,12 @@ ECPGexecute(struct statement * stmt) if (var->arrsize > 1) { - strncpy(mallocedval, "'{", sizeof("'{")); - + strncpy(mallocedval, "'{", sizeof("'{")); + for (element = 0; element < var->arrsize; element++) sprintf(mallocedval + strlen(mallocedval), "%lu,", ((unsigned long *) var->value)[element]); - - strncpy(mallocedval + strlen(mallocedval) - 1, "}'", sizeof("}'")); + + strncpy(mallocedval + strlen(mallocedval) - 1, "}'", sizeof("}'")); } else sprintf(mallocedval, "%lu", *((unsigned long *) var->value)); @@ -433,12 +435,12 @@ ECPGexecute(struct statement * stmt) if (var->arrsize > 1) { - strncpy(mallocedval, "'{", sizeof("'{")); - + strncpy(mallocedval, "'{", sizeof("'{")); + for (element = 0; element < var->arrsize; element++) sprintf(mallocedval + strlen(mallocedval), "%.14g,", ((float *) var->value)[element]); - - strncpy(mallocedval + strlen(mallocedval) - 1, "}'", sizeof("}'")); + + strncpy(mallocedval + strlen(mallocedval) - 1, "}'", sizeof("}'")); } else sprintf(mallocedval, "%.14g", *((float *) var->value)); @@ -452,12 +454,12 @@ ECPGexecute(struct statement * stmt) if (var->arrsize > 1) { - strncpy(mallocedval, "'{", sizeof("'{")); - + strncpy(mallocedval, "'{", sizeof("'{")); + for (element = 0; element < var->arrsize; element++) sprintf(mallocedval + strlen(mallocedval), "%.14g,", ((double *) var->value)[element]); - - strncpy(mallocedval + strlen(mallocedval) - 1, "}'", sizeof("}'")); + + strncpy(mallocedval + strlen(mallocedval) - 1, "}'", sizeof("}'")); } else sprintf(mallocedval, "%.14g", *((double *) var->value)); @@ -471,12 +473,12 @@ ECPGexecute(struct statement * stmt) if (var->arrsize > 1) { - strncpy(mallocedval, "'{", sizeof("'{")); - + strncpy(mallocedval, "'{", sizeof("'{")); + for (element = 0; element < var->arrsize; element++) sprintf(mallocedval + strlen(mallocedval), "%c,", (((char *) var->value)[element]) ? 't' : 'f'); - - strncpy(mallocedval + strlen(mallocedval) - 1, "}'", sizeof("}'")); + + strncpy(mallocedval + strlen(mallocedval) - 1, "}'", sizeof("}'")); } else sprintf(mallocedval, "'%c'", (*((char *) var->value)) ? 't' : 'f'); @@ -541,7 +543,7 @@ ECPGexecute(struct statement * stmt) default: /* Not implemented yet */ - ECPGraise(stmt->lineno, ECPG_UNSUPPORTED, (char *)ECPGtype_name(var->type)); + ECPGraise(stmt->lineno, ECPG_UNSUPPORTED, (char *) ECPGtype_name(var->type)); return false; break; } @@ -656,7 +658,7 @@ ECPGexecute(struct statement * stmt) for (act_field = 0; act_field < nfields && status; act_field++) { char *array_query; - + if (var == NULL) { ECPGlog("ECPGexecute line %d: Too few arguments.\n", stmt->lineno); @@ -664,16 +666,21 @@ ECPGexecute(struct statement * stmt) return (false); } - array_query = (char *)ecpg_alloc(strlen("select typelem from pg_type where oid=") + 11, stmt -> lineno); + array_query = (char *) ecpg_alloc(strlen("select typelem from pg_type where oid=") + 11, stmt->lineno); sprintf(array_query, "select typelem from pg_type where oid=%d", PQftype(results, act_field)); query = PQexec(stmt->connection->connection, array_query); isarray = 0; - if (PQresultStatus(query) == PGRES_TUPLES_OK) { - isarray = atol((char *)PQgetvalue(query, 0, 0)); + if (PQresultStatus(query) == PGRES_TUPLES_OK) + { + isarray = atol((char *) PQgetvalue(query, 0, 0)); if (ECPGDynamicType(PQftype(results, act_field)) == SQL3_CHARACTER || - ECPGDynamicType(PQftype(results, act_field)) == SQL3_CHARACTER_VARYING) + ECPGDynamicType(PQftype(results, act_field)) == SQL3_CHARACTER_VARYING) { - /* arrays of character strings are not yet implemented */ + + /* + * arrays of character strings are not yet + * implemented + */ isarray = false; } ECPGlog("ECPGexecute line %d: TYPE database: %d C: %d array: %s\n", stmt->lineno, PQftype(results, act_field), var->type, isarray ? "yes" : "no"); @@ -682,14 +689,15 @@ ECPGexecute(struct statement * stmt) if (!isarray) { + /* - * if we don't have enough space, we cannot read all - * tuples + * if we don't have enough space, we cannot read + * all tuples */ if ((var->arrsize > 0 && ntuples > var->arrsize) || (var->ind_arrsize > 0 && ntuples > var->ind_arrsize)) { ECPGlog("ECPGexecute line %d: Incorrect number of matches: %d don't fit into array of %d\n", - stmt->lineno, ntuples, var->arrsize); + stmt->lineno, ntuples, var->arrsize); ECPGraise(stmt->lineno, ECPG_TOO_MANY_MATCHES, NULL); status = false; break; @@ -697,6 +705,7 @@ ECPGexecute(struct statement * stmt) } else { + /* * since we read an array, the variable has to be * an array too @@ -707,9 +716,9 @@ ECPGexecute(struct statement * stmt) ECPGraise(stmt->lineno, ECPG_NO_ARRAY, NULL); status = false; break; - } + } } - + /* * allocate memory for NULL pointers */ @@ -744,13 +753,13 @@ ECPGexecute(struct statement * stmt) *((void **) var->pointer) = var->value; add_mem(var->value, stmt->lineno); } - + for (act_tuple = 0; act_tuple < ntuples && status; act_tuple++) { if (!get_data(results, act_tuple, act_field, stmt->lineno, - var->type, var->ind_type, var->value, - var->ind_value, var->varcharsize, var->offset, isarray)) - status = false; + var->type, var->ind_type, var->value, + var->ind_value, var->varcharsize, var->offset, isarray)) + status = false; } var = var->next; } @@ -811,13 +820,13 @@ ECPGexecute(struct statement * stmt) } bool -ECPGdo(int lineno, const char *connection_name, char *query, ...) +ECPGdo(int lineno, const char *connection_name, char *query,...) { - va_list args; - struct statement *stmt; - struct connection *con = get_connection(connection_name); - bool status=true; - char *locale = setlocale(LC_NUMERIC, NULL); + va_list args; + struct statement *stmt; + struct connection *con = get_connection(connection_name); + bool status = true; + char *locale = setlocale(LC_NUMERIC, NULL); /* Make sure we do NOT honor the locale for numeric input/output */ /* since the database wants teh standard decimal point */ @@ -826,7 +835,7 @@ ECPGdo(int lineno, const char *connection_name, char *query, ...) if (!ecpg_init(con, connection_name, lineno)) { setlocale(LC_NUMERIC, locale); - return(false); + return (false); } va_start(args, query); @@ -859,26 +868,27 @@ ECPGdo(int lineno, const char *connection_name, char *query, ...) * * Copyright (c) 2000, Christof Petig <christof.petig@wtal.de> * - * $Header: /cvsroot/pgsql/src/interfaces/ecpg/lib/Attic/execute.c,v 1.5 2000/04/05 15:51:25 meskes Exp $ + * $Header: /cvsroot/pgsql/src/interfaces/ecpg/lib/Attic/execute.c,v 1.6 2000/04/12 17:17:03 momjian Exp $ */ -PGconn *ECPG_internal_get_connection(char *name); +PGconn *ECPG_internal_get_connection(char *name); extern struct descriptor { - char *name; - PGresult *result; - struct descriptor *next; -} *all_descriptors; + char *name; + PGresult *result; + struct descriptor *next; +} *all_descriptors; /* like ECPGexecute */ -static bool execute_descriptor(int lineno,const char *query - ,struct connection *con,PGresult **resultptr) +static bool +execute_descriptor(int lineno, const char *query + ,struct connection * con, PGresult **resultptr) { - bool status = false; + bool status = false; PGresult *results; PGnotify *notify; - + /* Now the request is built. */ if (con->committed && !con->autocommit) @@ -902,9 +912,12 @@ static bool execute_descriptor(int lineno,const char *query ECPGraise(lineno, ECPG_PGSQL, PQerrorMessage(con->connection)); } else - { *resultptr=results; + { + *resultptr = results; switch (PQresultStatus(results)) - { int ntuples; + { + int ntuples; + case PGRES_TUPLES_OK: status = true; sqlca.sqlerrd[2] = ntuples = PQntuples(results); @@ -917,7 +930,7 @@ static bool execute_descriptor(int lineno,const char *query break; } break; -#if 1 /* strictly these are not needed (yet) */ +#if 1 /* strictly these are not needed (yet) */ case PGRES_EMPTY_QUERY: /* do nothing */ ECPGraise(lineno, ECPG_EMPTY, NULL); @@ -972,20 +985,22 @@ static bool execute_descriptor(int lineno,const char *query } /* like ECPGdo */ -static bool do_descriptor2(int lineno,const char *connection_name, - PGresult **resultptr, const char *query) +static bool +do_descriptor2(int lineno, const char *connection_name, + PGresult **resultptr, const char *query) { struct connection *con = get_connection(connection_name); - bool status=true; - char *locale = setlocale(LC_NUMERIC, NULL); + bool status = true; + char *locale = setlocale(LC_NUMERIC, NULL); /* Make sure we do NOT honor the locale for numeric input/output */ /* since the database wants teh standard decimal point */ setlocale(LC_NUMERIC, "C"); if (!ecpg_init(con, connection_name, lineno)) - { setlocale(LC_NUMERIC, locale); - return(false); + { + setlocale(LC_NUMERIC, locale); + return (false); } /* are we connected? */ @@ -997,33 +1012,38 @@ static bool do_descriptor2(int lineno,const char *connection_name, return false; } - status = execute_descriptor(lineno,query,con,resultptr); + status = execute_descriptor(lineno, query, con, resultptr); /* and reset locale value so our application is not affected */ setlocale(LC_NUMERIC, locale); return (status); } -bool ECPGdo_descriptor(int line,const char *connection, - const char *descriptor,const char *query) +bool +ECPGdo_descriptor(int line, const char *connection, + const char *descriptor, const char *query) { struct descriptor *i; - for (i=all_descriptors;i!=NULL;i=i->next) - { if (!strcmp(descriptor,i->name)) - { - bool status; + + for (i = all_descriptors; i != NULL; i = i->next) + { + if (!strcmp(descriptor, i->name)) + { + bool status; /* free previous result */ - if (i->result) PQclear(i->result); - i->result=NULL; - - status=do_descriptor2(line,connection,&i->result,query); - - if (!i->result) PQmakeEmptyPGresult(NULL, 0); + if (i->result) + PQclear(i->result); + i->result = NULL; + + status = do_descriptor2(line, connection, &i->result, query); + + if (!i->result) + PQmakeEmptyPGresult(NULL, 0); return (status); - } + } } - + ECPGraise(line, ECPG_UNKNOWN_DESCRIPTOR, (char *) descriptor); return false; } diff --git a/src/interfaces/ecpg/lib/extern.h b/src/interfaces/ecpg/lib/extern.h index ef9515d7c96..86cc8bbab87 100644 --- a/src/interfaces/ecpg/lib/extern.h +++ b/src/interfaces/ecpg/lib/extern.h @@ -3,14 +3,14 @@ /* Here are some methods used by the lib. */ /* Returns a pointer to a string containing a simple type name. */ -void free_auto_mem(void); +void free_auto_mem(void); bool get_data(PGresult *, int, int, int, enum ECPGttype type, - enum ECPGttype, void *, void *, long, long, bool); + enum ECPGttype, void *, void *, long, long, bool); struct connection *get_connection(const char *); -void init_sqlca(void); -char *ecpg_alloc(long, int); -bool ecpg_init(const struct connection *, const char *, const int); -char *ecpg_strdup(const char *, int); +void init_sqlca(void); +char *ecpg_alloc(long, int); +bool ecpg_init(const struct connection *, const char *, const int); +char *ecpg_strdup(const char *, int); const char *ECPGtype_name(enum ECPGttype); unsigned int ECPGDynamicType(Oid); @@ -24,20 +24,19 @@ struct ECPGgeneric_varchar /* structure to store one statement */ struct statement { - int lineno; - char *command; - struct connection *connection; - struct variable *inlist; - struct variable *outlist; + int lineno; + char *command; + struct connection *connection; + struct variable *inlist; + struct variable *outlist; }; /* structure to store connections */ struct connection { - char *name; - PGconn *connection; - bool committed; - int autocommit; - struct connection *next; + char *name; + PGconn *connection; + bool committed; + int autocommit; + struct connection *next; }; - diff --git a/src/interfaces/ecpg/lib/misc.c b/src/interfaces/ecpg/lib/misc.c index 55e0cfc8177..dbfb8b810de 100644 --- a/src/interfaces/ecpg/lib/misc.c +++ b/src/interfaces/ecpg/lib/misc.c @@ -27,7 +27,7 @@ init_sqlca(void) } bool -ecpg_init(const struct connection *con, const char * connection_name, const int lineno) +ecpg_init(const struct connection * con, const char *connection_name, const int lineno) { init_sqlca(); if (con == NULL) @@ -35,7 +35,7 @@ ecpg_init(const struct connection *con, const char * connection_name, const int ECPGraise(lineno, ECPG_NO_CONN, connection_name ? connection_name : "NULL"); return (false); } - + return (true); } @@ -45,7 +45,7 @@ ECPGstatus(int lineno, const char *connection_name) struct connection *con = get_connection(connection_name); if (!ecpg_init(con, connection_name, lineno)) - return(false); + return (false); /* are we connected? */ if (con->connection == NULL) @@ -65,7 +65,7 @@ ECPGtrans(int lineno, const char *connection_name, const char *transaction) struct connection *con = get_connection(connection_name); if (!ecpg_init(con, connection_name, lineno)) - return(false); + return (false); ECPGlog("ECPGtrans line %d action = %s connection = %s\n", lineno, transaction, con->name); @@ -79,14 +79,14 @@ ECPGtrans(int lineno, const char *connection_name, const char *transaction) } PQclear(res); } - + if (strcmp(transaction, "commit") == 0 || strcmp(transaction, "rollback") == 0) { con->committed = true; /* deallocate all prepared statements */ if (!ECPGdeallocate_all(lineno)) - return false; + return false; } return true; diff --git a/src/interfaces/ecpg/lib/prepare.c b/src/interfaces/ecpg/lib/prepare.c index 2155177edec..c49d44ab8d8 100644 --- a/src/interfaces/ecpg/lib/prepare.c +++ b/src/interfaces/ecpg/lib/prepare.c @@ -8,10 +8,10 @@ static struct prepared_statement { - char *name; - struct statement *stmt; - struct prepared_statement *next; -} *prep_stmts = NULL; + char *name; + struct statement *stmt; + struct prepared_statement *next; +} *prep_stmts = NULL; static bool isvarchar(unsigned char c) @@ -47,7 +47,7 @@ replace_variables(char *text) } } } - + /* handle the EXEC SQL PREPARE statement */ bool ECPGprepare(int lineno, char *name, char *variable) @@ -117,7 +117,7 @@ ECPGdeallocate(int lineno, char *name) prev->next = this->next; else prep_stmts = this->next; - + free(this); return true; } @@ -130,15 +130,15 @@ bool ECPGdeallocate_all(int lineno) { /* deallocate all prepared statements */ - while(prep_stmts != NULL) - { - bool b = ECPGdeallocate(lineno, prep_stmts->name); - - if (!b) + while (prep_stmts != NULL) + { + bool b = ECPGdeallocate(lineno, prep_stmts->name); + + if (!b) return false; - } - - return true; + } + + return true; } /* return the prepared statement */ diff --git a/src/interfaces/ecpg/lib/typename.c b/src/interfaces/ecpg/lib/typename.c index 2b64c19a8ce..19f1fcdbf23 100644 --- a/src/interfaces/ecpg/lib/typename.c +++ b/src/interfaces/ecpg/lib/typename.c @@ -12,7 +12,7 @@ ECPGtype_name(enum ECPGttype typ) { switch (typ) { - case ECPGt_char: + case ECPGt_char: return "char"; case ECPGt_unsigned_char: return "unsigned char"; @@ -47,21 +47,34 @@ ECPGtype_name(enum ECPGttype typ) unsigned int ECPGDynamicType(Oid type) { - switch(type) + switch (type) { - case 16: return SQL3_BOOLEAN; /* bool */ - case 21: return SQL3_SMALLINT; /* int2 */ - case 23: return SQL3_INTEGER; /* int4 */ - case 25: return SQL3_CHARACTER; /* text */ - case 700: return SQL3_REAL; /* float4 */ - case 701: return SQL3_DOUBLE_PRECISION; /* float8 */ - case 1042: return SQL3_CHARACTER; /* bpchar */ - case 1043: return SQL3_CHARACTER_VARYING; /* varchar */ - case 1082: return SQL3_DATE_TIME_TIMESTAMP; /* date */ - case 1083: return SQL3_DATE_TIME_TIMESTAMP; /* time */ - case 1184: return SQL3_DATE_TIME_TIMESTAMP; /* datetime */ - case 1296: return SQL3_DATE_TIME_TIMESTAMP; /* timestamp */ - case 1700: return SQL3_NUMERIC; /* numeric */ - default: return -type; + case 16:return SQL3_BOOLEAN; /* bool */ + case 21: + return SQL3_SMALLINT; /* int2 */ + case 23: + return SQL3_INTEGER;/* int4 */ + case 25: + return SQL3_CHARACTER; /* text */ + case 700: + return SQL3_REAL; /* float4 */ + case 701: + return SQL3_DOUBLE_PRECISION; /* float8 */ + case 1042: + return SQL3_CHARACTER; /* bpchar */ + case 1043: + return SQL3_CHARACTER_VARYING; /* varchar */ + case 1082: + return SQL3_DATE_TIME_TIMESTAMP; /* date */ + case 1083: + return SQL3_DATE_TIME_TIMESTAMP; /* time */ + case 1184: + return SQL3_DATE_TIME_TIMESTAMP; /* datetime */ + case 1296: + return SQL3_DATE_TIME_TIMESTAMP; /* timestamp */ + case 1700: + return SQL3_NUMERIC;/* numeric */ + default: + return -type; } } diff --git a/src/interfaces/ecpg/preproc/descriptor.c b/src/interfaces/ecpg/preproc/descriptor.c index e55aa886cf8..792b286d8c0 100644 --- a/src/interfaces/ecpg/preproc/descriptor.c +++ b/src/interfaces/ecpg/preproc/descriptor.c @@ -3,18 +3,19 @@ */ #include "postgres.h" -#include "extern.h" +#include "extern.h" /* * assignment handling function (descriptor) */ - + struct assignment *assignments; -void push_assignment(char *var, enum ECPGdtype value) +void +push_assignment(char *var, enum ECPGdtype value) { - struct assignment *new = (struct assignment *)mm_alloc(sizeof(struct assignment)); - + struct assignment *new = (struct assignment *) mm_alloc(sizeof(struct assignment)); + new->next = assignments; new->variable = mm_alloc(strlen(var) + 1); strcpy(new->variable, var); @@ -35,91 +36,94 @@ drop_assignments(void) } } -static void ECPGnumeric_lvalue(FILE *f,char *name) +static void +ECPGnumeric_lvalue(FILE *f, char *name) { - const struct variable *v=find_variable(name); + const struct variable *v = find_variable(name); - switch(v->type->typ) + switch (v->type->typ) { case ECPGt_short: - case ECPGt_int: + case ECPGt_int: case ECPGt_long: case ECPGt_unsigned_short: case ECPGt_unsigned_int: case ECPGt_unsigned_long: - fputs(name,yyout); + fputs(name, yyout); break; default: - snprintf(errortext,sizeof errortext,"variable %s: numeric type needed" - ,name); - mmerror(ET_ERROR,errortext); + snprintf(errortext, sizeof errortext, "variable %s: numeric type needed" + ,name); + mmerror(ET_ERROR, errortext); break; - } + } } /* * descriptor name lookup */ - + static struct descriptor *descriptors; -void add_descriptor(char *name,char *connection) +void +add_descriptor(char *name, char *connection) { - struct descriptor *new = (struct descriptor *)mm_alloc(sizeof(struct descriptor)); - + struct descriptor *new = (struct descriptor *) mm_alloc(sizeof(struct descriptor)); + new->next = descriptors; new->name = mm_alloc(strlen(name) + 1); - strcpy(new->name,name); - if (connection) + strcpy(new->name, name); + if (connection) { new->connection = mm_alloc(strlen(connection) + 1); strcpy(new->connection, connection); } - else new->connection = connection; + else + new->connection = connection; descriptors = new; } void -drop_descriptor(char *name,char *connection) +drop_descriptor(char *name, char *connection) { struct descriptor *i; - struct descriptor **lastptr=&descriptors; - - for (i=descriptors;i;lastptr=&i->next,i=i->next) + struct descriptor **lastptr = &descriptors; + + for (i = descriptors; i; lastptr = &i->next, i = i->next) { - if (!strcmp(name,i->name)) + if (!strcmp(name, i->name)) { - if ((!connection && !i->connection) - || (connection && i->connection - && !strcmp(connection,i->connection))) + if ((!connection && !i->connection) + || (connection && i->connection + && !strcmp(connection, i->connection))) { - *lastptr=i->next; - if (i->connection) free(i->connection); + *lastptr = i->next; + if (i->connection) + free(i->connection); free(i->name); free(i); return; } } } - snprintf(errortext,sizeof errortext,"unknown descriptor %s",name); - mmerror(ET_WARN,errortext); + snprintf(errortext, sizeof errortext, "unknown descriptor %s", name); + mmerror(ET_WARN, errortext); } struct descriptor -*lookup_descriptor(char *name, char *connection) + * +lookup_descriptor(char *name, char *connection) { struct descriptor *i; - + for (i = descriptors; i; i = i->next) { if (!strcmp(name, i->name)) { - if ((!connection && !i->connection) - || (connection && i->connection - && !strcmp(connection,i->connection))) - { + if ((!connection && !i->connection) + || (connection && i->connection + && !strcmp(connection, i->connection))) return i; - } } } snprintf(errortext, sizeof errortext, "unknown descriptor %s", name); @@ -136,14 +140,14 @@ output_get_descr_header(char *desc_name) for (results = assignments; results != NULL; results = results->next) { if (results->value == ECPGd_count) - ECPGnumeric_lvalue(yyout,results->variable); + ECPGnumeric_lvalue(yyout, results->variable); else { snprintf(errortext, sizeof errortext, "unknown descriptor header item '%d'", results->value); mmerror(ET_WARN, errortext); } } - + drop_assignments(); fprintf(yyout, "));\n"); whenever_action(3); @@ -154,27 +158,27 @@ output_get_descr(char *desc_name, char *index) { struct assignment *results; - fprintf(yyout, "{ ECPGget_desc(%d,\"%s\",%s,", yylineno, desc_name, index); + fprintf(yyout, "{ ECPGget_desc(%d,\"%s\",%s,", yylineno, desc_name, index); for (results = assignments; results != NULL; results = results->next) { const struct variable *v = find_variable(results->variable); - + switch (results->value) { case ECPGd_nullable: - mmerror(ET_WARN,"nullable is always 1"); + mmerror(ET_WARN, "nullable is always 1"); break; case ECPGd_key_member: - mmerror(ET_WARN,"key_member is always 0"); + mmerror(ET_WARN, "key_member is always 0"); break; default: - break; + break; } fprintf(yyout, "%s,", get_dtype(results->value)); ECPGdump_a_type(yyout, v->name, v->type, NULL, NULL, NULL, NULL); } drop_assignments(); - fputs("ECPGd_EODT);\n",yyout); - - whenever_action(2|1); + fputs("ECPGd_EODT);\n", yyout); + + whenever_action(2 | 1); } diff --git a/src/interfaces/ecpg/preproc/ecpg.c b/src/interfaces/ecpg/preproc/ecpg.c index 31bc48752f7..1cc00dbcc7c 100644 --- a/src/interfaces/ecpg/preproc/ecpg.c +++ b/src/interfaces/ecpg/preproc/ecpg.c @@ -11,7 +11,8 @@ #include "extern.h" -int ret_value = OK, autocommit = 0; +int ret_value = OK, + autocommit = 0; struct _include_path *include_paths = NULL; struct cursor *cur = NULL; struct typedefs *types = NULL; @@ -85,8 +86,8 @@ main(int argc, char *const argv[]) verbose = true; break; case 'D': - add_preprocessor_define(optarg); - break; + add_preprocessor_define(optarg); + break; default: usage(argv[0]); return ILLEGAL_OPTION; @@ -102,7 +103,7 @@ main(int argc, char *const argv[]) fprintf(stderr, "End of search list.\n"); return OK; } - + if (optind >= argc) /* no files specified */ { usage(argv[0]); @@ -123,7 +124,7 @@ main(int argc, char *const argv[]) /* take care of relative paths */ ptr2ext = strrchr(input_filename, '/'); ptr2ext = (ptr2ext ? strrchr(ptr2ext, '.') : strrchr(input_filename, '.')); - + /* no extension? */ if (ptr2ext == NULL) { @@ -137,7 +138,7 @@ main(int argc, char *const argv[]) ptr2ext[4] = '\0'; } - if (out_option == 0) /* calculate the output name */ + if (out_option == 0)/* calculate the output name */ { output_filename = strdup(input_filename); @@ -177,7 +178,8 @@ main(int argc, char *const argv[]) for (ptr = cur; ptr != NULL;) { struct cursor *this = ptr; - struct arguments *l1, *l2; + struct arguments *l1, + *l2; free(ptr->command); free(ptr->connection); @@ -198,26 +200,28 @@ main(int argc, char *const argv[]) cur = NULL; /* remove non-pertinent old defines as well */ - while ( defines && !defines->pertinent ) { - defptr = defines; - defines = defines->next; + while (defines && !defines->pertinent) + { + defptr = defines; + defines = defines->next; - free(defptr->new); - free(defptr->old); - free(defptr); + free(defptr->new); + free(defptr->old); + free(defptr); } - for (defptr = defines; defptr != NULL; defptr = defptr->next ) + for (defptr = defines; defptr != NULL; defptr = defptr->next) { - struct _defines *this = defptr->next; - - if ( this && !this->pertinent ) { - defptr->next = this->next; + struct _defines *this = defptr->next; - free(this->new); - free(this->old); - free(this); - } + if (this && !this->pertinent) + { + defptr->next = this->next; + + free(this->new); + free(this->old); + free(this); + } } /* and old typedefs */ @@ -232,18 +236,18 @@ main(int argc, char *const argv[]) free(this); } types = NULL; - + /* initialize whenever structures */ memset(&when_error, 0, sizeof(struct when)); memset(&when_nf, 0, sizeof(struct when)); memset(&when_warn, 0, sizeof(struct when)); - + /* and structure member lists */ memset(struct_member_list, 0, sizeof(struct_member_list)); - + /* finally the actual connection */ connection = NULL; - + /* initialize lex */ lex_init(); diff --git a/src/interfaces/ecpg/preproc/ecpg_keywords.c b/src/interfaces/ecpg/preproc/ecpg_keywords.c index 0a468c041ea..a1a0452e1cb 100644 --- a/src/interfaces/ecpg/preproc/ecpg_keywords.c +++ b/src/interfaces/ecpg/preproc/ecpg_keywords.c @@ -61,7 +61,8 @@ static ScanKeyword ScanKeywords[] = { {"section", SQL_SECTION}, {"short", SQL_SHORT}, {"signed", SQL_SIGNED}, - {"sql",SQL_SQL}, /* strange thing, used for into sql descriptor MYDESC; */ + {"sql", SQL_SQL}, /* strange thing, used for into sql + * descriptor MYDESC; */ {"sqlerror", SQL_SQLERROR}, {"sqlprint", SQL_SQLPRINT}, {"sqlwarning", SQL_SQLWARNING}, diff --git a/src/interfaces/ecpg/preproc/extern.h b/src/interfaces/ecpg/preproc/extern.h index bcdba111915..779985ac169 100644 --- a/src/interfaces/ecpg/preproc/extern.h +++ b/src/interfaces/ecpg/preproc/extern.h @@ -10,16 +10,19 @@ /* variables */ extern int braces_open, - autocommit, - ret_value, - struct_level; + autocommit, + ret_value, + struct_level; extern char *descriptor_index; extern char *descriptor_name; extern char *connection; -extern char *input_filename; -extern char *yytext, errortext[128]; -extern int yylineno, yyleng; -extern FILE *yyin, *yyout; +extern char *input_filename; +extern char *yytext, + errortext[128]; +extern int yylineno, + yyleng; +extern FILE *yyin, + *yyout; extern struct _include_path *include_paths; extern struct cursor *cur; @@ -29,7 +32,9 @@ extern struct ECPGtype ecpg_no_indicator; extern struct variable no_indicator; extern struct arguments *argsinsert; extern struct arguments *argsresult; -extern struct when when_error, when_nf, when_warn; +extern struct when when_error, + when_nf, + when_warn; extern struct ECPGstruct_member *struct_member_list[STRUCT_DEPTH]; extern struct descriptor *descriptors; @@ -47,19 +52,19 @@ extern int yylex(void); extern void yyerror(char *); extern void *mm_alloc(size_t), *mm_realloc(void *, size_t); extern char *mm_strdup(const char *); -extern void mmerror(enum errortype, char * ); +extern void mmerror(enum errortype, char *); extern ScanKeyword *ScanECPGKeywordLookup(char *); extern ScanKeyword *ScanCKeywordLookup(char *); extern void output_get_descr_header(char *); extern void output_get_descr(char *, char *); extern void push_assignment(char *, enum ECPGdtype); -extern struct variable * find_variable(char *); +extern struct variable *find_variable(char *); extern void whenever_action(int); -extern void add_descriptor(char *,char *); -extern void drop_descriptor(char *,char *); -extern struct descriptor *lookup_descriptor(char *,char *); -extern void add_variable(struct arguments ** , struct variable * , struct variable *); -extern void append_variable(struct arguments ** , struct variable * , struct variable *); +extern void add_descriptor(char *, char *); +extern void drop_descriptor(char *, char *); +extern struct descriptor *lookup_descriptor(char *, char *); +extern void add_variable(struct arguments **, struct variable *, struct variable *); +extern void append_variable(struct arguments **, struct variable *, struct variable *); extern void dump_variables(struct arguments *, int); extern struct typedefs *get_typedef(char *); extern void adjust_array(enum ECPGttype, int *, int *, int, int, bool); @@ -67,13 +72,13 @@ extern void reset_variables(void); extern void check_indicator(struct ECPGtype *); extern void remove_variables(int); extern struct variable *new_variable(const char *, struct ECPGtype *); - + /* return codes */ #define OK 0 #define PARSE_ERROR -1 #define ILLEGAL_OPTION -2 -#define INDICATOR_NOT_ARRAY -3 +#define INDICATOR_NOT_ARRAY -3 #define NO_INCLUDE_FILE ENOENT #define OUT_OF_MEMORY ENOMEM diff --git a/src/interfaces/ecpg/preproc/output.c b/src/interfaces/ecpg/preproc/output.c index 760751affd3..7fe282586f6 100644 --- a/src/interfaces/ecpg/preproc/output.c +++ b/src/interfaces/ecpg/preproc/output.c @@ -6,74 +6,83 @@ void output_line_number() { - if (input_filename) - fprintf(yyout, "\n#line %d \"%s\"\n", yylineno, input_filename); + if (input_filename) + fprintf(yyout, "\n#line %d \"%s\"\n", yylineno, input_filename); } void output_simple_statement(char *cmd) { - int i, j = strlen(cmd);; - + int i, + j = strlen(cmd);; + /* do this char by char as we have to filter '\"' */ - for (i = 0; i < j; i++) { + for (i = 0; i < j; i++) + { if (cmd[i] != '"') fputc(cmd[i], yyout); else fputs("\\\"", yyout); } output_line_number(); - free(cmd); + free(cmd); } /* * store the whenever action here */ -struct when when_error, when_nf, when_warn; +struct when when_error, + when_nf, + when_warn; static void -print_action(struct when *w) +print_action(struct when * w) { switch (w->code) { - case W_SQLPRINT: fprintf(yyout, "sqlprint();"); - break; - case W_GOTO: fprintf(yyout, "goto %s;", w->command); - break; - case W_DO: fprintf(yyout, "%s;", w->command); - break; - case W_STOP: fprintf(yyout, "exit (1);"); - break; - case W_BREAK: fprintf(yyout, "break;"); - break; - default: fprintf(yyout, "{/* %d not implemented yet */}", w->code); - break; + case W_SQLPRINT:fprintf(yyout, "sqlprint();"); + break; + case W_GOTO: + fprintf(yyout, "goto %s;", w->command); + break; + case W_DO: + fprintf(yyout, "%s;", w->command); + break; + case W_STOP: + fprintf(yyout, "exit (1);"); + break; + case W_BREAK: + fprintf(yyout, "break;"); + break; + default: + fprintf(yyout, "{/* %d not implemented yet */}", w->code); + break; } } void whenever_action(int mode) { - if ((mode&1) == 1 && when_nf.code != W_NOTHING) + if ((mode & 1) == 1 && when_nf.code != W_NOTHING) { output_line_number(); fprintf(yyout, "\nif (sqlca.sqlcode == ECPG_NOT_FOUND) "); print_action(&when_nf); } if (when_warn.code != W_NOTHING) - { + { output_line_number(); - fprintf(yyout, "\nif (sqlca.sqlwarn[0] == 'W') "); + fprintf(yyout, "\nif (sqlca.sqlwarn[0] == 'W') "); print_action(&when_warn); - } + } if (when_error.code != W_NOTHING) - { + { output_line_number(); - fprintf(yyout, "\nif (sqlca.sqlcode < 0) "); + fprintf(yyout, "\nif (sqlca.sqlcode < 0) "); print_action(&when_error); - } + } - if ((mode&2) == 2) + if ((mode & 2) == 2) fputc('}', yyout); output_line_number(); @@ -82,30 +91,33 @@ whenever_action(int mode) char * hashline_number(void) { - if (input_filename) - { - char* line = mm_alloc(strlen("\n#line %d \"%s\"\n") + 21 + strlen(input_filename)); - sprintf(line, "\n#line %d \"%s\"\n", yylineno, input_filename); + if (input_filename) + { + char *line = mm_alloc(strlen("\n#line %d \"%s\"\n") + 21 + strlen(input_filename)); - return line; - } + sprintf(line, "\n#line %d \"%s\"\n", yylineno, input_filename); - return EMPTY; + return line; + } + + return EMPTY; } void -output_statement(char * stmt, int mode, char *descriptor, char *con) +output_statement(char *stmt, int mode, char *descriptor, char *con) { - int i, j = strlen(stmt); + int i, + j = strlen(stmt); if (descriptor == NULL) fprintf(yyout, "{ ECPGdo(__LINE__, %s, \"", con ? con : "NULL"); else - fprintf(yyout, "{ ECPGdo_descriptor(__LINE__, %s, \"%s\", \"", - con ? con : "NULL", descriptor); + fprintf(yyout, "{ ECPGdo_descriptor(__LINE__, %s, \"%s\", \"", + con ? con : "NULL", descriptor); /* do this char by char as we have to filter '\"' */ - for (i = 0; i < j; i++) { + for (i = 0; i < j; i++) + { if (stmt[i] != '"') fputc(stmt[i], yyout); else @@ -115,7 +127,7 @@ output_statement(char * stmt, int mode, char *descriptor, char *con) if (descriptor == NULL) { fputs("\", ", yyout); - + /* dump variables to C file */ dump_variables(argsinsert, 1); fputs("ECPGt_EOIT, ", yyout); @@ -125,7 +137,7 @@ output_statement(char * stmt, int mode, char *descriptor, char *con) } else fputs("\");", yyout); - + mode |= 2; whenever_action(mode); free(stmt); @@ -134,4 +146,3 @@ output_statement(char * stmt, int mode, char *descriptor, char *con) if (connection != NULL) free(connection); } - diff --git a/src/interfaces/ecpg/preproc/type.c b/src/interfaces/ecpg/preproc/type.c index 95c79e3f09e..8d292e11098 100644 --- a/src/interfaces/ecpg/preproc/type.c +++ b/src/interfaces/ecpg/preproc/type.c @@ -124,7 +124,7 @@ get_type(enum ECPGttype typ) { switch (typ) { - case ECPGt_char: + case ECPGt_char: return ("ECPGt_char"); break; case ECPGt_unsigned_char: @@ -163,7 +163,7 @@ get_type(enum ECPGttype typ) return ("ECPGt_NO_INDICATOR"); break; case ECPGt_char_variable: /* string that should not be - * quoted */ + * quoted */ return ("ECPGt_char_variable"); break; default: @@ -200,10 +200,10 @@ ECPGdump_a_type(FILE *o, const char *name, struct ECPGtype * typ, const char *in { switch (typ->typ) { - case ECPGt_array: + case ECPGt_array: switch (typ->u.element->typ) { - case ECPGt_array: + case ECPGt_array: yyerror("No nested arrays allowed (except strings)"); /* array of array */ break; case ECPGt_struct: @@ -269,7 +269,11 @@ ECPGdump_a_simple(FILE *o, const char *name, enum ECPGttype typ, switch (typ) { case ECPGt_varchar: - /* we have to use the pointer except for arrays with given bounds */ + + /* + * we have to use the pointer except for arrays with given + * bounds + */ if (arrsize > 0) sprintf(variable, "(%s%s)", prefix ? prefix : "", name); else @@ -280,7 +284,11 @@ ECPGdump_a_simple(FILE *o, const char *name, enum ECPGttype typ, case ECPGt_char: case ECPGt_unsigned_char: case ECPGt_char_variable: - /* we have to use the pointer except for arrays with given bounds */ + + /* + * we have to use the pointer except for arrays with given + * bounds + */ if (varcharsize > 1 || arrsize > 0) sprintf(variable, "(%s%s)", prefix ? prefix : "", name); else @@ -289,7 +297,11 @@ ECPGdump_a_simple(FILE *o, const char *name, enum ECPGttype typ, sprintf(offset, "%ld*sizeof(char)", varcharsize == 0 ? 1 : varcharsize); break; default: - /* we have to use the pointer except for arrays with given bounds */ + + /* + * we have to use the pointer except for arrays with given + * bounds + */ if (arrsize > 0) sprintf(variable, "(%s%s)", prefix ? prefix : "", name); else @@ -375,10 +387,10 @@ ECPGfree_type(struct ECPGtype * typ) { switch (typ->typ) { - case ECPGt_array: + case ECPGt_array: switch (typ->u.element->typ) { - case ECPGt_array: + case ECPGt_array: yyerror("internal error, found multi-dimensional array\n"); break; case ECPGt_struct: @@ -412,7 +424,7 @@ get_dtype(enum ECPGdtype typ) { switch (typ) { - case ECPGd_count: + case ECPGd_count: return ("ECPGd_countr"); break; case ECPGd_data: @@ -450,10 +462,10 @@ get_dtype(enum ECPGdtype typ) case ECPGd_ret_octet: return ("ECPGd_ret_octet"); break; - case ECPGd_scale: + case ECPGd_scale: return ("ECPGd_scale"); break; - case ECPGd_type: + case ECPGd_type: return ("ECPGd_type"); break; default: diff --git a/src/interfaces/ecpg/preproc/type.h b/src/interfaces/ecpg/preproc/type.h index 29525c392c3..7ce1e892870 100644 --- a/src/interfaces/ecpg/preproc/type.h +++ b/src/interfaces/ecpg/preproc/type.h @@ -119,7 +119,7 @@ struct _defines { char *old; char *new; - int pertinent; + int pertinent; struct _defines *next; }; @@ -141,22 +141,25 @@ struct arguments struct descriptor { - char *name; - char *connection; + char *name; + char *connection; struct descriptor *next; }; struct assignment -{ - char *variable; - enum ECPGdtype value; - struct assignment *next; +{ + char *variable; + enum ECPGdtype value; + struct assignment *next; }; -enum errortype {ET_WARN, ET_ERROR, ET_FATAL}; +enum errortype +{ + ET_WARN, ET_ERROR, ET_FATAL +}; struct fetch_desc { - char *str; - char *name; + char *str; + char *name; }; diff --git a/src/interfaces/ecpg/preproc/variable.c b/src/interfaces/ecpg/preproc/variable.c index 3de45350b1c..f3d2dca0597 100644 --- a/src/interfaces/ecpg/preproc/variable.c +++ b/src/interfaces/ecpg/preproc/variable.c @@ -2,174 +2,177 @@ #include "extern.h" -struct variable * allvariables = NULL; +struct variable *allvariables = NULL; struct variable * -new_variable(const char * name, struct ECPGtype * type) +new_variable(const char *name, struct ECPGtype * type) { - struct variable * p = (struct variable*) mm_alloc(sizeof(struct variable)); + struct variable *p = (struct variable *) mm_alloc(sizeof(struct variable)); - p->name = mm_strdup(name); - p->type = type; - p->brace_level = braces_open; + p->name = mm_strdup(name); + p->type = type; + p->brace_level = braces_open; - p->next = allvariables; - allvariables = p; + p->next = allvariables; + allvariables = p; - return(p); + return (p); } static struct variable * -find_struct_member(char *name, char *str, struct ECPGstruct_member *members) +find_struct_member(char *name, char *str, struct ECPGstruct_member * members) { - char *next = strchr(++str, '.'), c = '\0'; + char *next = strchr(++str, '.'), + c = '\0'; - if (next != NULL) - { - c = *next; - *next = '\0'; - } + if (next != NULL) + { + c = *next; + *next = '\0'; + } - for (; members; members = members->next) - { - if (strcmp(members->name, str) == 0) + for (; members; members = members->next) { - if (c == '\0') + if (strcmp(members->name, str) == 0) { - /* found the end */ - switch (members->typ->typ) + if (c == '\0') { - case ECPGt_array: - return(new_variable(name, ECPGmake_array_type(members->typ->u.element, members->typ->size))); - case ECPGt_struct: - case ECPGt_union: - return(new_variable(name, ECPGmake_struct_type(members->typ->u.members, members->typ->typ))); - default: - return(new_variable(name, ECPGmake_simple_type(members->typ->typ, members->typ->size))); + /* found the end */ + switch (members->typ->typ) + { + case ECPGt_array: + return (new_variable(name, ECPGmake_array_type(members->typ->u.element, members->typ->size))); + case ECPGt_struct: + case ECPGt_union: + return (new_variable(name, ECPGmake_struct_type(members->typ->u.members, members->typ->typ))); + default: + return (new_variable(name, ECPGmake_simple_type(members->typ->typ, members->typ->size))); + } } - } - else - { - *next = c; - if (c == '-') + else { - next++; - return(find_struct_member(name, next, members->typ->u.element->u.members)); + *next = c; + if (c == '-') + { + next++; + return (find_struct_member(name, next, members->typ->u.element->u.members)); + } + else + return (find_struct_member(name, next, members->typ->u.members)); } - else return(find_struct_member(name, next, members->typ->u.members)); } } - } - return(NULL); + return (NULL); } static struct variable * -find_struct(char * name, char *next) +find_struct(char *name, char *next) { - struct variable * p; - char c = *next; - - /* first get the mother structure entry */ - *next = '\0'; - p = find_variable(name); - - if (c == '-') - { - if (p->type->typ != ECPGt_struct && p->type->typ != ECPGt_union) - { - sprintf(errortext, "variable %s is not a pointer", name); - mmerror(ET_FATAL, errortext); - } - - if (p->type->u.element->typ != ECPGt_struct && p->type->u.element->typ != ECPGt_union) - { - sprintf(errortext, "variable %s is not a pointer to a structure or a union", name); - mmerror(ET_FATAL, errortext); - } - - /* restore the name, we will need it later on */ - *next = c; - next++; - - return find_struct_member(name, next, p->type->u.element->u.members); - } - else - { - if (p->type->typ != ECPGt_struct && p->type->typ != ECPGt_union) + struct variable *p; + char c = *next; + + /* first get the mother structure entry */ + *next = '\0'; + p = find_variable(name); + + if (c == '-') { - sprintf(errortext, "variable %s is neither a structure nor a union", name); - mmerror(ET_FATAL, errortext); + if (p->type->typ != ECPGt_struct && p->type->typ != ECPGt_union) + { + sprintf(errortext, "variable %s is not a pointer", name); + mmerror(ET_FATAL, errortext); + } + + if (p->type->u.element->typ != ECPGt_struct && p->type->u.element->typ != ECPGt_union) + { + sprintf(errortext, "variable %s is not a pointer to a structure or a union", name); + mmerror(ET_FATAL, errortext); + } + + /* restore the name, we will need it later on */ + *next = c; + next++; + + return find_struct_member(name, next, p->type->u.element->u.members); } + else + { + if (p->type->typ != ECPGt_struct && p->type->typ != ECPGt_union) + { + sprintf(errortext, "variable %s is neither a structure nor a union", name); + mmerror(ET_FATAL, errortext); + } - /* restore the name, we will need it later on */ - *next = c; + /* restore the name, we will need it later on */ + *next = c; - return find_struct_member(name, next, p->type->u.members); - } + return find_struct_member(name, next, p->type->u.members); + } } static struct variable * -find_simple(char * name) +find_simple(char *name) { - struct variable * p; + struct variable *p; - for (p = allvariables; p; p = p->next) - { - if (strcmp(p->name, name) == 0) - return p; - } + for (p = allvariables; p; p = p->next) + { + if (strcmp(p->name, name) == 0) + return p; + } - return(NULL); + return (NULL); } /* Note that this function will end the program in case of an unknown */ /* variable */ struct variable * -find_variable(char * name) +find_variable(char *name) { - char * next; - struct variable * p; - - if ((next = strchr(name, '.')) != NULL) - p = find_struct(name, next); - else if ((next = strstr(name, "->")) != NULL) - p = find_struct(name, next); - else - p = find_simple(name); - - if (p == NULL) - { - sprintf(errortext, "The variable %s is not declared", name); - mmerror(ET_FATAL, errortext); - } - - return(p); + char *next; + struct variable *p; + + if ((next = strchr(name, '.')) != NULL) + p = find_struct(name, next); + else if ((next = strstr(name, "->")) != NULL) + p = find_struct(name, next); + else + p = find_simple(name); + + if (p == NULL) + { + sprintf(errortext, "The variable %s is not declared", name); + mmerror(ET_FATAL, errortext); + } + + return (p); } void remove_variables(int brace_level) { - struct variable * p, *prev; + struct variable *p, + *prev; - for (p = prev = allvariables; p; p = p ? p->next : NULL) - { - if (p->brace_level >= brace_level) + for (p = prev = allvariables; p; p = p ? p->next : NULL) { - /* remove it */ - if (p == allvariables) - prev = allvariables = p->next; - else - prev->next = p->next; - - ECPGfree_type(p->type); - free(p->name); - free(p); - p = prev; + if (p->brace_level >= brace_level) + { + /* remove it */ + if (p == allvariables) + prev = allvariables = p->next; + else + prev->next = p->next; + + ECPGfree_type(p->type); + free(p->name); + free(p); + p = prev; + } + else + prev = p; } - else - prev = p; - } } @@ -179,44 +182,45 @@ remove_variables(int brace_level) * I will make two lists for them. */ -struct arguments * argsinsert = NULL; -struct arguments * argsresult = NULL; +struct arguments *argsinsert = NULL; +struct arguments *argsresult = NULL; void reset_variables(void) { - argsinsert = NULL; - argsresult = NULL; + argsinsert = NULL; + argsresult = NULL; } /* Insert a new variable into our request list. */ void add_variable(struct arguments ** list, struct variable * var, struct variable * ind) { - struct arguments *p = (struct arguments *)mm_alloc(sizeof(struct arguments)); - - p->variable = var; - p->indicator = ind; - p->next = *list; - *list = p; + struct arguments *p = (struct arguments *) mm_alloc(sizeof(struct arguments)); + + p->variable = var; + p->indicator = ind; + p->next = *list; + *list = p; } /* Append a new variable to our request list. */ void append_variable(struct arguments ** list, struct variable * var, struct variable * ind) { - struct arguments *p, *new = (struct arguments *)mm_alloc(sizeof(struct arguments)); - - for (p = *list; p && p->next; p = p->next); - - new->variable = var; - new->indicator = ind; - new->next = NULL; - - if (p) - p->next = new; - else - *list = new; + struct arguments *p, + *new = (struct arguments *) mm_alloc(sizeof(struct arguments)); + + for (p = *list; p && p->next; p = p->next); + + new->variable = var; + new->indicator = ind; + new->next = NULL; + + if (p) + p->next = new; + else + *list = new; } /* Dump out a list of all the variable on this list. @@ -226,33 +230,32 @@ append_variable(struct arguments ** list, struct variable * var, struct variable void dump_variables(struct arguments * list, int mode) { - if (list == NULL) - { - return; - } + if (list == NULL) + return; - /* The list is build up from the beginning so lets first dump the - end of the list: - */ + /* + * The list is build up from the beginning so lets first dump the end + * of the list: + */ - dump_variables(list->next, mode); + dump_variables(list->next, mode); - /* Then the current element and its indicator */ - ECPGdump_a_type(yyout, list->variable->name, list->variable->type, - list->indicator->name, list->indicator->type, NULL, NULL); + /* Then the current element and its indicator */ + ECPGdump_a_type(yyout, list->variable->name, list->variable->type, + list->indicator->name, list->indicator->type, NULL, NULL); - /* Then release the list element. */ - if (mode != 0) - free(list); + /* Then release the list element. */ + if (mode != 0) + free(list); } void -check_indicator(struct ECPGtype *var) +check_indicator(struct ECPGtype * var) { /* make sure this is a valid indicator variable */ switch (var->typ) { - struct ECPGstruct_member *p; + struct ECPGstruct_member *p; case ECPGt_short: case ECPGt_int: @@ -271,7 +274,7 @@ check_indicator(struct ECPGtype *var) case ECPGt_array: check_indicator(var->u.element); break; - default: + default: mmerror(ET_ERROR, "indicator variable must be integer type"); break; } @@ -289,20 +292,20 @@ get_typedef(char *name) mmerror(ET_FATAL, errortext); } - return(this); + return (this); } void adjust_array(enum ECPGttype type_enum, int *dimension, int *length, int type_dimension, int type_index, bool pointer) { - if (type_index >= 0) + if (type_index >= 0) { if (*length >= 0) - mmerror(ET_FATAL, "No multi-dimensional array support"); + mmerror(ET_FATAL, "No multi-dimensional array support"); *length = type_index; } - + if (type_dimension >= 0) { if (*dimension >= 0 && *length >= 0) @@ -319,56 +322,57 @@ adjust_array(enum ECPGttype type_enum, int *dimension, int *length, int type_dim switch (type_enum) { - case ECPGt_struct: - case ECPGt_union: - /* pointer has to get dimension 0 */ - if (pointer) - { - *length = *dimension; - *dimension = 0; - } - - if (*length >= 0) - mmerror(ET_FATAL, "No multi-dimensional array support for structures"); - - break; - case ECPGt_varchar: - /* pointer has to get dimension 0 */ - if (pointer) - *dimension = 0; - - /* one index is the string length */ - if (*length < 0) - { - *length = *dimension; - *dimension = -1; - } - - break; - case ECPGt_char: - case ECPGt_unsigned_char: - /* pointer has to get length 0 */ - if (pointer) - *length=0; - - /* one index is the string length */ - if (*length < 0) - { - *length = (*dimension < 0) ? 1 : *dimension; - *dimension = -1; - } - - break; - default: - /* a pointer has dimension = 0 */ - if (pointer) { - *length = *dimension; - *dimension = 0; - } - - if (*length >= 0) - mmerror(ET_FATAL, "No multi-dimensional array support for simple data types"); - - break; + case ECPGt_struct: + case ECPGt_union: + /* pointer has to get dimension 0 */ + if (pointer) + { + *length = *dimension; + *dimension = 0; + } + + if (*length >= 0) + mmerror(ET_FATAL, "No multi-dimensional array support for structures"); + + break; + case ECPGt_varchar: + /* pointer has to get dimension 0 */ + if (pointer) + *dimension = 0; + + /* one index is the string length */ + if (*length < 0) + { + *length = *dimension; + *dimension = -1; + } + + break; + case ECPGt_char: + case ECPGt_unsigned_char: + /* pointer has to get length 0 */ + if (pointer) + *length = 0; + + /* one index is the string length */ + if (*length < 0) + { + *length = (*dimension < 0) ? 1 : *dimension; + *dimension = -1; + } + + break; + default: + /* a pointer has dimension = 0 */ + if (pointer) + { + *length = *dimension; + *dimension = 0; + } + + if (*length >= 0) + mmerror(ET_FATAL, "No multi-dimensional array support for simple data types"); + + break; } } diff --git a/src/interfaces/ecpg/test/header_test.h b/src/interfaces/ecpg/test/header_test.h index 71017aacbbd..741c6fa4b7a 100644 --- a/src/interfaces/ecpg/test/header_test.h +++ b/src/interfaces/ecpg/test/header_test.h @@ -1,26 +1,32 @@ exec sql include sqlca; -void Finish(msg) +void +Finish(msg) { fprintf(stderr, "Error in statement '%s':\n", msg); sqlprint(); - + /* finish transaction */ - exec sql rollback; - + exec sql rollback; + /* and remove test table */ exec sql drop table meskes; - exec sql commit; + exec sql commit; + + exec sql disconnect; - exec sql disconnect; - exit(-1); } -void warn(void) +void +warn(void) { fprintf(stderr, "Warning: At least one column was truncated\n"); } -exec sql whenever sqlerror do Finish(msg); -exec sql whenever sqlwarning do warn(); +exec sql whenever sqlerror +do + Finish(msg); +exec sql whenever sqlwarning +do + warn(); diff --git a/src/interfaces/libpgeasy/halt.c b/src/interfaces/libpgeasy/halt.c index 9d9796a6cba..2173f7adf6e 100644 --- a/src/interfaces/libpgeasy/halt.c +++ b/src/interfaces/libpgeasy/halt.c @@ -20,7 +20,7 @@ **------------------------------------------------------------------------*/ void -halt(char *format, ...) +halt(char *format,...) { va_list arg_ptr; char *pstr; diff --git a/src/interfaces/libpgeasy/libpgeasy.h b/src/interfaces/libpgeasy/libpgeasy.h index 43fbeaba85e..e58d5a1cd60 100644 --- a/src/interfaces/libpgeasy/libpgeasy.h +++ b/src/interfaces/libpgeasy/libpgeasy.h @@ -4,11 +4,11 @@ */ PGresult *doquery(char *query); -PGconn *connectdb(char *dbName, - char *pghost, - char *pgport, - char *pgoptions, - char *pgtty); +PGconn *connectdb(char *dbName, + char *pghost, + char *pgport, + char *pgoptions, + char *pgtty); void disconnectdb(void); int fetch(void *param,...); int fetchwithnulls(void *param,...); diff --git a/src/interfaces/libpgtcl/pgtclCmds.c b/src/interfaces/libpgtcl/pgtclCmds.c index 10aa2f01bc0..fb0341b857d 100644 --- a/src/interfaces/libpgtcl/pgtclCmds.c +++ b/src/interfaces/libpgtcl/pgtclCmds.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/interfaces/libpgtcl/Attic/pgtclCmds.c,v 1.48 2000/03/11 03:08:35 tgl Exp $ + * $Header: /cvsroot/pgsql/src/interfaces/libpgtcl/Attic/pgtclCmds.c,v 1.49 2000/04/12 17:17:11 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -1381,7 +1381,7 @@ Pg_select(ClientData cData, Tcl_Interp *interp, int argc, char **argv) */ static int -Pg_have_listener(Pg_ConnectionId *connid, const char *relname) +Pg_have_listener(Pg_ConnectionId * connid, const char *relname) { Pg_TclNotifies *notifies; Tcl_HashEntry *entry; diff --git a/src/interfaces/libpgtcl/pgtclCmds.h b/src/interfaces/libpgtcl/pgtclCmds.h index 2cb20211e10..b1d908fbee2 100644 --- a/src/interfaces/libpgtcl/pgtclCmds.h +++ b/src/interfaces/libpgtcl/pgtclCmds.h @@ -6,7 +6,7 @@ * Portions Copyright (c) 1996-2000, PostgreSQL, Inc * Portions Copyright (c) 1994, Regents of the University of California * - * $Id: pgtclCmds.h,v 1.16 2000/01/26 05:58:43 momjian Exp $ + * $Id: pgtclCmds.h,v 1.17 2000/04/12 17:17:11 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -39,7 +39,7 @@ typedef struct Pg_TclNotifies_s * got round to deleting the Pg_TclNotifies structure. */ Tcl_HashTable notify_hash; /* Active pg_listen requests */ -} Pg_TclNotifies; +} Pg_TclNotifies; typedef struct Pg_ConnectionId_s { @@ -56,7 +56,7 @@ typedef struct Pg_ConnectionId_s Pg_TclNotifies *notify_list;/* head of list of notify info */ int notifier_running; /* notify event source is live */ int notifier_socket;/* PQsocket on which notifier is listening */ -} Pg_ConnectionId; +} Pg_ConnectionId; /* Values of res_copyStatus */ #define RES_COPY_NONE 0 diff --git a/src/interfaces/libpgtcl/pgtclId.c b/src/interfaces/libpgtcl/pgtclId.c index 1ecf7e02f8b..2cb0cb9de41 100644 --- a/src/interfaces/libpgtcl/pgtclId.c +++ b/src/interfaces/libpgtcl/pgtclId.c @@ -13,7 +13,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/interfaces/libpgtcl/Attic/pgtclId.c,v 1.22 2000/01/26 05:58:43 momjian Exp $ + * $Header: /cvsroot/pgsql/src/interfaces/libpgtcl/Attic/pgtclId.c,v 1.23 2000/04/12 17:17:11 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -26,7 +26,7 @@ static int -PgEndCopy(Pg_ConnectionId *connid, int *errorCodePtr) +PgEndCopy(Pg_ConnectionId * connid, int *errorCodePtr) { connid->res_copyStatus = RES_COPY_NONE; if (PQendcopy(connid->conn)) @@ -197,7 +197,7 @@ PgSetConnectionId(Tcl_Interp *interp, PGconn *conn) * Get back the connection from the Id */ PGconn * -PgGetConnectionId(Tcl_Interp *interp, char *id, Pg_ConnectionId **connid_p) +PgGetConnectionId(Tcl_Interp *interp, char *id, Pg_ConnectionId ** connid_p) { Tcl_Channel conn_chan; Pg_ConnectionId *connid; @@ -333,7 +333,7 @@ PgSetResultId(Tcl_Interp *interp, char *connid_c, PGresult *res) } static int -getresid(Tcl_Interp *interp, char *id, Pg_ConnectionId **connid_p) +getresid(Tcl_Interp *interp, char *id, Pg_ConnectionId ** connid_p) { Tcl_Channel conn_chan; char *mark; @@ -477,7 +477,7 @@ typedef struct Tcl_Event header; /* Standard Tcl event info */ PGnotify info; /* Notify name from SQL server */ Pg_ConnectionId *connid; /* Connection for server */ -} NotifyEvent; +} NotifyEvent; /* Dispatch a NotifyEvent that has reached the front of the event queue */ @@ -569,7 +569,7 @@ Pg_Notify_EventProc(Tcl_Event *evPtr, int flags) */ void -PgNotifyTransferEvents(Pg_ConnectionId *connid) +PgNotifyTransferEvents(Pg_ConnectionId * connid) { PGnotify *notify; @@ -678,7 +678,7 @@ Pg_Notify_FileHandler(ClientData clientData, int mask) */ void -PgStartNotifyEventSource(Pg_ConnectionId *connid) +PgStartNotifyEventSource(Pg_ConnectionId * connid) { /* Start the notify event source if it isn't already running */ if (!connid->notifier_running) @@ -705,7 +705,7 @@ PgStartNotifyEventSource(Pg_ConnectionId *connid) } void -PgStopNotifyEventSource(Pg_ConnectionId *connid) +PgStopNotifyEventSource(Pg_ConnectionId * connid) { /* Remove the event source */ if (connid->notifier_running) diff --git a/src/interfaces/libpgtcl/pgtclId.h b/src/interfaces/libpgtcl/pgtclId.h index abe41e761f9..1cbb262dd59 100644 --- a/src/interfaces/libpgtcl/pgtclId.h +++ b/src/interfaces/libpgtcl/pgtclId.h @@ -10,7 +10,7 @@ * Portions Copyright (c) 1996-2000, PostgreSQL, Inc * Portions Copyright (c) 1994, Regents of the University of California * - * $Id: pgtclId.h,v 1.14 2000/01/26 05:58:43 momjian Exp $ + * $Id: pgtclId.h,v 1.15 2000/04/12 17:17:12 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -43,9 +43,9 @@ extern int PgSetResultId(Tcl_Interp *interp, char *connid, PGresult *res); extern PGresult *PgGetResultId(Tcl_Interp *interp, char *id); extern void PgDelResultId(Tcl_Interp *interp, char *id); extern int PgGetConnByResultId(Tcl_Interp *interp, char *resid); -extern void PgStartNotifyEventSource(Pg_ConnectionId *connid); -extern void PgStopNotifyEventSource(Pg_ConnectionId *connid); -extern void PgNotifyTransferEvents(Pg_ConnectionId *connid); +extern void PgStartNotifyEventSource(Pg_ConnectionId * connid); +extern void PgStopNotifyEventSource(Pg_ConnectionId * connid); +extern void PgNotifyTransferEvents(Pg_ConnectionId * connid); extern void PgNotifyInterpDelete(ClientData clientData, Tcl_Interp *interp); /* GetFileProc is needed in Tcl 7.6 *only* ... it went away again in 8.0 */ diff --git a/src/interfaces/libpq/fe-auth.c b/src/interfaces/libpq/fe-auth.c index fe870963df4..bf5a21bee9a 100644 --- a/src/interfaces/libpq/fe-auth.c +++ b/src/interfaces/libpq/fe-auth.c @@ -10,7 +10,7 @@ * exceed INITIAL_EXPBUFFER_SIZE (currently 256 bytes). * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-auth.c,v 1.38 2000/03/11 03:08:36 tgl Exp $ + * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-auth.c,v 1.39 2000/04/12 17:17:13 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -94,7 +94,7 @@ static const struct authsvc authsvcs[] = { {"password", STARTUP_PASSWORD_MSG, 0} }; -static const int n_authsvcs = sizeof(authsvcs) / sizeof(struct authsvc); +static const int n_authsvcs = sizeof(authsvcs) / sizeof(struct authsvc); #ifdef KRB4 /*---------------------------------------------------------------- @@ -475,12 +475,12 @@ fe_sendauth(AuthRequest areq, PGconn *conn, const char *hostname, const char *password, char *PQerrormsg) { #if !defined(KRB4) && !defined(KRB5) - (void)hostname; /*not used*/ + (void) hostname; /* not used */ #endif switch (areq) { - case AUTH_REQ_OK: + case AUTH_REQ_OK: break; case AUTH_REQ_KRB4: diff --git a/src/interfaces/libpq/fe-connect.c b/src/interfaces/libpq/fe-connect.c index df572884ebf..c400a7ebb16 100644 --- a/src/interfaces/libpq/fe-connect.c +++ b/src/interfaces/libpq/fe-connect.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.125 2000/03/24 01:39:55 tgl Exp $ + * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.126 2000/04/12 17:17:14 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -46,18 +46,23 @@ #endif #ifdef WIN32 -static int inet_aton(const char *cp, struct in_addr *inp) { +static int +inet_aton(const char *cp, struct in_addr * inp) +{ unsigned long a = inet_addr(cp); + if (a == -1) return 0; - inp->s_addr = a; + inp->s_addr = a; return 1; } + #endif #ifdef USE_SSL static SSL_CTX *SSL_context = NULL; + #endif #define NOTIFYLIST_INITIAL_SIZE 10 @@ -85,15 +90,17 @@ static SSL_CTX *SSL_context = NULL; * * PQconninfoOptions[] is a constant static array that we use to initialize * a dynamically allocated working copy. All the "val" fields in - * PQconninfoOptions[] *must* be NULL. In a working copy, non-null "val" + * PQconninfoOptions[] *must* be NULL. In a working copy, non-null "val" * fields point to malloc'd strings that should be freed when the working * array is freed (see PQconninfoFree). * ---------- */ static const PQconninfoOption PQconninfoOptions[] = { - /* "authtype" is no longer used, so mark it "don't show". We keep it - * in the array so as not to reject conninfo strings from old apps that - * might still try to set it. + + /* + * "authtype" is no longer used, so mark it "don't show". We keep it + * in the array so as not to reject conninfo strings from old apps + * that might still try to set it. */ {"authtype", "PGAUTHTYPE", DefaultAuthtype, NULL, "Database-Authtype", "D", 20}, @@ -111,7 +118,8 @@ static const PQconninfoOption PQconninfoOptions[] = { "Database-Host", "", 40}, {"hostaddr", "PGHOSTADDR", NULL, NULL, - "Database-Host-IPv4-Address", "", 15}, /* Room for abc.def.ghi.jkl */ + "Database-Host-IPv4-Address", "", 15}, /* Room for + * abc.def.ghi.jkl */ {"port", "PGPORT", DEF_PGPORT, NULL, "Database-Port", "", 6}, @@ -156,22 +164,22 @@ static const struct EnvironmentOptions }; -static int connectDBStart(PGconn *conn); -static int connectDBComplete(PGconn *conn); +static int connectDBStart(PGconn *conn); +static int connectDBComplete(PGconn *conn); static bool PQsetenvStart(PGconn *conn); static PostgresPollingStatusType PQsetenvPoll(PGconn *conn); static PGconn *makeEmptyPGconn(void); static void freePGconn(PGconn *conn); static void closePGconn(PGconn *conn); static PQconninfoOption *conninfo_parse(const char *conninfo, - PQExpBuffer errorMessage); + PQExpBuffer errorMessage); static char *conninfo_getval(PQconninfoOption *connOptions, - const char *keyword); + const char *keyword); static void defaultNoticeProcessor(void *arg, const char *message); /* ---------------- - * Connecting to a Database + * Connecting to a Database * * There are now four different ways a user of this API can connect to the * database. Two are not recommended for use in new code, because of their @@ -187,7 +195,7 @@ static void defaultNoticeProcessor(void *arg, const char *message); * * Internally, the static functions connectDBStart, connectDBComplete * are part of the connection procedure. - * + * * ---------------- */ @@ -218,7 +226,7 @@ static void defaultNoticeProcessor(void *arg, const char *message); PGconn * PQconnectdb(const char *conninfo) { - PGconn *conn = PQconnectStart(conninfo); + PGconn *conn = PQconnectStart(conninfo); if (conn && conn->status != CONNECTION_BAD) (void) connectDBComplete(conn); @@ -235,7 +243,7 @@ PQconnectdb(const char *conninfo) * See comment for PQconnectdb for the definition of the string format. * * Returns a PGconn*. If NULL is returned, a malloc error has occurred, and - * you should not attempt to proceed with this connection. If the status + * you should not attempt to proceed with this connection. If the status * field of the connection returned is CONNECTION_BAD, an error has * occurred. In this case you should call PQfinish on the result, (perhaps * inspecting the error message first). Other fields of the structure may not @@ -258,7 +266,7 @@ PQconnectStart(const char *conninfo) * Allocate memory for the conn structure * ---------- */ - + conn = makeEmptyPGconn(); if (conn == NULL) return (PGconn *) NULL; @@ -324,7 +332,7 @@ PQconnectStart(const char *conninfo) * and their current default values. * * NOTE: as of PostgreSQL 7.0, the returned array is dynamically allocated - * and should be freed when no longer needed via PQconninfoFree(). (In prior + * and should be freed when no longer needed via PQconninfoFree(). (In prior * versions, the returned array was static, but that's not thread-safe.) * Pre-7.0 applications that use this function will see a small memory leak * until they are updated to call PQconninfoFree. @@ -333,7 +341,7 @@ PQconnectStart(const char *conninfo) PQconninfoOption * PQconndefaults(void) { - PQExpBufferData errorBuf; + PQExpBufferData errorBuf; PQconninfoOption *connOptions; initPQExpBuffer(&errorBuf); @@ -388,7 +396,8 @@ PQsetdbLogin(const char *pghost, const char *pgport, const char *pgoptions, const char *pwd) { PGconn *conn; - char *tmp; /* An error message from some service we call. */ + char *tmp; /* An error message from some service we + * call. */ bool error = FALSE; /* We encountered an error. */ conn = makeEmptyPGconn(); @@ -466,15 +475,13 @@ PQsetdbLogin(const char *pghost, const char *pgport, const char *pgoptions, conn->dbName = strdup(dbName); if (error) - { conn->status = CONNECTION_BAD; - } else { if (connectDBStart(conn)) (void) connectDBComplete(conn); } - + return conn; } @@ -595,12 +602,13 @@ connectMakeNonblocking(PGconn *conn) #ifndef WIN32 if (fcntl(conn->sock, F_SETFL, O_NONBLOCK) < 0) #else - int on = 1; + int on = 1; + if (ioctlsocket(conn->sock, FIONBIO, &on) != 0) #endif { printfPQExpBuffer(&conn->errorMessage, - "connectMakeNonblocking -- fcntl() failed: errno=%d\n%s\n", + "connectMakeNonblocking -- fcntl() failed: errno=%d\n%s\n", errno, strerror(errno)); return 0; } @@ -637,7 +645,7 @@ connectNoDelay(PGconn *conn) sizeof(on)) < 0) { printfPQExpBuffer(&conn->errorMessage, - "connectNoDelay() -- setsockopt failed: errno=%d\n%s\n", + "connectNoDelay() -- setsockopt failed: errno=%d\n%s\n", errno, strerror(errno)); #ifdef WIN32 printf("Winsock error: %i\n", WSAGetLastError()); @@ -661,13 +669,16 @@ connectDBStart(PGconn *conn) { int portno, family; + #ifdef USE_SSL - StartupPacket np; /* Used to negotiate SSL connection */ - char SSLok; + StartupPacket np; /* Used to negotiate SSL connection */ + char SSLok; + #endif if (!conn) return 0; + /* * parse dbName to get all additional info in it, if any */ @@ -679,8 +690,8 @@ connectDBStart(PGconn *conn) conn->outCount = 0; /* - * Set up the connection to postmaster/backend. - * Note that this supports IPv4 and UDP only. + * Set up the connection to postmaster/backend. Note that this + * supports IPv4 and UDP only. */ MemSet((char *) &conn->raddr, 0, sizeof(conn->raddr)); @@ -691,11 +702,11 @@ connectDBStart(PGconn *conn) /* Note that this supports IPv4 only */ struct in_addr addr; - if(!inet_aton(conn->pghostaddr, &addr)) + if (!inet_aton(conn->pghostaddr, &addr)) { printfPQExpBuffer(&conn->errorMessage, "connectDBStart() -- " - "invalid host address: %s\n", conn->pghostaddr); + "invalid host address: %s\n", conn->pghostaddr); goto connect_errReturn; } @@ -713,7 +724,7 @@ connectDBStart(PGconn *conn) if ((hp == NULL) || (hp->h_addrtype != AF_INET)) { printfPQExpBuffer(&conn->errorMessage, - "connectDBStart() -- unknown hostname: %s\n", + "connectDBStart() -- unknown hostname: %s\n", conn->pghost); goto connect_errReturn; } @@ -740,8 +751,8 @@ connectDBStart(PGconn *conn) conn->raddr_len = sizeof(struct sockaddr_in); } #if !defined(WIN32) && !defined(__CYGWIN32__) - else - conn->raddr_len = UNIXSOCK_PATH(conn->raddr.un, portno); + else + conn->raddr_len = UNIXSOCK_PATH(conn->raddr.un, portno); #endif @@ -775,82 +786,91 @@ connectDBStart(PGconn *conn) * WIN32_NON_BLOCKING_CONNECTIONS before compilation. If it works, then * this code can be cleaned up. * - * Ewan Mellor <eem21@cam.ac.uk>. + * Ewan Mellor <eem21@cam.ac.uk>. * ---------- */ #if (!defined(WIN32) || defined(WIN32_NON_BLOCKING_CONNECTIONS)) && !defined(USE_SSL) if (connectMakeNonblocking(conn) == 0) goto connect_errReturn; -#endif +#endif #ifdef USE_SSL - /* This needs to be done before we set into nonblocking, since SSL - * negotiation does not like that mode */ + + /* + * This needs to be done before we set into nonblocking, since SSL + * negotiation does not like that mode + */ /* Attempt to negotiate SSL usage */ - if (conn->allow_ssl_try) { - memset((char *)&np, 0, sizeof(np)); - np.protoVersion = htonl(NEGOTIATE_SSL_CODE); - if (pqPacketSend(conn, (char *) &np, sizeof(StartupPacket)) != STATUS_OK) - { - sprintf(conn->errorMessage, - "connectDB() -- couldn't send SSL negotiation packet: errno=%d\n%s\n", - errno, strerror(errno)); - goto connect_errReturn; - } - /* Now receive the postmasters response */ - if (recv(conn->sock, &SSLok, 1, 0) != 1) { - sprintf(conn->errorMessage, "PQconnectDB() -- couldn't read postmaster response: errno=%d\n%s\n", - errno, strerror(errno)); - goto connect_errReturn; - } - if (SSLok == 'S') { - if (!SSL_context) - { - SSL_load_error_strings(); - SSL_library_init(); - SSL_context = SSL_CTX_new(SSLv23_method()); - if (!SSL_context) { - sprintf(conn->errorMessage, - "connectDB() -- couldn't create SSL context: %s\n", - ERR_reason_error_string(ERR_get_error())); - goto connect_errReturn; + if (conn->allow_ssl_try) + { + memset((char *) &np, 0, sizeof(np)); + np.protoVersion = htonl(NEGOTIATE_SSL_CODE); + if (pqPacketSend(conn, (char *) &np, sizeof(StartupPacket)) != STATUS_OK) + { + sprintf(conn->errorMessage, + "connectDB() -- couldn't send SSL negotiation packet: errno=%d\n%s\n", + errno, strerror(errno)); + goto connect_errReturn; + } + /* Now receive the postmasters response */ + if (recv(conn->sock, &SSLok, 1, 0) != 1) + { + sprintf(conn->errorMessage, "PQconnectDB() -- couldn't read postmaster response: errno=%d\n%s\n", + errno, strerror(errno)); + goto connect_errReturn; + } + if (SSLok == 'S') + { + if (!SSL_context) + { + SSL_load_error_strings(); + SSL_library_init(); + SSL_context = SSL_CTX_new(SSLv23_method()); + if (!SSL_context) + { + sprintf(conn->errorMessage, + "connectDB() -- couldn't create SSL context: %s\n", + ERR_reason_error_string(ERR_get_error())); + goto connect_errReturn; + } + } + if (!(conn->ssl = SSL_new(SSL_context)) || + !SSL_set_fd(conn->ssl, conn->sock) || + SSL_connect(conn->ssl) <= 0) + { + sprintf(conn->errorMessage, + "connectDB() -- couldn't establish SSL connection: %s\n", + ERR_reason_error_string(ERR_get_error())); + goto connect_errReturn; + } + /* SSL connection finished. Continue to send startup packet */ + } + else if (SSLok == 'E') + { + /* Received error - probably protocol mismatch */ + if (conn->Pfdebug) + fprintf(conn->Pfdebug, "Postmaster reports error, attempting fallback to pre-6.6.\n"); + close(conn->sock); + conn->allow_ssl_try = FALSE; + return connectDBStart(conn); + } + else if (SSLok != 'N') + { + strcpy(conn->errorMessage, + "Received invalid negotiation response.\n"); + goto connect_errReturn; } - } - if (!(conn->ssl = SSL_new(SSL_context)) || - !SSL_set_fd(conn->ssl, conn->sock) || - SSL_connect(conn->ssl) <= 0) - { - sprintf(conn->errorMessage, - "connectDB() -- couldn't establish SSL connection: %s\n", - ERR_reason_error_string(ERR_get_error())); - goto connect_errReturn; - } - /* SSL connection finished. Continue to send startup packet */ - } - else if (SSLok == 'E') { - /* Received error - probably protocol mismatch */ - if (conn->Pfdebug) - fprintf(conn->Pfdebug, "Postmaster reports error, attempting fallback to pre-6.6.\n"); - close(conn->sock); - conn->allow_ssl_try = FALSE; - return connectDBStart(conn); - } - else if (SSLok != 'N') { - strcpy(conn->errorMessage, - "Received invalid negotiation response.\n"); - goto connect_errReturn; - } } #endif /* ---------- - * Start / make connection. We are hopefully in non-blocking mode + * Start / make connection. We are hopefully in non-blocking mode * now, but it is possible that: - * 1. Older systems will still block on connect, despite the - * non-blocking flag. (Anyone know if this is true?) - * 2. We are running under Windows, and aren't even trying - * to be non-blocking (see above). - * 3. We are using SSL. + * 1. Older systems will still block on connect, despite the + * non-blocking flag. (Anyone know if this is true?) + * 2. We are running under Windows, and aren't even trying + * to be non-blocking (see above). + * 3. We are using SSL. * Thus, we have make arrangements for all eventualities. * ---------- */ @@ -862,8 +882,11 @@ connectDBStart(PGconn *conn) if (WSAGetLastError() == WSAEINPROGRESS) #endif { - /* This is fine - we're in non-blocking mode, and the - * connection is in progress. */ + + /* + * This is fine - we're in non-blocking mode, and the + * connection is in progress. + */ conn->status = CONNECTION_STARTED; } else @@ -888,12 +911,14 @@ connectDBStart(PGconn *conn) conn->status = CONNECTION_MADE; } - /* This makes the connection non-blocking, for all those cases which forced us - not to do it above. */ + /* + * This makes the connection non-blocking, for all those cases which + * forced us not to do it above. + */ #if (defined(WIN32) && !defined(WIN32_NON_BLOCKING_CONNECTIONS)) || defined(USE_SSL) if (connectMakeNonblocking(conn) == 0) goto connect_errReturn; -#endif +#endif return 1; @@ -929,10 +954,13 @@ connectDBComplete(PGconn *conn) if (conn == NULL || conn->status == CONNECTION_BAD) return 0; - for (;;) { + for (;;) + { + /* - * Wait, if necessary. Note that the initial state (just after - * PQconnectStart) is to wait for the socket to select for writing. + * Wait, if necessary. Note that the initial state (just after + * PQconnectStart) is to wait for the socket to select for + * writing. */ switch (flag) { @@ -941,7 +969,7 @@ connectDBComplete(PGconn *conn) case PGRES_POLLING_OK: return 1; /* success! */ - + case PGRES_POLLING_READING: if (pqWait(1, 0, conn)) { @@ -963,6 +991,7 @@ connectDBComplete(PGconn *conn) conn->status = CONNECTION_BAD; return 0; } + /* * Now try to advance the state machine. */ @@ -977,23 +1006,23 @@ connectDBComplete(PGconn *conn) * * Returns a PostgresPollingStatusType. * Before calling this function, use select(2) to determine when data arrive. - * + * * You must call PQfinish whether or not this fails. * * This function and PQconnectStart are intended to allow connections to be * made without blocking the execution of your program on remote I/O. However, * there are a number of caveats: * - * o If you call PQtrace, ensure that the stream object into which you trace - * will not block. - * o If you do not supply an IP address for the remote host (i.e. you - * supply a host name instead) then this function will block on - * gethostbyname. You will be fine if using Unix sockets (i.e. by - * supplying neither a host name nor a host address). - * o If your backend wants to use Kerberos authentication then you must - * supply both a host name and a host address, otherwise this function - * may block on gethostname. - * o This function will block if compiled with USE_SSL. + * o If you call PQtrace, ensure that the stream object into which you trace + * will not block. + * o If you do not supply an IP address for the remote host (i.e. you + * supply a host name instead) then this function will block on + * gethostbyname. You will be fine if using Unix sockets (i.e. by + * supplying neither a host name nor a host address). + * o If your backend wants to use Kerberos authentication then you must + * supply both a host name and a host address, otherwise this function + * may block on gethostname. + * o This function will block if compiled with USE_SSL. * * ---------------- */ @@ -1008,32 +1037,35 @@ PQconnectPoll(PGconn *conn) /* Get the new data */ switch (conn->status) { - /* We really shouldn't have been polled in these two cases, but - we can handle it. */ + + /* + * We really shouldn't have been polled in these two cases, + * but we can handle it. + */ case CONNECTION_BAD: return PGRES_POLLING_FAILED; case CONNECTION_OK: return PGRES_POLLING_OK; - /* These are reading states */ + /* These are reading states */ case CONNECTION_AWAITING_RESPONSE: case CONNECTION_AUTH_OK: - { - /* Load waiting data */ - int n = pqReadData(conn); - - if (n < 0) - goto error_return; - if (n == 0) - return PGRES_POLLING_READING; + { + /* Load waiting data */ + int n = pqReadData(conn); - break; - } + if (n < 0) + goto error_return; + if (n == 0) + return PGRES_POLLING_READING; + + break; + } - /* These are writing states, so we just proceed. */ + /* These are writing states, so we just proceed. */ case CONNECTION_STARTED: case CONNECTION_MADE: - break; + break; case CONNECTION_SETENV: /* We allow PQsetenvPoll to decide whether to proceed */ @@ -1041,281 +1073,319 @@ PQconnectPoll(PGconn *conn) default: printfPQExpBuffer(&conn->errorMessage, - "PQconnectPoll() -- unknown connection state - " - "probably indicative of memory corruption!\n"); + "PQconnectPoll() -- unknown connection state - " + "probably indicative of memory corruption!\n"); goto error_return; } - keep_going: /* We will come back to here until there is nothing left to - parse. */ - switch(conn->status) +keep_going: /* We will come back to here until there + * is nothing left to parse. */ + switch (conn->status) { case CONNECTION_STARTED: - { - SOCKET_SIZE_TYPE laddrlen; + { + SOCKET_SIZE_TYPE laddrlen; + #ifndef WIN32 - int optval; + int optval; + #else - char optval; -#endif - SOCKET_SIZE_TYPE optlen = sizeof(optval); + char optval; - /* Write ready, since we've made it here, so the connection - * has been made. */ +#endif + SOCKET_SIZE_TYPE optlen = sizeof(optval); - /* Now check (using getsockopt) that there is not an error - state waiting for us on the socket. */ + /* + * Write ready, since we've made it here, so the + * connection has been made. + */ - if (getsockopt(conn->sock, SOL_SOCKET, SO_ERROR, - &optval, &optlen) == -1) - { - printfPQExpBuffer(&conn->errorMessage, - "PQconnectPoll() -- getsockopt() failed: " - "errno=%d\n%s\n", - errno, strerror(errno)); - goto error_return; - } - else if (optval != 0) - { /* - * When using a nonblocking connect, we will typically see - * connect failures at this point, so provide a friendly - * error message. + * Now check (using getsockopt) that there is not an error + * state waiting for us on the socket. */ - printfPQExpBuffer(&conn->errorMessage, - "PQconnectPoll() -- connect() failed: %s\n" - "\tIs the postmaster running%s at '%s'\n" - "\tand accepting connections on %s '%s'?\n", - strerror(optval), - (conn->raddr.sa.sa_family == AF_INET) ? " (with -i)" : "", - conn->pghost ? conn->pghost : "localhost", + + if (getsockopt(conn->sock, SOL_SOCKET, SO_ERROR, + &optval, &optlen) == -1) + { + printfPQExpBuffer(&conn->errorMessage, + "PQconnectPoll() -- getsockopt() failed: " + "errno=%d\n%s\n", + errno, strerror(errno)); + goto error_return; + } + else if (optval != 0) + { + + /* + * When using a nonblocking connect, we will typically + * see connect failures at this point, so provide a + * friendly error message. + */ + printfPQExpBuffer(&conn->errorMessage, + "PQconnectPoll() -- connect() failed: %s\n" + "\tIs the postmaster running%s at '%s'\n" + "\tand accepting connections on %s '%s'?\n", + strerror(optval), + (conn->raddr.sa.sa_family == AF_INET) ? " (with -i)" : "", + conn->pghost ? conn->pghost : "localhost", (conn->raddr.sa.sa_family == AF_INET) ? - "TCP/IP port" : "Unix socket", - conn->pgport); - goto error_return; + "TCP/IP port" : "Unix socket", + conn->pgport); + goto error_return; + } + + /* Fill in the client address */ + laddrlen = sizeof(conn->laddr); + if (getsockname(conn->sock, &conn->laddr.sa, &laddrlen) < 0) + { + printfPQExpBuffer(&conn->errorMessage, + "PQconnectPoll() -- getsockname() failed: " + "errno=%d\n%s\n", + errno, strerror(errno)); + goto error_return; + } + + conn->status = CONNECTION_MADE; + return PGRES_POLLING_WRITING; } - /* Fill in the client address */ - laddrlen = sizeof(conn->laddr); - if (getsockname(conn->sock, &conn->laddr.sa, &laddrlen) < 0) + case CONNECTION_MADE: { - printfPQExpBuffer(&conn->errorMessage, - "PQconnectPoll() -- getsockname() failed: " - "errno=%d\n%s\n", - errno, strerror(errno)); - goto error_return; - } + StartupPacket sp; - conn->status = CONNECTION_MADE; - return PGRES_POLLING_WRITING; - } + /* + * Initialize the startup packet. + */ - case CONNECTION_MADE: - { - StartupPacket sp; - - /* - * Initialize the startup packet. - */ + MemSet((char *) &sp, 0, sizeof(StartupPacket)); - MemSet((char *) &sp, 0, sizeof(StartupPacket)); - - sp.protoVersion = (ProtocolVersion) htonl(PG_PROTOCOL_LIBPQ); - - strncpy(sp.user, conn->pguser, SM_USER); - strncpy(sp.database, conn->dbName, SM_DATABASE); - strncpy(sp.tty, conn->pgtty, SM_TTY); - - if (conn->pgoptions) - strncpy(sp.options, conn->pgoptions, SM_OPTIONS); - - /* Send the startup packet. - * - * Theoretically, this could block, but it really shouldn't - * since we only got here if the socket is write-ready. - */ + sp.protoVersion = (ProtocolVersion) htonl(PG_PROTOCOL_LIBPQ); - if (pqPacketSend(conn, (char *) &sp, - sizeof(StartupPacket)) != STATUS_OK) - { - printfPQExpBuffer(&conn->errorMessage, - "PQconnectPoll() -- " - "couldn't send startup packet: " - "errno=%d\n%s\n", - errno, strerror(errno)); - goto error_return; - } + strncpy(sp.user, conn->pguser, SM_USER); + strncpy(sp.database, conn->dbName, SM_DATABASE); + strncpy(sp.tty, conn->pgtty, SM_TTY); - conn->status = CONNECTION_AWAITING_RESPONSE; - return PGRES_POLLING_READING; - } + if (conn->pgoptions) + strncpy(sp.options, conn->pgoptions, SM_OPTIONS); - /* - * Handle the authentication exchange: wait for postmaster messages - * and respond as necessary. - */ - case CONNECTION_AWAITING_RESPONSE: - { - char beresp; - AuthRequest areq; + /* + * Send the startup packet. + * + * Theoretically, this could block, but it really shouldn't + * since we only got here if the socket is write-ready. + */ - /* Scan the message from current point (note that if we find - * the message is incomplete, we will return without advancing - * inStart, and resume here next time). - */ - conn->inCursor = conn->inStart; + if (pqPacketSend(conn, (char *) &sp, + sizeof(StartupPacket)) != STATUS_OK) + { + printfPQExpBuffer(&conn->errorMessage, + "PQconnectPoll() -- " + "couldn't send startup packet: " + "errno=%d\n%s\n", + errno, strerror(errno)); + goto error_return; + } - if (pqGetc(&beresp, conn)) - { - /* We'll come back when there are more data */ + conn->status = CONNECTION_AWAITING_RESPONSE; return PGRES_POLLING_READING; } - /* Handle errors. */ - if (beresp == 'E') + /* + * Handle the authentication exchange: wait for postmaster + * messages and respond as necessary. + */ + case CONNECTION_AWAITING_RESPONSE: { - if (pqGets(&conn->errorMessage, conn)) + char beresp; + AuthRequest areq; + + /* + * Scan the message from current point (note that if we + * find the message is incomplete, we will return without + * advancing inStart, and resume here next time). + */ + conn->inCursor = conn->inStart; + + if (pqGetc(&beresp, conn)) { /* We'll come back when there are more data */ return PGRES_POLLING_READING; } - /* OK, we read the message; mark data consumed */ - conn->inStart = conn->inCursor; - /* The postmaster typically won't end its message with a - * newline, so add one to conform to libpq conventions. - */ - appendPQExpBufferChar(&conn->errorMessage, '\n'); - goto error_return; - } - /* Otherwise it should be an authentication request. */ - if (beresp != 'R') - { - printfPQExpBuffer(&conn->errorMessage, - "PQconnectPoll() -- expected " - "authentication request\n"); - goto error_return; - } + /* Handle errors. */ + if (beresp == 'E') + { + if (pqGets(&conn->errorMessage, conn)) + { + /* We'll come back when there are more data */ + return PGRES_POLLING_READING; + } + /* OK, we read the message; mark data consumed */ + conn->inStart = conn->inCursor; + + /* + * The postmaster typically won't end its message with + * a newline, so add one to conform to libpq + * conventions. + */ + appendPQExpBufferChar(&conn->errorMessage, '\n'); + goto error_return; + } - /* Get the type of request. */ - if (pqGetInt((int *) &areq, 4, conn)) - { - /* We'll come back when there are more data */ - return PGRES_POLLING_READING; - } + /* Otherwise it should be an authentication request. */ + if (beresp != 'R') + { + printfPQExpBuffer(&conn->errorMessage, + "PQconnectPoll() -- expected " + "authentication request\n"); + goto error_return; + } - /* Get the password salt if there is one. */ - if (areq == AUTH_REQ_CRYPT) - { - if (pqGetnchar(conn->salt, sizeof(conn->salt), conn)) + /* Get the type of request. */ + if (pqGetInt((int *) &areq, 4, conn)) { /* We'll come back when there are more data */ return PGRES_POLLING_READING; } - } - /* OK, we successfully read the message; mark data consumed */ - conn->inStart = conn->inCursor; + /* Get the password salt if there is one. */ + if (areq == AUTH_REQ_CRYPT) + { + if (pqGetnchar(conn->salt, sizeof(conn->salt), conn)) + { + /* We'll come back when there are more data */ + return PGRES_POLLING_READING; + } + } + + /* + * OK, we successfully read the message; mark data + * consumed + */ + conn->inStart = conn->inCursor; - /* Respond to the request if necessary. */ - /* Note that conn->pghost must be non-NULL if we are going to - * avoid the Kerberos code doing a hostname look-up. */ - /* XXX fe-auth.c has not been fixed to support PQExpBuffers, so: */ - if (fe_sendauth(areq, conn, conn->pghost, conn->pgpass, - conn->errorMessage.data) != STATUS_OK) - { + /* Respond to the request if necessary. */ + + /* + * Note that conn->pghost must be non-NULL if we are going + * to avoid the Kerberos code doing a hostname look-up. + */ + + /* + * XXX fe-auth.c has not been fixed to support + * PQExpBuffers, so: + */ + if (fe_sendauth(areq, conn, conn->pghost, conn->pgpass, + conn->errorMessage.data) != STATUS_OK) + { + conn->errorMessage.len = strlen(conn->errorMessage.data); + goto error_return; + } conn->errorMessage.len = strlen(conn->errorMessage.data); - goto error_return; - } - conn->errorMessage.len = strlen(conn->errorMessage.data); - /* Just make sure that any data sent by fe_sendauth is flushed - * out. Although this theoretically could block, it really - * shouldn't since we don't send large auth responses. - */ - if (pqFlush(conn)) - goto error_return; + /* + * Just make sure that any data sent by fe_sendauth is + * flushed out. Although this theoretically could block, + * it really shouldn't since we don't send large auth + * responses. + */ + if (pqFlush(conn)) + goto error_return; - if (areq == AUTH_REQ_OK) - { - /* We are done with authentication exchange */ - conn->status = CONNECTION_AUTH_OK; - /* Set asyncStatus so that PQsetResult will think that what - * comes back next is the result of a query. See below. */ - conn->asyncStatus = PGASYNC_BUSY; - } + if (areq == AUTH_REQ_OK) + { + /* We are done with authentication exchange */ + conn->status = CONNECTION_AUTH_OK; + + /* + * Set asyncStatus so that PQsetResult will think that + * what comes back next is the result of a query. See + * below. + */ + conn->asyncStatus = PGASYNC_BUSY; + } - /* Look to see if we have more data yet. */ - goto keep_going; - } + /* Look to see if we have more data yet. */ + goto keep_going; + } case CONNECTION_AUTH_OK: - { - /* ---------- - * Now we expect to hear from the backend. A ReadyForQuery - * message indicates that startup is successful, but we might - * also get an Error message indicating failure. (Notice - * messages indicating nonfatal warnings are also allowed by - * the protocol, as is a BackendKeyData message.) Easiest way - * to handle this is to let PQgetResult() read the messages. We - * just have to fake it out about the state of the connection, - * by setting asyncStatus = PGASYNC_BUSY (done above). - *---------- - */ - - if (PQisBusy(conn)) - return PGRES_POLLING_READING; - - res = PQgetResult(conn); - /* NULL return indicating we have gone to - IDLE state is expected */ - if (res) { - if (res->resultStatus != PGRES_FATAL_ERROR) - printfPQExpBuffer(&conn->errorMessage, - "PQconnectPoll() -- unexpected message " - "during startup\n"); - /* if the resultStatus is FATAL, then conn->errorMessage - * already has a copy of the error; needn't copy it back. - * But add a newline if it's not there already, since - * postmaster error messages may not have one. + /* ---------- + * Now we expect to hear from the backend. A ReadyForQuery + * message indicates that startup is successful, but we might + * also get an Error message indicating failure. (Notice + * messages indicating nonfatal warnings are also allowed by + * the protocol, as is a BackendKeyData message.) Easiest way + * to handle this is to let PQgetResult() read the messages. We + * just have to fake it out about the state of the connection, + * by setting asyncStatus = PGASYNC_BUSY (done above). + *---------- */ - if (conn->errorMessage.len <= 0 || - conn->errorMessage.data[conn->errorMessage.len-1] != '\n') - appendPQExpBufferChar(&conn->errorMessage, '\n'); - PQclear(res); - goto error_return; - } - /* - * Post-connection housekeeping. Prepare to send environment - * variables to server. - */ - if (! PQsetenvStart(conn)) - goto error_return; + if (PQisBusy(conn)) + return PGRES_POLLING_READING; - conn->status = CONNECTION_SETENV; + res = PQgetResult(conn); - goto keep_going; - } + /* + * NULL return indicating we have gone to IDLE state is + * expected + */ + if (res) + { + if (res->resultStatus != PGRES_FATAL_ERROR) + printfPQExpBuffer(&conn->errorMessage, + "PQconnectPoll() -- unexpected message " + "during startup\n"); + + /* + * if the resultStatus is FATAL, then + * conn->errorMessage already has a copy of the error; + * needn't copy it back. But add a newline if it's not + * there already, since postmaster error messages may + * not have one. + */ + if (conn->errorMessage.len <= 0 || + conn->errorMessage.data[conn->errorMessage.len - 1] != '\n') + appendPQExpBufferChar(&conn->errorMessage, '\n'); + PQclear(res); + goto error_return; + } + + /* + * Post-connection housekeeping. Prepare to send + * environment variables to server. + */ + if (!PQsetenvStart(conn)) + goto error_return; + + conn->status = CONNECTION_SETENV; + + goto keep_going; + } case CONNECTION_SETENV: - /* We pretend that the connection is OK for the duration of - these queries. */ + + /* + * We pretend that the connection is OK for the duration of + * these queries. + */ conn->status = CONNECTION_OK; switch (PQsetenvPoll(conn)) { - case PGRES_POLLING_OK: /* Success */ + case PGRES_POLLING_OK: /* Success */ conn->status = CONNECTION_OK; return PGRES_POLLING_OK; - case PGRES_POLLING_READING: /* Still going */ + case PGRES_POLLING_READING: /* Still going */ conn->status = CONNECTION_SETENV; return PGRES_POLLING_READING; - case PGRES_POLLING_WRITING: /* Still going */ + case PGRES_POLLING_WRITING: /* Still going */ conn->status = CONNECTION_SETENV; return PGRES_POLLING_WRITING; @@ -1327,8 +1397,8 @@ PQconnectPoll(PGconn *conn) default: printfPQExpBuffer(&conn->errorMessage, - "PQconnectPoll() -- unknown connection state - " - "probably indicative of memory corruption!\n"); + "PQconnectPoll() -- unknown connection state - " + "probably indicative of memory corruption!\n"); goto error_return; } @@ -1368,7 +1438,7 @@ PQsetenvStart(PGconn *conn) #else conn->setenv_state = SETENV_STATE_OPTION_SEND; #endif - + conn->next_eo = EnvironmentOptions; return true; @@ -1386,8 +1456,10 @@ static PostgresPollingStatusType PQsetenvPoll(PGconn *conn) { PGresult *res; + #ifdef MULTIBYTE static const char envname[] = "PGCLIENTENCODING"; + #endif if (conn == NULL || conn->status == CONNECTION_BAD) @@ -1396,168 +1468,175 @@ PQsetenvPoll(PGconn *conn) /* Check whether there are any data for us */ switch (conn->setenv_state) { - /* These are reading states */ + /* These are reading states */ #ifdef MULTIBYTE case SETENV_STATE_ENCODINGS_WAIT: #endif case SETENV_STATE_OPTION_WAIT: - { - /* Load waiting data */ - int n = pqReadData(conn); - - if (n < 0) - goto error_return; - if (n == 0) - return PGRES_POLLING_READING; + { + /* Load waiting data */ + int n = pqReadData(conn); - break; - } + if (n < 0) + goto error_return; + if (n == 0) + return PGRES_POLLING_READING; - /* These are writing states, so we just proceed. */ + break; + } + + /* These are writing states, so we just proceed. */ #ifdef MULTIBYTE case SETENV_STATE_ENCODINGS_SEND: #endif case SETENV_STATE_OPTION_SEND: break; - /* Should we raise an error if called when not active? */ + /* Should we raise an error if called when not active? */ case SETENV_STATE_IDLE: return PGRES_POLLING_OK; default: printfPQExpBuffer(&conn->errorMessage, "PQsetenvPoll() -- unknown state - " - "probably indicative of memory corruption!\n"); + "probably indicative of memory corruption!\n"); goto error_return; } - keep_going: /* We will come back to here until there is nothing left to - parse. */ - switch(conn->setenv_state) +keep_going: /* We will come back to here until there + * is nothing left to parse. */ + switch (conn->setenv_state) { #ifdef MULTIBYTE case SETENV_STATE_ENCODINGS_SEND: - { - const char *env; - - /* query server encoding */ - env = getenv(envname); - if (!env || *env == '\0') { - if (!PQsendQuery(conn, - "select getdatabaseencoding()")) - goto error_return; + const char *env; - conn->setenv_state = SETENV_STATE_ENCODINGS_WAIT; - return PGRES_POLLING_READING; + /* query server encoding */ + env = getenv(envname); + if (!env || *env == '\0') + { + if (!PQsendQuery(conn, + "select getdatabaseencoding()")) + goto error_return; + + conn->setenv_state = SETENV_STATE_ENCODINGS_WAIT; + return PGRES_POLLING_READING; + } } - } case SETENV_STATE_ENCODINGS_WAIT: - { - if (PQisBusy(conn)) - return PGRES_POLLING_READING; - - res = PQgetResult(conn); - - if (res) { - char *encoding; + if (PQisBusy(conn)) + return PGRES_POLLING_READING; + + res = PQgetResult(conn); - if (PQresultStatus(res) != PGRES_TUPLES_OK) + if (res) { + char *encoding; + + if (PQresultStatus(res) != PGRES_TUPLES_OK) + { + PQclear(res); + goto error_return; + } + + /* set client encoding in pg_conn struct */ + encoding = PQgetvalue(res, 0, 0); + if (!encoding) /* this should not happen */ + conn->client_encoding = SQL_ASCII; + else + conn->client_encoding = pg_char_to_encoding(encoding); PQclear(res); - goto error_return; + + /* + * We have to keep going in order to clear up the + * query + */ + goto keep_going; } - /* set client encoding in pg_conn struct */ - encoding = PQgetvalue(res, 0, 0); - if (!encoding) /* this should not happen */ - conn->client_encoding = SQL_ASCII; - else - conn->client_encoding = pg_char_to_encoding(encoding); - PQclear(res); - /* We have to keep going in order to clear up the query */ + /* NULL result indicates that the query is finished */ + + /* Move on to setting the environment options */ + conn->setenv_state = SETENV_STATE_OPTION_SEND; goto keep_going; } - - /* NULL result indicates that the query is finished */ - - /* Move on to setting the environment options */ - conn->setenv_state = SETENV_STATE_OPTION_SEND; - goto keep_going; - } #endif case SETENV_STATE_OPTION_SEND: - { - /* Send an Environment Option */ - char setQuery[100]; /* note length limits in sprintf's below */ - - if (conn->next_eo->envName) { - const char *val; + /* Send an Environment Option */ + char setQuery[100]; /* note length limits in + * sprintf's below */ - if ((val = getenv(conn->next_eo->envName))) + if (conn->next_eo->envName) { - if (strcasecmp(val, "default") == 0) - sprintf(setQuery, "SET %s = %.60s", - conn->next_eo->pgName, val); - else - sprintf(setQuery, "SET %s = '%.60s'", - conn->next_eo->pgName, val); + const char *val; + + if ((val = getenv(conn->next_eo->envName))) + { + if (strcasecmp(val, "default") == 0) + sprintf(setQuery, "SET %s = %.60s", + conn->next_eo->pgName, val); + else + sprintf(setQuery, "SET %s = '%.60s'", + conn->next_eo->pgName, val); #ifdef CONNECTDEBUG - printf("Use environment variable %s to send %s\n", - conn->next_eo->envName, setQuery); + printf("Use environment variable %s to send %s\n", + conn->next_eo->envName, setQuery); #endif - if (!PQsendQuery(conn, setQuery)) - goto error_return; + if (!PQsendQuery(conn, setQuery)) + goto error_return; - conn->setenv_state = SETENV_STATE_OPTION_WAIT; + conn->setenv_state = SETENV_STATE_OPTION_WAIT; + } + else + conn->next_eo++; } else { - conn->next_eo++; + /* No more options to send, so we are done. */ + conn->setenv_state = SETENV_STATE_IDLE; } - } - else - { - /* No more options to send, so we are done. */ - conn->setenv_state = SETENV_STATE_IDLE; - } - goto keep_going; - } + goto keep_going; + } case SETENV_STATE_OPTION_WAIT: - { - if (PQisBusy(conn)) - return PGRES_POLLING_READING; - - res = PQgetResult(conn); - - if (res) { - if (PQresultStatus(res) != PGRES_COMMAND_OK) + if (PQisBusy(conn)) + return PGRES_POLLING_READING; + + res = PQgetResult(conn); + + if (res) { + if (PQresultStatus(res) != PGRES_COMMAND_OK) + { + PQclear(res); + goto error_return; + } + /* Don't need the result */ PQclear(res); - goto error_return; + + /* + * We have to keep going in order to clear up the + * query + */ + goto keep_going; } - /* Don't need the result */ - PQclear(res); - /* We have to keep going in order to clear up the query */ - goto keep_going; - } - /* NULL result indicates that the query is finished */ + /* NULL result indicates that the query is finished */ - /* Send the next option */ - conn->next_eo++; - conn->setenv_state = SETENV_STATE_OPTION_SEND; - goto keep_going; - } + /* Send the next option */ + conn->next_eo++; + conn->setenv_state = SETENV_STATE_OPTION_SEND; + goto keep_going; + } case SETENV_STATE_IDLE: return PGRES_POLLING_OK; @@ -1565,13 +1644,13 @@ PQsetenvPoll(PGconn *conn) default: printfPQExpBuffer(&conn->errorMessage, "PQsetenvPoll() -- unknown state - " - "probably indicative of memory corruption!\n"); + "probably indicative of memory corruption!\n"); goto error_return; } /* Unreachable */ - error_return: +error_return: conn->setenv_state = SETENV_STATE_IDLE; return PGRES_POLLING_FAILED; } @@ -1597,12 +1676,14 @@ PQsetenv(PGconn *conn) { PostgresPollingStatusType flag = PGRES_POLLING_WRITING; - if (! PQsetenvStart(conn)) + if (!PQsetenvStart(conn)) return false; - for (;;) { + for (;;) + { + /* - * Wait, if necessary. Note that the initial state (just after + * Wait, if necessary. Note that the initial state (just after * PQsetenvStart) is to wait for the socket to select for writing. */ switch (flag) @@ -1612,7 +1693,7 @@ PQsetenv(PGconn *conn) case PGRES_POLLING_OK: return true; /* success! */ - + case PGRES_POLLING_READING: if (pqWait(1, 0, conn)) { @@ -1634,6 +1715,7 @@ PQsetenv(PGconn *conn) conn->status = CONNECTION_BAD; return false; } + /* * Now try to advance the state machine. */ @@ -1641,7 +1723,7 @@ PQsetenv(PGconn *conn) } } -#endif /* NOT_USED */ +#endif /* NOT_USED */ /* @@ -1670,15 +1752,15 @@ makeEmptyPGconn(void) #endif /* - * The output buffer size is set to 8K, which is the usual size of pipe - * buffers on Unix systems. That way, when we are sending a large - * amount of data, we avoid incurring extra kernel context swaps for - * partial bufferloads. Note that we currently don't ever enlarge + * The output buffer size is set to 8K, which is the usual size of + * pipe buffers on Unix systems. That way, when we are sending a + * large amount of data, we avoid incurring extra kernel context swaps + * for partial bufferloads. Note that we currently don't ever enlarge * the output buffer. * * With the same goal of minimizing context swaps, the input buffer will - * be enlarged anytime it has less than 8K free, so we initially allocate - * twice that. + * be enlarged anytime it has less than 8K free, so we initially + * allocate twice that. */ conn->inBufSize = 16 * 1024; conn->inBuffer = (char *) malloc(conn->inBufSize); @@ -1712,7 +1794,7 @@ freePGconn(PGconn *conn) pqClearAsyncResult(conn); /* deallocate result and curTuple */ #ifdef USE_SSL if (conn->ssl) - SSL_free(conn->ssl); + SSL_free(conn->ssl); #endif if (conn->sock >= 0) #ifdef WIN32 @@ -1770,7 +1852,7 @@ closePGconn(PGconn *conn) (void) pqFlush(conn); } - /* + /* * must reset the blocking status so a possible reconnect will work * don't call PQsetnonblocking() because it will fail if it's unable * to flush the connection. @@ -1861,9 +1943,7 @@ PostgresPollingStatusType PQresetPoll(PGconn *conn) { if (conn) - { return PQconnectPoll(conn); - } return PGRES_POLLING_FAILED; } @@ -2028,7 +2108,7 @@ conninfo_parse(const char *conninfo, PQExpBuffer errorMessage) if (options == NULL) { printfPQExpBuffer(errorMessage, - "FATAL: cannot allocate memory for copy of PQconninfoOptions\n"); + "FATAL: cannot allocate memory for copy of PQconninfoOptions\n"); return NULL; } memcpy(options, PQconninfoOptions, sizeof(PQconninfoOptions)); @@ -2076,7 +2156,7 @@ conninfo_parse(const char *conninfo, PQExpBuffer errorMessage) if (*cp != '=') { printfPQExpBuffer(errorMessage, - "ERROR: Missing '=' after '%s' in conninfo\n", + "ERROR: Missing '=' after '%s' in conninfo\n", pname); PQconninfoFree(options); free(buf); @@ -2125,7 +2205,7 @@ conninfo_parse(const char *conninfo, PQExpBuffer errorMessage) if (*cp == '\0') { printfPQExpBuffer(errorMessage, - "ERROR: PQconnectdb() - unterminated quoted string in conninfo\n"); + "ERROR: PQconnectdb() - unterminated quoted string in conninfo\n"); PQconninfoFree(options); free(buf); return NULL; @@ -2375,10 +2455,10 @@ PQclientEncoding(const PGconn *conn) int PQsetClientEncoding(PGconn *conn, const char *encoding) { - char qbuf[128]; + char qbuf[128]; static char query[] = "set client_encoding to '%s'"; - PGresult *res; - int status; + PGresult *res; + int status; if (!conn || conn->status != CONNECTION_OK) return -1; @@ -2394,7 +2474,7 @@ PQsetClientEncoding(PGconn *conn, const char *encoding) sprintf(qbuf, query, encoding); res = PQexec(conn, qbuf); - if (res == (PGresult *)NULL) + if (res == (PGresult *) NULL) return -1; if (res->resultStatus != PGRES_COMMAND_OK) status = -1; @@ -2402,17 +2482,19 @@ PQsetClientEncoding(PGconn *conn, const char *encoding) { /* change libpq internal encoding */ conn->client_encoding = pg_char_to_encoding(encoding); - status = 0; /* everything is ok */ + status = 0; /* everything is ok */ } PQclear(res); - return(status); + return (status); } + #else int PQsetClientEncoding(PGconn *conn, const char *encoding) { return -1; } + #endif void @@ -2465,7 +2547,7 @@ PQsetNoticeProcessor(PGconn *conn, PQnoticeProcessor proc, void *arg) static void defaultNoticeProcessor(void *arg, const char *message) { - (void)arg; /*not used*/ + (void) arg; /* not used */ /* Note: we expect the supplied string to end with a newline already. */ fprintf(stderr, "%s", message); } diff --git a/src/interfaces/libpq/fe-exec.c b/src/interfaces/libpq/fe-exec.c index 6b3999193d5..6617bb2bc30 100644 --- a/src/interfaces/libpq/fe-exec.c +++ b/src/interfaces/libpq/fe-exec.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.93 2000/03/14 23:59:23 tgl Exp $ + * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.94 2000/04/12 17:17:14 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -27,7 +27,7 @@ #endif /* keep this in same order as ExecStatusType in libpq-fe.h */ -char * const pgresStatus[] = { +char *const pgresStatus[] = { "PGRES_EMPTY_QUERY", "PGRES_COMMAND_OK", "PGRES_TUPLES_OK", @@ -47,7 +47,7 @@ char * const pgresStatus[] = { static void pqCatenateResultError(PGresult *res, const char *msg); static void saveErrorResult(PGconn *conn); static PGresult *prepareAsyncResult(PGconn *conn); -static int addTuple(PGresult *res, PGresAttValue *tup); +static int addTuple(PGresult *res, PGresAttValue * tup); static void parseInput(PGconn *conn); static void handleSendFailure(PGconn *conn); static int getRowDescriptions(PGconn *conn); @@ -178,7 +178,7 @@ PQmakeEmptyPGresult(PGconn *conn, ExecStatusType status) /* defaults... */ result->noticeHook = NULL; result->noticeArg = NULL; - result->client_encoding = 0; /* should be SQL_ASCII */ + result->client_encoding = 0; /* should be SQL_ASCII */ } return result; @@ -324,7 +324,7 @@ pqSetResultError(PGresult *res, const char *msg) static void pqCatenateResultError(PGresult *res, const char *msg) { - PQExpBufferData errorBuf; + PQExpBufferData errorBuf; if (!res || !msg) return; @@ -391,7 +391,9 @@ pqClearAsyncResult(PGconn *conn) static void saveErrorResult(PGconn *conn) { - /* If no old async result, just let PQmakeEmptyPGresult make one. + + /* + * If no old async result, just let PQmakeEmptyPGresult make one. * Likewise if old result is not an error message. */ if (conn->result == NULL || @@ -421,9 +423,9 @@ prepareAsyncResult(PGconn *conn) PGresult *res; /* - * conn->result is the PGresult to return. If it is NULL - * (which probably shouldn't happen) we assume there is an - * appropriate error message in conn->errorMessage. + * conn->result is the PGresult to return. If it is NULL (which + * probably shouldn't happen) we assume there is an appropriate error + * message in conn->errorMessage. */ res = conn->result; conn->result = NULL; /* handing over ownership to caller */ @@ -432,9 +434,10 @@ prepareAsyncResult(PGconn *conn) res = PQmakeEmptyPGresult(conn, PGRES_FATAL_ERROR); else { + /* - * Make sure PQerrorMessage agrees with result; it could - * be different if we have concatenated messages. + * Make sure PQerrorMessage agrees with result; it could be + * different if we have concatenated messages. */ resetPQExpBuffer(&conn->errorMessage); appendPQExpBufferStr(&conn->errorMessage, @@ -449,7 +452,7 @@ prepareAsyncResult(PGconn *conn) * Returns TRUE if OK, FALSE if not enough memory to add the row */ static int -addTuple(PGresult *res, PGresAttValue *tup) +addTuple(PGresult *res, PGresAttValue * tup) { if (res->ntups >= res->tupArrSize) { @@ -521,7 +524,7 @@ PQsendQuery(PGconn *conn, const char *query) if (conn->asyncStatus != PGASYNC_IDLE) { printfPQExpBuffer(&conn->errorMessage, - "PQsendQuery() -- another query already in progress.\n"); + "PQsendQuery() -- another query already in progress.\n"); return 0; } @@ -532,21 +535,21 @@ PQsendQuery(PGconn *conn, const char *query) /* send the query to the backend; */ /* - * in order to guarantee that we don't send a partial query - * where we would become out of sync with the backend and/or - * block during a non-blocking connection we must first flush - * the send buffer before sending more data + * in order to guarantee that we don't send a partial query where we + * would become out of sync with the backend and/or block during a + * non-blocking connection we must first flush the send buffer before + * sending more data * - * an alternative is to implement 'queue reservations' where - * we are able to roll up a transaction - * (the 'Q' along with our query) and make sure we have - * enough space for it all in the send buffer. + * an alternative is to implement 'queue reservations' where we are able + * to roll up a transaction (the 'Q' along with our query) and make + * sure we have enough space for it all in the send buffer. */ if (pqIsnonblocking(conn)) { + /* - * the buffer must have emptied completely before we allow - * a new query to be buffered + * the buffer must have emptied completely before we allow a new + * query to be buffered */ if (pqFlush(conn)) return 0; @@ -555,20 +558,21 @@ PQsendQuery(PGconn *conn, const char *query) if (pqPutnchar("Q", 1, conn) || pqPuts(query, conn)) { - handleSendFailure(conn); + handleSendFailure(conn); return 0; } + /* - * give the data a push, ignore the return value as - * ConsumeInput() will do any aditional flushing if needed + * give the data a push, ignore the return value as ConsumeInput() + * will do any aditional flushing if needed */ - (void) pqFlush(conn); + (void) pqFlush(conn); } else { - /* - * the frontend-backend protocol uses 'Q' to - * designate queries + + /* + * the frontend-backend protocol uses 'Q' to designate queries */ if (pqPutnchar("Q", 1, conn) || pqPuts(query, conn) || @@ -596,16 +600,17 @@ PQsendQuery(PGconn *conn, const char *query) static void handleSendFailure(PGconn *conn) { + /* * Accept any available input data, ignoring errors. Note that if * pqReadData decides the backend has closed the channel, it will * close our side of the socket --- that's just what we want here. */ while (pqReadData(conn) > 0) - /* loop until no more data readable */ ; + /* loop until no more data readable */ ; /* - * Parse any available input messages. Since we are in PGASYNC_IDLE + * Parse any available input messages. Since we are in PGASYNC_IDLE * state, only NOTICE and NOTIFY messages will be eaten. */ parseInput(conn); @@ -631,11 +636,11 @@ PQconsumeInput(PGconn *conn) */ if (pqReadData(conn) < 0) { + /* - * for non-blocking connections - * try to flush the send-queue otherwise we may never get a - * responce for something that may not have already been sent - * because it's in our write buffer! + * for non-blocking connections try to flush the send-queue + * otherwise we may never get a responce for something that may + * not have already been sent because it's in our write buffer! */ if (pqIsnonblocking(conn)) (void) pqFlush(conn); @@ -686,11 +691,11 @@ parseInput(PGconn *conn) * OUT; always process them right away. * * Most other messages should only be processed while in BUSY state. - * (In particular, in READY state we hold off further parsing until - * the application collects the current PGresult.) + * (In particular, in READY state we hold off further parsing + * until the application collects the current PGresult.) * - * However, if the state is IDLE then we got trouble; we need to - * deal with the unexpected message somehow. + * However, if the state is IDLE then we got trouble; we need to deal + * with the unexpected message somehow. */ if (id == 'A') { @@ -707,6 +712,7 @@ parseInput(PGconn *conn) /* If not IDLE state, just wait ... */ if (conn->asyncStatus != PGASYNC_IDLE) return; + /* * Unexpected message in IDLE state; need to recover somehow. * ERROR messages are displayed using the notice processor; @@ -723,7 +729,7 @@ parseInput(PGconn *conn) else { sprintf(noticeWorkspace, - "Backend message type 0x%02x arrived while idle\n", + "Backend message type 0x%02x arrived while idle\n", id); DONOTICE(conn, noticeWorkspace); /* Discard the unexpected message; good idea?? */ @@ -733,6 +739,7 @@ parseInput(PGconn *conn) } else { + /* * In BUSY state, we can process everything. */ @@ -743,13 +750,13 @@ parseInput(PGconn *conn) return; if (conn->result == NULL) conn->result = PQmakeEmptyPGresult(conn, - PGRES_COMMAND_OK); + PGRES_COMMAND_OK); strncpy(conn->result->cmdStatus, conn->workBuffer.data, CMDSTATUS_LEN); conn->asyncStatus = PGASYNC_READY; break; case 'E': /* error return */ - if (pqGets(& conn->errorMessage, conn)) + if (pqGets(&conn->errorMessage, conn)) return; /* build an error result holding the error message */ saveErrorResult(conn); @@ -823,7 +830,7 @@ parseInput(PGconn *conn) else { sprintf(noticeWorkspace, - "Backend sent D message without prior T\n"); + "Backend sent D message without prior T\n"); DONOTICE(conn, noticeWorkspace); /* Discard the unexpected message; good idea?? */ conn->inStart = conn->inEnd; @@ -840,7 +847,7 @@ parseInput(PGconn *conn) else { sprintf(noticeWorkspace, - "Backend sent B message without prior T\n"); + "Backend sent B message without prior T\n"); DONOTICE(conn, noticeWorkspace); /* Discard the unexpected message; good idea?? */ conn->inStart = conn->inEnd; @@ -855,10 +862,10 @@ parseInput(PGconn *conn) break; default: printfPQExpBuffer(&conn->errorMessage, - "Unknown protocol character '%c' read from backend. " - "(The protocol character is the first character the " - "backend sends in response to a query it receives).\n", - id); + "Unknown protocol character '%c' read from backend. " + "(The protocol character is the first character the " + "backend sends in response to a query it receives).\n", + id); /* build an error result holding the error message */ saveErrorResult(conn); /* Discard the unexpected message; good idea?? */ @@ -963,6 +970,7 @@ getAnotherTuple(PGconn *conn, int binary) PGresult *result = conn->result; int nfields = result->numAttributes; PGresAttValue *tup; + /* the backend sends us a bitmap of which attributes are null */ char std_bitmap[64]; /* used unless it doesn't fit */ char *bitmap = std_bitmap; @@ -1055,7 +1063,9 @@ getAnotherTuple(PGconn *conn, int binary) outOfMemory: /* Replace partially constructed result with an error result */ - /* we do NOT use saveErrorResult() here, because of the likelihood + + /* + * we do NOT use saveErrorResult() here, because of the likelihood * that there's not enough memory to concatenate messages... */ pqClearAsyncResult(conn); @@ -1116,8 +1126,10 @@ PQgetResult(PGconn *conn) if (pqWait(TRUE, FALSE, conn) || pqReadData(conn) < 0) { - /* conn->errorMessage has been set by pqWait or pqReadData. - * We want to append it to any already-received error message. + + /* + * conn->errorMessage has been set by pqWait or pqReadData. We + * want to append it to any already-received error message. */ saveErrorResult(conn); conn->asyncStatus = PGASYNC_IDLE; @@ -1173,12 +1185,12 @@ PQexec(PGconn *conn, const char *query) { PGresult *result; PGresult *lastResult; - bool savedblocking; + bool savedblocking; /* - * we assume anyone calling PQexec wants blocking behaviour, - * we force the blocking status of the connection to blocking - * for the duration of this function and restore it on return + * we assume anyone calling PQexec wants blocking behaviour, we force + * the blocking status of the connection to blocking for the duration + * of this function and restore it on return */ savedblocking = pqIsnonblocking(conn); if (PQsetnonblocking(conn, FALSE) == -1) @@ -1205,15 +1217,15 @@ PQexec(PGconn *conn, const char *query) /* OK to send the message */ if (!PQsendQuery(conn, query)) - goto errout; /* restore blocking status */ + goto errout; /* restore blocking status */ /* * For backwards compatibility, return the last result if there are * more than one --- but merge error messages if we get more than one * error result. * - * We have to stop if we see copy in/out, however. - * We will resume parsing when application calls PQendcopy. + * We have to stop if we see copy in/out, however. We will resume parsing + * when application calls PQendcopy. */ lastResult = NULL; while ((result = PQgetResult(conn)) != NULL) @@ -1260,11 +1272,13 @@ errout: static int getNotice(PGconn *conn) { - /* Since the Notice might be pretty long, we create a temporary - * PQExpBuffer rather than using conn->workBuffer. workBuffer is + + /* + * Since the Notice might be pretty long, we create a temporary + * PQExpBuffer rather than using conn->workBuffer. workBuffer is * intended for stuff that is expected to be short. */ - PQExpBufferData noticeBuf; + PQExpBufferData noticeBuf; initPQExpBuffer(¬iceBuf); if (pqGets(¬iceBuf, conn)) @@ -1532,13 +1546,13 @@ PQendcopy(PGconn *conn) conn->asyncStatus != PGASYNC_COPY_OUT) { printfPQExpBuffer(&conn->errorMessage, - "PQendcopy() -- I don't think there's a copy in progress.\n"); + "PQendcopy() -- I don't think there's a copy in progress.\n"); return 1; } /* - * make sure no data is waiting to be sent, - * abort if we are non-blocking and the flush fails + * make sure no data is waiting to be sent, abort if we are + * non-blocking and the flush fails */ if (pqFlush(conn) && pqIsnonblocking(conn)) return (1); @@ -1632,7 +1646,7 @@ PQfn(PGconn *conn, return NULL; } - if (pqPuts("F ", conn) || /* function */ + if (pqPuts("F ", conn) || /* function */ pqPutInt(fnid, 4, conn) || /* function id */ pqPutInt(nargs, 4, conn)) /* # of args */ { @@ -1730,7 +1744,7 @@ PQfn(PGconn *conn, { /* The backend violates the protocol. */ printfPQExpBuffer(&conn->errorMessage, - "FATAL: PQfn: protocol error: id=0x%x\n", + "FATAL: PQfn: protocol error: id=0x%x\n", id); saveErrorResult(conn); conn->inStart = conn->inCursor; @@ -1764,7 +1778,7 @@ PQfn(PGconn *conn, default: /* The backend violates the protocol. */ printfPQExpBuffer(&conn->errorMessage, - "FATAL: PQfn: protocol error: id=0x%x\n", + "FATAL: PQfn: protocol error: id=0x%x\n", id); saveErrorResult(conn); conn->inStart = conn->inCursor; @@ -1775,9 +1789,10 @@ PQfn(PGconn *conn, needInput = false; } - /* We fall out of the loop only upon failing to read data. - * conn->errorMessage has been set by pqWait or pqReadData. - * We want to append it to any already-received error message. + /* + * We fall out of the loop only upon failing to read data. + * conn->errorMessage has been set by pqWait or pqReadData. We want to + * append it to any already-received error message. */ saveErrorResult(conn); return prepareAsyncResult(conn); @@ -1842,7 +1857,7 @@ PQbinaryTuples(const PGresult *res) static int check_field_number(const char *routineName, const PGresult *res, int field_num) { - char noticeBuf[128]; + char noticeBuf[128]; if (!res) return FALSE; /* no way to display error message... */ @@ -1864,7 +1879,7 @@ static int check_tuple_field_number(const char *routineName, const PGresult *res, int tup_num, int field_num) { - char noticeBuf[128]; + char noticeBuf[128]; if (!res) return FALSE; /* no way to display error message... */ @@ -1997,13 +2012,14 @@ PQcmdStatus(PGresult *res) char * PQoidStatus(const PGresult *res) { - /* - * This must be enough to hold the result. Don't laugh, this is - * better than what this function used to do. + + /* + * This must be enough to hold the result. Don't laugh, this is better + * than what this function used to do. */ static char buf[24]; - size_t len; + size_t len; if (!res || !res->cmdStatus || strncmp(res->cmdStatus, "INSERT ", 7) != 0) return ""; @@ -2019,25 +2035,25 @@ PQoidStatus(const PGresult *res) /* PQoidValue - - a perhaps preferable form of the above which just returns + a perhaps preferable form of the above which just returns an Oid type */ Oid PQoidValue(const PGresult *res) { - char * endptr = NULL; - long int result; + char *endptr = NULL; + long int result; - if (!res || !res->cmdStatus || strncmp(res->cmdStatus, "INSERT ", 7) != 0) - return InvalidOid; + if (!res || !res->cmdStatus || strncmp(res->cmdStatus, "INSERT ", 7) != 0) + return InvalidOid; - errno = 0; - result = strtoul(res->cmdStatus + 7, &endptr, 10); + errno = 0; + result = strtoul(res->cmdStatus + 7, &endptr, 10); - if (!endptr || (*endptr != ' ' && *endptr != '\0') || errno == ERANGE) - return InvalidOid; - else - return (Oid)result; + if (!endptr || (*endptr != ' ' && *endptr != '\0') || errno == ERANGE) + return InvalidOid; + else + return (Oid) result; } /* @@ -2048,7 +2064,7 @@ PQoidValue(const PGresult *res) char * PQcmdTuples(PGresult *res) { - char noticeBuf[128]; + char noticeBuf[128]; if (!res) return ""; @@ -2160,9 +2176,9 @@ PQsetnonblocking(PGconn *conn, int arg) /* * to guarantee constancy for flushing/query/result-polling behavior * we need to flush the send queue at this point in order to guarantee - * proper behavior. - * this is ok because either they are making a transition - * _from_ or _to_ blocking mode, either way we can block them. + * proper behavior. this is ok because either they are making a + * transition _from_ or _to_ blocking mode, either way we can block + * them. */ /* if we are going from blocking to non-blocking flush here */ if (pqFlush(conn)) diff --git a/src/interfaces/libpq/fe-lobj.c b/src/interfaces/libpq/fe-lobj.c index 6a7fd71f440..23b9ffb09c0 100644 --- a/src/interfaces/libpq/fe-lobj.c +++ b/src/interfaces/libpq/fe-lobj.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-lobj.c,v 1.28 2000/02/07 23:10:11 petere Exp $ + * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-lobj.c,v 1.29 2000/04/12 17:17:15 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -523,7 +523,7 @@ lo_initialize(PGconn *conn) PGresult *res; PGlobjfuncs *lobjfuncs; int n; - const char *fname; + const char *fname; Oid foid; /* ---------------- @@ -563,7 +563,7 @@ lo_initialize(PGconn *conn) free(lobjfuncs); PQclear(res); printfPQExpBuffer(&conn->errorMessage, - "ERROR: SELECT didn't return data in lo_initialize()\n"); + "ERROR: SELECT didn't return data in lo_initialize()\n"); return -1; } @@ -603,56 +603,56 @@ lo_initialize(PGconn *conn) if (lobjfuncs->fn_lo_open == 0) { printfPQExpBuffer(&conn->errorMessage, - "ERROR: Cannot determine OID for function lo_open\n"); + "ERROR: Cannot determine OID for function lo_open\n"); free(lobjfuncs); return -1; } if (lobjfuncs->fn_lo_close == 0) { printfPQExpBuffer(&conn->errorMessage, - "ERROR: Cannot determine OID for function lo_close\n"); + "ERROR: Cannot determine OID for function lo_close\n"); free(lobjfuncs); return -1; } if (lobjfuncs->fn_lo_creat == 0) { printfPQExpBuffer(&conn->errorMessage, - "ERROR: Cannot determine OID for function lo_creat\n"); + "ERROR: Cannot determine OID for function lo_creat\n"); free(lobjfuncs); return -1; } if (lobjfuncs->fn_lo_unlink == 0) { printfPQExpBuffer(&conn->errorMessage, - "ERROR: Cannot determine OID for function lo_unlink\n"); + "ERROR: Cannot determine OID for function lo_unlink\n"); free(lobjfuncs); return -1; } if (lobjfuncs->fn_lo_lseek == 0) { printfPQExpBuffer(&conn->errorMessage, - "ERROR: Cannot determine OID for function lo_lseek\n"); + "ERROR: Cannot determine OID for function lo_lseek\n"); free(lobjfuncs); return -1; } if (lobjfuncs->fn_lo_tell == 0) { printfPQExpBuffer(&conn->errorMessage, - "ERROR: Cannot determine OID for function lo_tell\n"); + "ERROR: Cannot determine OID for function lo_tell\n"); free(lobjfuncs); return -1; } if (lobjfuncs->fn_lo_read == 0) { printfPQExpBuffer(&conn->errorMessage, - "ERROR: Cannot determine OID for function loread\n"); + "ERROR: Cannot determine OID for function loread\n"); free(lobjfuncs); return -1; } if (lobjfuncs->fn_lo_write == 0) { printfPQExpBuffer(&conn->errorMessage, - "ERROR: Cannot determine OID for function lowrite\n"); + "ERROR: Cannot determine OID for function lowrite\n"); free(lobjfuncs); return -1; } diff --git a/src/interfaces/libpq/fe-misc.c b/src/interfaces/libpq/fe-misc.c index e6dd26d8fbb..d7f1b6e1549 100644 --- a/src/interfaces/libpq/fe-misc.c +++ b/src/interfaces/libpq/fe-misc.c @@ -25,7 +25,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-misc.c,v 1.40 2000/04/11 19:00:31 momjian Exp $ + * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-misc.c,v 1.41 2000/04/12 17:17:15 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -91,40 +91,41 @@ pqGetc(char *result, PGconn *conn) static int pqPutBytes(const char *s, size_t nbytes, PGconn *conn) { - size_t avail = Max(conn->outBufSize - conn->outCount, 0); + size_t avail = Max(conn->outBufSize - conn->outCount, 0); /* - * if we are non-blocking and the send queue is too full to buffer this - * request then try to flush some and return an error + * if we are non-blocking and the send queue is too full to buffer + * this request then try to flush some and return an error */ if (pqIsnonblocking(conn) && nbytes > avail && pqFlush(conn)) { - /* - * even if the flush failed we may still have written some - * data, recalculate the size of the send-queue relative - * to the amount we have to send, we may be able to queue it - * afterall even though it's not sent to the database it's - * ok, any routines that check the data coming from the - * database better call pqFlush() anyway. + + /* + * even if the flush failed we may still have written some data, + * recalculate the size of the send-queue relative to the amount + * we have to send, we may be able to queue it afterall even + * though it's not sent to the database it's ok, any routines that + * check the data coming from the database better call pqFlush() + * anyway. */ if (nbytes > Max(conn->outBufSize - conn->outCount, 0)) { printfPQExpBuffer(&conn->errorMessage, - "pqPutBytes -- pqFlush couldn't flush enough" - " data: space available: %d, space needed %d\n", - Max(conn->outBufSize - conn->outCount, 0), nbytes); + "pqPutBytes -- pqFlush couldn't flush enough" + " data: space available: %d, space needed %d\n", + Max(conn->outBufSize - conn->outCount, 0), nbytes); return EOF; } /* fixup avail for while loop */ avail = Max(conn->outBufSize - conn->outCount, 0); } - /* + /* * is the amount of data to be sent is larger than the size of the * output buffer then we must flush it to make more room. * - * the code above will make sure the loop conditional is never - * true for non-blocking connections + * the code above will make sure the loop conditional is never true for + * non-blocking connections */ while (nbytes > avail) { @@ -208,7 +209,7 @@ pqGetnchar(char *s, size_t len, PGconn *conn) conn->inCursor += len; if (conn->Pfdebug) - fprintf(conn->Pfdebug, "From backend (%d)> %.*s\n", len, (int)len, s); + fprintf(conn->Pfdebug, "From backend (%d)> %.*s\n", len, (int) len, s); return 0; } @@ -224,7 +225,7 @@ pqPutnchar(const char *s, size_t len, PGconn *conn) return EOF; if (conn->Pfdebug) - fprintf(conn->Pfdebug, "To backend> %.*s\n", (int)len, s); + fprintf(conn->Pfdebug, "To backend> %.*s\n", (int) len, s); return 0; } @@ -324,7 +325,7 @@ pqReadReady(PGconn *conn) FD_SET(conn->sock, &input_mask); timeout.tv_sec = 0; timeout.tv_usec = 0; - retry: +retry: if (select(conn->sock + 1, &input_mask, (fd_set *) NULL, (fd_set *) NULL, &timeout) < 0) { @@ -333,7 +334,7 @@ pqReadReady(PGconn *conn) goto retry; printfPQExpBuffer(&conn->errorMessage, - "pqReadReady() -- select() failed: errno=%d\n%s\n", + "pqReadReady() -- select() failed: errno=%d\n%s\n", errno, strerror(errno)); return -1; } @@ -358,7 +359,7 @@ pqWriteReady(PGconn *conn) FD_SET(conn->sock, &input_mask); timeout.tv_sec = 0; timeout.tv_usec = 0; - retry: +retry: if (select(conn->sock + 1, (fd_set *) NULL, &input_mask, (fd_set *) NULL, &timeout) < 0) { @@ -367,7 +368,7 @@ pqWriteReady(PGconn *conn) goto retry; printfPQExpBuffer(&conn->errorMessage, - "pqWriteReady() -- select() failed: errno=%d\n%s\n", + "pqWriteReady() -- select() failed: errno=%d\n%s\n", errno, strerror(errno)); return -1; } @@ -415,7 +416,7 @@ pqReadData(PGconn *conn) * buffer size. We enlarge before filling the buffer entirely so as * to avoid asking the kernel for a partial packet. The magic constant * here should be large enough for a TCP packet or Unix pipe - * bufferload. 8K is the usual pipe buffer size, so... + * bufferload. 8K is the usual pipe buffer size, so... */ if (conn->inBufSize - conn->inEnd < 8192) { @@ -432,13 +433,13 @@ pqReadData(PGconn *conn) /* OK, try to read some data */ tryAgain: #ifdef USE_SSL - if (conn->ssl) - nread = SSL_read(conn->ssl, conn->inBuffer + conn->inEnd, - conn->inBufSize - conn->inEnd); + if (conn->ssl) + nread = SSL_read(conn->ssl, conn->inBuffer + conn->inEnd, + conn->inBufSize - conn->inEnd); else #endif - nread = recv(conn->sock, conn->inBuffer + conn->inEnd, - conn->inBufSize - conn->inEnd, 0); + nread = recv(conn->sock, conn->inBuffer + conn->inEnd, + conn->inBufSize - conn->inEnd, 0); if (nread < 0) { if (errno == EINTR) @@ -458,24 +459,26 @@ tryAgain: goto definitelyFailed; #endif printfPQExpBuffer(&conn->errorMessage, - "pqReadData() -- read() failed: errno=%d\n%s\n", + "pqReadData() -- read() failed: errno=%d\n%s\n", errno, strerror(errno)); return -1; } if (nread > 0) { conn->inEnd += nread; + /* * Hack to deal with the fact that some kernels will only give us - * back 1 packet per recv() call, even if we asked for more and there - * is more available. If it looks like we are reading a long message, - * loop back to recv() again immediately, until we run out of data - * or buffer space. Without this, the block-and-restart behavior of - * libpq's higher levels leads to O(N^2) performance on long messages. + * back 1 packet per recv() call, even if we asked for more and + * there is more available. If it looks like we are reading a + * long message, loop back to recv() again immediately, until we + * run out of data or buffer space. Without this, the + * block-and-restart behavior of libpq's higher levels leads to + * O(N^2) performance on long messages. * * Since we left-justified the data above, conn->inEnd gives the - * amount of data already read in the current message. We consider - * the message "long" once we have acquired 32k ... + * amount of data already read in the current message. We + * consider the message "long" once we have acquired 32k ... */ if (conn->inEnd > 32768 && (conn->inBufSize - conn->inEnd) >= 8192) @@ -516,13 +519,13 @@ tryAgain: */ tryAgain2: #ifdef USE_SSL - if (conn->ssl) - nread = SSL_read(conn->ssl, conn->inBuffer + conn->inEnd, - conn->inBufSize - conn->inEnd); + if (conn->ssl) + nread = SSL_read(conn->ssl, conn->inBuffer + conn->inEnd, + conn->inBufSize - conn->inEnd); else #endif - nread = recv(conn->sock, conn->inBuffer + conn->inEnd, - conn->inBufSize - conn->inEnd, 0); + nread = recv(conn->sock, conn->inBuffer + conn->inEnd, + conn->inBufSize - conn->inEnd, 0); if (nread < 0) { if (errno == EINTR) @@ -542,7 +545,7 @@ tryAgain2: goto definitelyFailed; #endif printfPQExpBuffer(&conn->errorMessage, - "pqReadData() -- read() failed: errno=%d\n%s\n", + "pqReadData() -- read() failed: errno=%d\n%s\n", errno, strerror(errno)); return -1; } @@ -558,9 +561,9 @@ tryAgain2: */ definitelyFailed: printfPQExpBuffer(&conn->errorMessage, - "pqReadData() -- backend closed the channel unexpectedly.\n" - "\tThis probably means the backend terminated abnormally\n" - "\tbefore or while processing the request.\n"); + "pqReadData() -- backend closed the channel unexpectedly.\n" + "\tThis probably means the backend terminated abnormally\n" + "\tbefore or while processing the request.\n"); conn->status = CONNECTION_BAD; /* No more connection to backend */ #ifdef WIN32 closesocket(conn->sock); @@ -588,9 +591,9 @@ pqFlush(PGconn *conn) return EOF; } - /* - * don't try to send zero data, allows us to use this function - * without too much worry about overhead + /* + * don't try to send zero data, allows us to use this function without + * too much worry about overhead */ if (len == 0) return (0); @@ -601,16 +604,17 @@ pqFlush(PGconn *conn) /* Prevent being SIGPIPEd if backend has closed the connection. */ #ifndef WIN32 pqsigfunc oldsighandler = pqsignal(SIGPIPE, SIG_IGN); + #endif - int sent; + int sent; #ifdef USE_SSL - if (conn->ssl) - sent = SSL_write(conn->ssl, ptr, len); + if (conn->ssl) + sent = SSL_write(conn->ssl, ptr, len); else #endif - sent = send(conn->sock, ptr, len, 0); + sent = send(conn->sock, ptr, len, 0); #ifndef WIN32 pqsignal(SIGPIPE, oldsighandler); @@ -642,22 +646,24 @@ pqFlush(PGconn *conn) case ECONNRESET: #endif printfPQExpBuffer(&conn->errorMessage, - "pqFlush() -- backend closed the channel unexpectedly.\n" - "\tThis probably means the backend terminated abnormally" - " before or while processing the request.\n"); + "pqFlush() -- backend closed the channel unexpectedly.\n" + "\tThis probably means the backend terminated abnormally" + " before or while processing the request.\n"); + /* * We used to close the socket here, but that's a bad * idea since there might be unread data waiting - * (typically, a NOTICE message from the backend telling - * us it's committing hara-kiri...). Leave the socket - * open until pqReadData finds no more data can be read. + * (typically, a NOTICE message from the backend + * telling us it's committing hara-kiri...). Leave + * the socket open until pqReadData finds no more data + * can be read. */ return EOF; default: printfPQExpBuffer(&conn->errorMessage, - "pqFlush() -- couldn't send data: errno=%d\n%s\n", - errno, strerror(errno)); + "pqFlush() -- couldn't send data: errno=%d\n%s\n", + errno, strerror(errno)); /* We don't assume it's a fatal error... */ return EOF; } @@ -672,9 +678,9 @@ pqFlush(PGconn *conn) { /* We didn't send it all, wait till we can send more */ - /* - * if the socket is in non-blocking mode we may need - * to abort here + /* + * if the socket is in non-blocking mode we may need to abort + * here */ #ifdef USE_SSL /* can't do anything for our SSL users yet */ @@ -723,7 +729,7 @@ pqWait(int forRead, int forWrite, PGconn *conn) if (forRead || forWrite) { - retry: +retry: FD_ZERO(&input_mask); FD_ZERO(&output_mask); if (forRead) @@ -736,7 +742,7 @@ pqWait(int forRead, int forWrite, PGconn *conn) if (errno == EINTR) goto retry; printfPQExpBuffer(&conn->errorMessage, - "pqWait() -- select() failed: errno=%d\n%s\n", + "pqWait() -- select() failed: errno=%d\n%s\n", errno, strerror(errno)); return EOF; } @@ -775,7 +781,7 @@ PQenv2encoding(void) str = getenv("PGCLIENTENCODING"); if (str && *str != '\0') encoding = pg_char_to_encoding(str); - return(encoding); + return (encoding); } #else @@ -784,8 +790,8 @@ PQenv2encoding(void) int PQmblen(const unsigned char *s, int encoding) { - (void)s; - (void)encoding; + (void) s; + (void) encoding; return 1; } int diff --git a/src/interfaces/libpq/fe-print.c b/src/interfaces/libpq/fe-print.c index 840f47e5796..fac34940543 100644 --- a/src/interfaces/libpq/fe-print.c +++ b/src/interfaces/libpq/fe-print.c @@ -10,7 +10,7 @@ * didn't really belong there. * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-print.c,v 1.36 2000/03/14 23:59:23 tgl Exp $ + * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-print.c,v 1.37 2000/04/12 17:17:15 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -38,12 +38,14 @@ #ifdef TIOCGWINSZ static struct winsize screen_size; + #else static struct winsize { int ws_row; int ws_col; } screen_size; + #endif @@ -54,7 +56,7 @@ static void do_field(const PQprintOpt *po, const PGresult *res, unsigned char *fieldNotNum, int *fieldMax, const int fieldMaxLen, FILE *fout); static char *do_header(FILE *fout, const PQprintOpt *po, const int nFields, - int *fieldMax, const char **fieldNames, unsigned char *fieldNotNum, + int *fieldMax, const char **fieldNames, unsigned char *fieldNotNum, const int fs_len, const PGresult *res); static void output_row(FILE *fout, const PQprintOpt *po, const int nFields, char **fields, unsigned char *fieldNotNum, int *fieldMax, char *border, @@ -77,8 +79,8 @@ static void fill(int length, int max, char filler, FILE *fp); void PQprint(FILE *fout, - const PGresult *res, - const PQprintOpt *po) + const PGresult *res, + const PQprintOpt *po) { int nFields; @@ -93,7 +95,7 @@ PQprint(FILE *fout, unsigned char *fieldNotNum = NULL; char *border = NULL; char **fields = NULL; - const char **fieldNames; + const char **fieldNames; int fieldMaxLen = 0; int numFieldName; int fs_len = strlen(po->fieldSep); @@ -125,7 +127,7 @@ PQprint(FILE *fout, for (j = 0; j < nFields; j++) { int len; - const char *s = (j < numFieldName && po->fieldName[j][0]) ? + const char *s = (j < numFieldName && po->fieldName[j][0]) ? po->fieldName[j] : PQfname(res, j); fieldNames[j] = s; @@ -216,7 +218,7 @@ PQprint(FILE *fout, for (j = 0; j < nFields; j++) { - const char *s = fieldNames[j]; + const char *s = fieldNames[j]; fputs(s, fout); len += strlen(s) + fs_len; @@ -313,12 +315,12 @@ static void do_field(const PQprintOpt *po, const PGresult *res, const int i, const int j, const int fs_len, char **fields, - const int nFields, char const **fieldNames, + const int nFields, char const ** fieldNames, unsigned char *fieldNotNum, int *fieldMax, const int fieldMaxLen, FILE *fout) { - const char *pval, + const char *pval, *p; int plen; bool skipit; @@ -341,7 +343,7 @@ do_field(const PQprintOpt *po, const PGresult *res, if (!skipit) { - if (po->align && ! fieldNotNum[j]) + if (po->align && !fieldNotNum[j]) { /* Detect whether field contains non-numeric data */ char ch = '0'; @@ -353,21 +355,22 @@ do_field(const PQprintOpt *po, const PGresult *res, #endif { ch = *p; - if (! ((ch >= '0' && ch <= '9') || - ch == '.' || - ch == 'E' || - ch == 'e' || - ch == ' ' || - ch == '-')) + if (!((ch >= '0' && ch <= '9') || + ch == '.' || + ch == 'E' || + ch == 'e' || + ch == ' ' || + ch == '-')) { fieldNotNum[j] = 1; break; } } + /* - * Above loop will believe E in first column is numeric; also, we - * insist on a digit in the last column for a numeric. This test - * is still not bulletproof but it handles most cases. + * Above loop will believe E in first column is numeric; also, + * we insist on a digit in the last column for a numeric. This + * test is still not bulletproof but it handles most cases. */ if (*pval == 'E' || *pval == 'e' || !(ch >= '0' && ch <= '9')) @@ -483,7 +486,7 @@ do_header(FILE *fout, const PQprintOpt *po, const int nFields, int *fieldMax, fputs(po->fieldSep, fout); for (j = 0; j < nFields; j++) { - const char *s = PQfname(res, j); + const char *s = PQfname(res, j); if (po->html3) { @@ -562,11 +565,11 @@ output_row(FILE *fout, const PQprintOpt *po, const int nFields, char **fields, void PQdisplayTuples(const PGresult *res, - FILE *fp, /* where to send the output */ - int fillAlign, /* pad the fields with spaces */ - const char *fieldSep, /* field separator */ - int printHeader,/* display headers? */ - int quiet + FILE *fp, /* where to send the output */ + int fillAlign, /* pad the fields with spaces */ + const char *fieldSep, /* field separator */ + int printHeader,/* display headers? */ + int quiet ) { #define DEFAULT_FIELD_SEP " " @@ -597,7 +600,8 @@ PQdisplayTuples(const PGresult *res, fLength[j] = strlen(PQfname(res, j)); for (i = 0; i < nTuples; i++) { - int flen = PQgetlength(res, i, j); + int flen = PQgetlength(res, i, j); + if (flen > fLength[j]) fLength[j] = flen; } @@ -653,11 +657,11 @@ PQdisplayTuples(const PGresult *res, void PQprintTuples(const PGresult *res, - FILE *fout, /* output stream */ - int PrintAttNames,/* print attribute names or not */ - int TerseOutput, /* delimiter bars or not? */ - int colWidth /* width of column, if 0, use variable - * width */ + FILE *fout, /* output stream */ + int PrintAttNames,/* print attribute names or not */ + int TerseOutput, /* delimiter bars or not? */ + int colWidth /* width of column, if 0, use variable + * width */ ) { int nFields; @@ -713,7 +717,7 @@ PQprintTuples(const PGresult *res, { for (j = 0; j < nFields; j++) { - const char *pval = PQgetvalue(res, i, j); + const char *pval = PQgetvalue(res, i, j); fprintf(fout, formatString, TerseOutput ? "" : "|", @@ -730,13 +734,13 @@ PQprintTuples(const PGresult *res, /* simply send out max-length number of filler characters to fp */ - + static void fill(int length, int max, char filler, FILE *fp) { - int count; - - count = max - length; - while (count-- >= 0) - putc(filler, fp); + int count; + + count = max - length; + while (count-- >= 0) + putc(filler, fp); } diff --git a/src/interfaces/libpq/libpq-fe.h b/src/interfaces/libpq/libpq-fe.h index 2aba91a6905..f82ae6ce17b 100644 --- a/src/interfaces/libpq/libpq-fe.h +++ b/src/interfaces/libpq/libpq-fe.h @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2000, PostgreSQL, Inc * Portions Copyright (c) 1994, Regents of the University of California * - * $Id: libpq-fe.h,v 1.64 2000/03/30 02:59:14 tgl Exp $ + * $Id: libpq-fe.h,v 1.65 2000/04/12 17:17:15 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -30,31 +30,37 @@ extern "C" typedef enum { - /* Although you may decide to change this list in some way, - values which become unused should never be removed, nor - should constants be redefined - that would break - compatibility with existing code. */ + + /* + * Although you may decide to change this list in some way, values + * which become unused should never be removed, nor should + * constants be redefined - that would break compatibility with + * existing code. + */ CONNECTION_OK, CONNECTION_BAD, /* Non-blocking mode only below here */ - /* The existence of these should never be relied upon - they - should only be used for user feedback or similar purposes. */ - CONNECTION_STARTED, /* Waiting for connection to be made. */ - CONNECTION_MADE, /* Connection OK; waiting to send. */ - CONNECTION_AWAITING_RESPONSE, /* Waiting for a response - from the postmaster. */ - CONNECTION_AUTH_OK, /* Received authentication; - waiting for backend startup. */ - CONNECTION_SETENV /* Negotiating environment. */ + + /* + * The existence of these should never be relied upon - they + * should only be used for user feedback or similar purposes. + */ + CONNECTION_STARTED, /* Waiting for connection to be made. */ + CONNECTION_MADE, /* Connection OK; waiting to send. */ + CONNECTION_AWAITING_RESPONSE, /* Waiting for a response from the + * postmaster. */ + CONNECTION_AUTH_OK, /* Received authentication; waiting for + * backend startup. */ + CONNECTION_SETENV /* Negotiating environment. */ } ConnStatusType; typedef enum { PGRES_POLLING_FAILED = 0, - PGRES_POLLING_READING, /* These two indicate that one may */ - PGRES_POLLING_WRITING, /* use select before polling again. */ + PGRES_POLLING_READING, /* These two indicate that one may */ + PGRES_POLLING_WRITING, /* use select before polling again. */ PGRES_POLLING_OK, - PGRES_POLLING_ACTIVE /* Can call poll function immediately.*/ + PGRES_POLLING_ACTIVE /* Can call poll function immediately. */ } PostgresPollingStatusType; typedef enum @@ -104,17 +110,17 @@ extern "C" typedef void (*PQnoticeProcessor) (void *arg, const char *message); /* Print options for PQprint() */ - typedef char pqbool; + typedef char pqbool; typedef struct _PQprintOpt { - pqbool header; /* print output field headings and row + pqbool header; /* print output field headings and row * count */ - pqbool align; /* fill align the fields */ - pqbool standard; /* old brain dead format */ - pqbool html3; /* output html tables */ - pqbool expanded; /* expand tables */ - pqbool pager; /* use pager for output if needed */ + pqbool align; /* fill align the fields */ + pqbool standard; /* old brain dead format */ + pqbool html3; /* output html tables */ + pqbool expanded; /* expand tables */ + pqbool pager; /* use pager for output if needed */ char *fieldSep; /* field separator */ char *tableOpt; /* insert to HTML <table ...> */ char *caption; /* HTML <caption> */ @@ -135,14 +141,13 @@ extern "C" char *keyword; /* The keyword of the option */ char *envvar; /* Fallback environment variable name */ char *compiled; /* Fallback compiled in default value */ - char *val; /* Option's current value, or NULL */ + char *val; /* Option's current value, or NULL */ char *label; /* Label for field in connect dialog */ - char *dispchar; /* Character to display for this field - * in a connect dialog. Values are: - * "" Display entered value as is - * "*" Password field - hide value - * "D" Debug option - don't show by default - */ + char *dispchar; /* Character to display for this field in + * a connect dialog. Values are: "" + * Display entered value as is "*" + * Password field - hide value "D" Debug + * option - don't show by default */ int dispsize; /* Field size in characters for dialog */ } PQconninfoOption; @@ -176,8 +181,8 @@ extern "C" extern PGconn *PQconnectdb(const char *conninfo); extern PGconn *PQsetdbLogin(const char *pghost, const char *pgport, const char *pgoptions, const char *pgtty, - const char *dbName, - const char *login, const char *pwd); + const char *dbName, + const char *login, const char *pwd); #define PQsetdb(M_PGHOST,M_PGPORT,M_PGOPT,M_PGTTY,M_DBNAME) \ PQsetdbLogin(M_PGHOST, M_PGPORT, M_PGOPT, M_PGTTY, M_DBNAME, NULL, NULL) @@ -195,7 +200,7 @@ extern "C" * parameters */ /* Asynchronous (non-blocking) */ - extern int PQresetStart(PGconn *conn); + extern int PQresetStart(PGconn *conn); extern PostgresPollingStatusType PQresetPoll(PGconn *conn); /* Synchronous (blocking) */ extern void PQreset(PGconn *conn); @@ -258,12 +263,12 @@ extern "C" * use */ extern PGresult *PQfn(PGconn *conn, - int fnid, - int *result_buf, - int *result_len, - int result_is_int, - const PQArgBlock *args, - int nargs); + int fnid, + int *result_buf, + int *result_len, + int result_is_int, + const PQArgBlock *args, + int nargs); /* Accessor functions for PGresult objects */ extern ExecStatusType PQresultStatus(const PGresult *res); @@ -278,8 +283,8 @@ extern "C" extern int PQfsize(const PGresult *res, int field_num); extern int PQfmod(const PGresult *res, int field_num); extern char *PQcmdStatus(PGresult *res); - extern char *PQoidStatus(const PGresult *res); /* old and ugly */ - extern Oid PQoidValue(const PGresult *res); /* new and improved */ + extern char *PQoidStatus(const PGresult *res); /* old and ugly */ + extern Oid PQoidValue(const PGresult *res); /* new and improved */ extern char *PQcmdTuples(PGresult *res); extern char *PQgetvalue(const PGresult *res, int tup_num, int field_num); extern int PQgetlength(const PGresult *res, int tup_num, int field_num); @@ -298,25 +303,27 @@ extern "C" /* === in fe-print.c === */ extern void PQprint(FILE *fout, /* output stream */ - const PGresult *res, - const PQprintOpt *ps); /* option structure */ - - /* - * really old printing routines - */ - extern void PQdisplayTuples(const PGresult *res, - FILE *fp, /* where to send the output */ - int fillAlign, /* pad the fields with spaces */ - const char *fieldSep, /* field separator */ - int printHeader, /* display headers? */ - int quiet); - - extern void PQprintTuples(const PGresult *res, - FILE *fout, /* output stream */ - int printAttName, /* print attribute names */ - int terseOutput, /* delimiter bars */ - int width); /* width of column, if - * 0, use variable width */ + const PGresult *res, + const PQprintOpt *ps); /* option structure */ + + /* + * really old printing routines + */ + extern void PQdisplayTuples(const PGresult *res, + FILE *fp, /* where to send the + * output */ + int fillAlign, /* pad the fields with + * spaces */ + const char *fieldSep, /* field separator */ + int printHeader, /* display headers? */ + int quiet); + + extern void PQprintTuples(const PGresult *res, + FILE *fout, /* output stream */ + int printAttName, /* print attribute names */ + int terseOutput, /* delimiter bars */ + int width); /* width of column, if + * 0, use variable width */ /* === in fe-lobj.c === */ @@ -339,10 +346,11 @@ extern "C" extern int PQmblen(const unsigned char *s, int encoding); /* Get encoding id from environment variable PGCLIENTENCODING */ - extern int PQenv2encoding(void); + extern int PQenv2encoding(void); #ifdef __cplusplus } + #endif #endif /* LIBPQ_FE_H */ diff --git a/src/interfaces/libpq/libpq-int.h b/src/interfaces/libpq/libpq-int.h index 823abf20a33..fbad5fc7a81 100644 --- a/src/interfaces/libpq/libpq-int.h +++ b/src/interfaces/libpq/libpq-int.h @@ -12,7 +12,7 @@ * Portions Copyright (c) 1996-2000, PostgreSQL, Inc * Portions Copyright (c) 1994, Regents of the University of California * - * $Id: libpq-int.h,v 1.22 2000/03/24 01:39:55 tgl Exp $ + * $Id: libpq-int.h,v 1.23 2000/04/12 17:17:15 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -81,7 +81,7 @@ typedef struct pgresAttDesc Oid typid; /* type id */ int typlen; /* type size */ int atttypmod; /* type-specific modifier info */ -} PGresAttDesc; +} PGresAttDesc; /* Data for a single attribute of a single tuple */ @@ -106,7 +106,7 @@ typedef struct pgresAttValue int len; /* length in bytes of the value */ char *value; /* actual value, plus terminating zero * byte */ -} PGresAttValue; +} PGresAttValue; struct pg_result { @@ -121,12 +121,13 @@ struct pg_result * last query */ int binary; /* binary tuple values if binary == 1, * otherwise ASCII */ + /* - * The conn link in PGresult is no longer used by any libpq code. - * It should be removed entirely, because it could be a dangling link - * (the application could keep the PGresult around longer than it keeps - * the PGconn!) But there may be apps out there that depend on it, - * so we will leave it here at least for a release or so. + * The conn link in PGresult is no longer used by any libpq code. It + * should be removed entirely, because it could be a dangling link + * (the application could keep the PGresult around longer than it + * keeps the PGconn!) But there may be apps out there that depend on + * it, so we will leave it here at least for a release or so. */ PGconn *xconn; /* connection we did the query on, if any */ @@ -134,9 +135,9 @@ struct pg_result * These fields are copied from the originating PGconn, so that * operations on the PGresult don't have to reference the PGconn. */ - PQnoticeProcessor noticeHook; /* notice/error message processor */ + PQnoticeProcessor noticeHook; /* notice/error message processor */ void *noticeArg; - int client_encoding; /* encoding id */ + int client_encoding;/* encoding id */ char *errMsg; /* error message, or NULL if no error */ @@ -162,7 +163,7 @@ typedef enum PGASYNC_READY, /* result ready for PQgetResult */ PGASYNC_COPY_IN, /* Copy In data transfer in progress */ PGASYNC_COPY_OUT /* Copy Out data transfer in progress */ -} PGAsyncStatusType; +} PGAsyncStatusType; /* PGSetenvStatusType defines the state of the PQSetenv state machine */ typedef enum @@ -170,10 +171,10 @@ typedef enum SETENV_STATE_OPTION_SEND, /* About to send an Environment Option */ SETENV_STATE_OPTION_WAIT, /* Waiting for above send to complete */ /* these next two are only used in MULTIBYTE mode */ - SETENV_STATE_ENCODINGS_SEND, /* About to send an "encodings" query */ - SETENV_STATE_ENCODINGS_WAIT, /* Waiting for query to complete */ + SETENV_STATE_ENCODINGS_SEND,/* About to send an "encodings" query */ + SETENV_STATE_ENCODINGS_WAIT,/* Waiting for query to complete */ SETENV_STATE_IDLE -} PGSetenvStatusType; +} PGSetenvStatusType; /* large-object-access data ... allocated only if large-object code is used. */ typedef struct pgLobjfuncs @@ -186,7 +187,7 @@ typedef struct pgLobjfuncs Oid fn_lo_tell; /* OID of backend function lo_tell */ Oid fn_lo_read; /* OID of backend function LOread */ Oid fn_lo_write; /* OID of backend function LOwrite */ -} PGlobjfuncs; +} PGlobjfuncs; /* PGconn stores all the state data associated with a single connection * to a backend. @@ -197,8 +198,8 @@ struct pg_conn char *pghost; /* the machine on which the server is * running */ char *pghostaddr; /* the IPv4 address of the machine on - * which the server is running, in - * IPv4 numbers-and-dots notation. Takes + * which the server is running, in IPv4 + * numbers-and-dots notation. Takes * precedence over above. */ char *pgport; /* the server's communication port */ char *pgtty; /* tty on which the backend messages is @@ -243,8 +244,8 @@ struct pg_conn int inEnd; /* offset to first position after avail * data */ - int nonblocking; /* whether this connection is using a blocking - * socket to the backend or not */ + int nonblocking; /* whether this connection is using a + * blocking socket to the backend or not */ /* Buffer for data not yet sent to backend */ char *outBuffer; /* currently allocated buffer */ @@ -256,21 +257,21 @@ struct pg_conn PGresAttValue *curTuple; /* tuple currently being read */ /* Status for sending environment info. Used during PQSetenv only. */ - PGSetenvStatusType setenv_state; + PGSetenvStatusType setenv_state; const struct EnvironmentOptions *next_eo; #ifdef USE_SSL - bool allow_ssl_try; /* Allowed to try SSL negotiation */ - SSL *ssl; /* SSL status, if have SSL connection */ + bool allow_ssl_try; /* Allowed to try SSL negotiation */ + SSL *ssl; /* SSL status, if have SSL connection */ #endif /* Buffer for current error message */ - PQExpBufferData errorMessage; /* expansible string */ + PQExpBufferData errorMessage; /* expansible string */ /* Buffer for receiving various parts of messages */ - PQExpBufferData workBuffer; /* expansible string */ + PQExpBufferData workBuffer; /* expansible string */ - int client_encoding; /* encoding id */ + int client_encoding;/* encoding id */ }; /* String descriptions of the ExecStatusTypes. @@ -338,7 +339,7 @@ extern char *sys_errlist[]; #endif /* sunos4 */ #endif /* !strerror */ -/* +/* * this is so that we can check is a connection is non-blocking internally * without the overhead of a function call */ diff --git a/src/interfaces/libpq/pqexpbuffer.c b/src/interfaces/libpq/pqexpbuffer.c index f70d9139c2e..623ec8306e5 100644 --- a/src/interfaces/libpq/pqexpbuffer.c +++ b/src/interfaces/libpq/pqexpbuffer.c @@ -17,7 +17,7 @@ * Portions Copyright (c) 1996-2000, PostgreSQL, Inc * Portions Copyright (c) 1994, Regents of the University of California * - * $Header: /cvsroot/pgsql/src/interfaces/libpq/pqexpbuffer.c,v 1.5 2000/02/07 23:10:11 petere Exp $ + * $Header: /cvsroot/pgsql/src/interfaces/libpq/pqexpbuffer.c,v 1.6 2000/04/12 17:17:15 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -39,7 +39,7 @@ PQExpBuffer createPQExpBuffer(void) { - PQExpBuffer res; + PQExpBuffer res; res = (PQExpBuffer) malloc(sizeof(PQExpBufferData)); if (res != NULL) @@ -156,7 +156,7 @@ enlargePQExpBuffer(PQExpBuffer str, size_t needed) /*------------------------ * printfPQExpBuffer * Format text data under the control of fmt (an sprintf-like format string) - * and insert it into str. More space is allocated to str if necessary. + * and insert it into str. More space is allocated to str if necessary. * This is a convenience routine that does the same thing as * resetPQExpBuffer() followed by appendPQExpBuffer(). */ @@ -165,7 +165,7 @@ printfPQExpBuffer(PQExpBuffer str, const char *fmt,...) { va_list args; size_t avail; - int nprinted; + int nprinted; resetPQExpBuffer(str); @@ -184,12 +184,13 @@ printfPQExpBuffer(PQExpBuffer str, const char *fmt,...) nprinted = vsnprintf(str->data + str->len, avail, fmt, args); va_end(args); + /* * Note: some versions of vsnprintf return the number of chars - * actually stored, but at least one returns -1 on failure. - * Be conservative about believing whether the print worked. + * actually stored, but at least one returns -1 on failure. Be + * conservative about believing whether the print worked. */ - if (nprinted >= 0 && nprinted < avail-1) + if (nprinted >= 0 && nprinted < avail - 1) { /* Success. Note nprinted does not include trailing null. */ str->len += nprinted; @@ -197,7 +198,7 @@ printfPQExpBuffer(PQExpBuffer str, const char *fmt,...) } } /* Double the buffer size and try again. */ - if (! enlargePQExpBuffer(str, str->maxlen)) + if (!enlargePQExpBuffer(str, str->maxlen)) return; /* oops, out of memory */ } } @@ -215,7 +216,7 @@ appendPQExpBuffer(PQExpBuffer str, const char *fmt,...) { va_list args; size_t avail; - int nprinted; + int nprinted; for (;;) { @@ -232,12 +233,13 @@ appendPQExpBuffer(PQExpBuffer str, const char *fmt,...) nprinted = vsnprintf(str->data + str->len, avail, fmt, args); va_end(args); + /* * Note: some versions of vsnprintf return the number of chars - * actually stored, but at least one returns -1 on failure. - * Be conservative about believing whether the print worked. + * actually stored, but at least one returns -1 on failure. Be + * conservative about believing whether the print worked. */ - if (nprinted >= 0 && nprinted < avail-1) + if (nprinted >= 0 && nprinted < avail - 1) { /* Success. Note nprinted does not include trailing null. */ str->len += nprinted; @@ -245,7 +247,7 @@ appendPQExpBuffer(PQExpBuffer str, const char *fmt,...) } } /* Double the buffer size and try again. */ - if (! enlargePQExpBuffer(str, str->maxlen)) + if (!enlargePQExpBuffer(str, str->maxlen)) return; /* oops, out of memory */ } } @@ -270,7 +272,7 @@ void appendPQExpBufferChar(PQExpBuffer str, char ch) { /* Make more room if needed */ - if (! enlargePQExpBuffer(str, 1)) + if (!enlargePQExpBuffer(str, 1)) return; /* OK, append the character */ @@ -289,7 +291,7 @@ void appendBinaryPQExpBuffer(PQExpBuffer str, const char *data, size_t datalen) { /* Make more room if needed */ - if (! enlargePQExpBuffer(str, datalen)) + if (!enlargePQExpBuffer(str, datalen)) return; /* OK, append the data */ diff --git a/src/interfaces/libpq/pqexpbuffer.h b/src/interfaces/libpq/pqexpbuffer.h index 014254465aa..ac50f8ea9a6 100644 --- a/src/interfaces/libpq/pqexpbuffer.h +++ b/src/interfaces/libpq/pqexpbuffer.h @@ -18,7 +18,7 @@ * Portions Copyright (c) 1996-2000, PostgreSQL, Inc * Portions Copyright (c) 1994, Regents of the University of California * - * $Id: pqexpbuffer.h,v 1.4 2000/02/07 23:10:11 petere Exp $ + * $Id: pqexpbuffer.h,v 1.5 2000/04/12 17:17:15 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -52,7 +52,7 @@ typedef PQExpBufferData *PQExpBuffer; * be returned by PQrequestCancel() or any routine in fe-auth.c. *------------------------ */ -#define INITIAL_EXPBUFFER_SIZE 256 +#define INITIAL_EXPBUFFER_SIZE 256 /*------------------------ * There are two ways to create a PQExpBuffer object initially: @@ -113,12 +113,12 @@ extern void resetPQExpBuffer(PQExpBuffer str); * * Returns 1 if OK, 0 if failed to enlarge buffer. */ -extern int enlargePQExpBuffer(PQExpBuffer str, size_t needed); +extern int enlargePQExpBuffer(PQExpBuffer str, size_t needed); /*------------------------ * printfPQExpBuffer * Format text data under the control of fmt (an sprintf-like format string) - * and insert it into str. More space is allocated to str if necessary. + * and insert it into str. More space is allocated to str if necessary. * This is a convenience routine that does the same thing as * resetPQExpBuffer() followed by appendPQExpBuffer(). */ @@ -153,6 +153,6 @@ extern void appendPQExpBufferChar(PQExpBuffer str, char ch); * if necessary. */ extern void appendBinaryPQExpBuffer(PQExpBuffer str, - const char *data, size_t datalen); + const char *data, size_t datalen); #endif /* PQEXPBUFFER_H */ diff --git a/src/interfaces/libpq/win32.h b/src/interfaces/libpq/win32.h index 3b57134f02d..126dd152c06 100644 --- a/src/interfaces/libpq/win32.h +++ b/src/interfaces/libpq/win32.h @@ -32,4 +32,3 @@ #define DEF_PGPORT "5432" #define MAXIMUM_ALIGNOF 4 - |