diff options
| author | Byron Nikolaidis <byronn@insightdist.com> | 1999-01-05 00:32:21 +0000 |
|---|---|---|
| committer | Byron Nikolaidis <byronn@insightdist.com> | 1999-01-05 00:32:21 +0000 |
| commit | 8aad28da2d0a89b8827125c519e5f52c2748a116 (patch) | |
| tree | 77726833f3854554d074a5ba58cc5fe507e0887d /src/interfaces/odbc/execute.c | |
| parent | 1bbe55c79f8c9d7b97f89e5e32482c5280658cbf (diff) | |
| download | postgresql-8aad28da2d0a89b8827125c519e5f52c2748a116.tar.gz | |
Mini Update #2 -- final fixes for buffer lengths, null buffers, truncation
Diffstat (limited to 'src/interfaces/odbc/execute.c')
| -rw-r--r-- | src/interfaces/odbc/execute.c | 37 |
1 files changed, 33 insertions, 4 deletions
diff --git a/src/interfaces/odbc/execute.c b/src/interfaces/odbc/execute.c index 59cfa450a1..87b6a31162 100644 --- a/src/interfaces/odbc/execute.c +++ b/src/interfaces/odbc/execute.c @@ -431,7 +431,8 @@ FARPROC addr; // - - - - - - - - - // Returns the SQL string as modified by the driver. - +// Currently, just copy the input string without modification +// observing buffer limits and truncation. RETCODE SQL_API SQLNativeSql( HDBC hdbc, UCHAR FAR *szSqlStrIn, @@ -441,12 +442,40 @@ RETCODE SQL_API SQLNativeSql( SDWORD FAR *pcbSqlStr) { static char *func="SQLNativeSql"; +int len = 0; +char *ptr; +ConnectionClass *conn = (ConnectionClass *) hdbc; +RETCODE result; - mylog( "%s: entering...\n", func); + mylog( "%s: entering...cbSqlStrIn=%d\n", func, cbSqlStrIn); + + ptr = (cbSqlStrIn == 0) ? "" : make_string(szSqlStrIn, cbSqlStrIn, NULL); + if ( ! ptr) { + conn->errornumber = CONN_NO_MEMORY_ERROR; + conn->errormsg = "No memory available to store native sql string"; + CC_log_error(func, "", conn); + return SQL_ERROR; + } + + result = SQL_SUCCESS; + len = strlen(ptr); + + if (szSqlStr) { + strncpy_null(szSqlStr, ptr, cbSqlStrMax); + + if (len >= cbSqlStrMax) { + result = SQL_SUCCESS_WITH_INFO; + conn->errornumber = STMT_TRUNCATED; + conn->errormsg = "The buffer was too small for the result."; + } + } + + if (pcbSqlStr) + *pcbSqlStr = len; - strncpy_null(szSqlStr, szSqlStrIn, cbSqlStrMax); + free(ptr); - return SQL_SUCCESS; + return result; } // - - - - - - - - - |
