freetds AT lists.ibiblio.org
Subject: FreeTDS Development Group
List archive
- From: Craig Spannring <cts AT internetcds.com>
- To: "TDS Development Group" <freetds AT franklin.oit.unc.edu>
- Subject: Re: Does anyone know what this packet means?
- Date: Mon, 14 Sep 1998 14:33:44 -0700 (PDT)
Brian Bruns writes:
> Oh and can you send in some of the ODBC code in? I have no experience w/
> ODBC and thus have no code to base the odbc cli on whn it's time to write
> it.
The code I'm using to generate test data with is really crappy. It is
mostly just cut and paste from the MSDN example code.
#include <iostream.h>
#include <windows.h>
#include <sql.h>
#include <sqlext.h>
#define SALES_PERSON_LEN 2
#define STATUS_LEN 6
SQLSMALLINT sOrderID;
SQLSMALLINT sCustID;
DATE_STRUCT dsOpenDate;
SQLCHAR szSalesPerson[SALES_PERSON_LEN] = "D";
SQLCHAR szStatus[STATUS_LEN];
SQLINTEGER cbOrderID = 0, cbCustID = 0, cbOpenDate = 0, cbSalesPerson =
SQL_NTS,
cbStatus = SQL_NTS;
SQLRETURN retcode;
HENV henv;
HDBC hdbc;
SQLHSTMT hstmt;
static void printStatementError(HSTMT hstmt, char *msg)
{
UCHAR szSqlState[6];
UCHAR szErrorMsg[SQL_MAX_MESSAGE_LENGTH];
SDWORD dwNativeError;
SWORD wErrorMsg;
SQLError(SQL_NULL_HENV, SQL_NULL_HDBC, hstmt,
szSqlState, &dwNativeError, szErrorMsg,
SQL_MAX_MESSAGE_LENGTH-1, &wErrorMsg);
cerr << msg << "\n|"
<< szSqlState << "|\n|"
<< szErrorMsg << "|\n" << endl;
}
void main()
{
retcode = SQLAllocEnv(&henv);
if (SQLAllocConnect(henv, &hdbc) != SQL_SUCCESS)
{
UCHAR szSqlState[6];
UCHAR szErrorMsg[SQL_MAX_MESSAGE_LENGTH];
SDWORD dwNativeError;
SWORD wErrorMsg;
SQLError(henv, SQL_NULL_HDBC, SQL_NULL_HSTMT,
szSqlState, &dwNativeError, szErrorMsg,
SQL_MAX_MESSAGE_LENGTH-1, &wErrorMsg);
cerr << "problem with SQLAllocConnect\n|"
<< szSqlState << "|\n|"
<< szErrorMsg << "|\n" << endl;
exit(1);
}
retcode = SQLSetConnectOption(hdbc, SQL_ACCESS_MODE,
SQL_MODE_READ_ONLY);
if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO)
{
UCHAR szSqlState[6];
UCHAR szErrorMsg[SQL_MAX_MESSAGE_LENGTH];
SDWORD dwNativeError;
SWORD wErrorMsg;
SQLError(SQL_NULL_HENV, hdbc, SQL_NULL_HSTMT,
szSqlState, &dwNativeError, szErrorMsg,
SQL_MAX_MESSAGE_LENGTH-1, &wErrorMsg);
cerr << "problem with SQLSetConnectOption\n|"
<< szSqlState << "|\n|"
<< szErrorMsg << "|\n" << endl;
exit(1);
}
retcode = SQLSetConnectOption(hdbc, SQL_AUTOCOMMIT,
SQL_AUTOCOMMIT_ON);
if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO)
{
UCHAR szSqlState[6];
UCHAR szErrorMsg[SQL_MAX_MESSAGE_LENGTH];
SDWORD dwNativeError;
SWORD wErrorMsg;
SQLError(SQL_NULL_HENV, hdbc, SQL_NULL_HSTMT,
szSqlState, &dwNativeError, szErrorMsg,
SQL_MAX_MESSAGE_LENGTH-1, &wErrorMsg);
cerr << "problem with SQLSetConnectOption\n|"
<< szSqlState << "|\n|"
<< szErrorMsg << "|\n" << endl;
exit(1);
}
retcode = SQLConnect(hdbc,
(UCHAR *)"dsn name", SQL_NTS,
(UCHAR *)"username", SQL_NTS,
(UCHAR *)"password", SQL_NTS);
if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO)
{
UCHAR szSqlState[6];
UCHAR szErrorMsg[SQL_MAX_MESSAGE_LENGTH];
SDWORD dwNativeError;
SWORD wErrorMsg;
SQLError(SQL_NULL_HENV, hdbc, SQL_NULL_HSTMT,
szSqlState, &dwNativeError, szErrorMsg,
SQL_MAX_MESSAGE_LENGTH-1, &wErrorMsg);
cerr << "problem with SQLConnect\n|"
<< szSqlState << "|\n|"
<< szErrorMsg << "|\n" << endl;
exit(1);
}
if (SQLAllocStmt(hdbc, &hstmt)!= SQL_SUCCESS)
{
UCHAR szSqlState[6];
UCHAR szErrorMsg[SQL_MAX_MESSAGE_LENGTH];
SDWORD dwNativeError;
SWORD wErrorMsg;
SQLError(SQL_NULL_HENV, hdbc, SQL_NULL_HSTMT,
szSqlState, &dwNativeError, szErrorMsg,
SQL_MAX_MESSAGE_LENGTH-1, &wErrorMsg);
cerr << "problem with SQLAllocStmt\n|"
<< szSqlState << "|\n|"
<< szErrorMsg << "|\n" << endl;
exit(1);
}
#if 0
retcode = SQLTables(hstmt,
(unsigned char *) NULL, 0,
(unsigned char *) "%", 1,
(unsigned char *) "%", 1,
(unsigned char *)
"VIEW,TABLE", 10);
if (! (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO))
{
cout << "got table stuff" << endl;
}
else
{
printStatementError(hstmt, "SQLTable");
}
#else
/* Prepare the SQL statement with parameter markers. */
retcode = SQLPrepare(hstmt,
(unsigned char *)"select * from many_types where
(mynullableint=? "
" and mynullableint=?) or
myint=?",
SQL_NTS);
if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
{
long p1;
// char p2[256];
long p1Len = sizeof(p1);
// long p2Len;
long sAge = 1023;
long cbAge = sizeof(long);
SQLBindParameter(hstmt, 2, SQL_PARAM_INPUT, SQL_C_SLONG,
SQL_INTEGER,
0, 0, &sAge, 0, &cbAge);
// SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT, SQL_C_INT,
// SQL_CHAR, 32, 0, p1, 0, &p1Len);
SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT, SQL_C_SLONG,
SQL_INTEGER,
0, 0, &p1, 0, &p1Len);
SQLBindParameter(hstmt, 3, SQL_PARAM_INPUT, SQL_C_SLONG,
SQL_INTEGER,
0, 0, &sAge, 0, &cbAge);
// p1Len = SQL_NULL_DATA;
/* Execute statement with first row. */
p1 = 8192;
// p1[0] = '%';
// p1Len = 1;
// p2[0] = '%';
// p2Len = 1;
cout << "excecuting first statement" << endl;
retcode = SQLExecute(hstmt);
if (retcode != SQL_SUCCESS)
{
UCHAR szSqlState[6];
UCHAR szErrorMsg[SQL_MAX_MESSAGE_LENGTH];
SDWORD dwNativeError;
SWORD wErrorMsg;
SQLError(SQL_NULL_HENV, SQL_NULL_HDBC, hstmt,
szSqlState, &dwNativeError, szErrorMsg,
SQL_MAX_MESSAGE_LENGTH-1, &wErrorMsg);
cerr << "problem with SQLExecute\n|"
<< szSqlState << "|\n|"
<< szErrorMsg << "|\n" << endl;
exit(1);
}
while ((retcode = SQLFetch(hstmt)) == SQL_SUCCESS)
{
// nop
}
if (retcode != SQL_NO_DATA)
{
printStatementError(hstmt, "problem with SQLFetch");
exit(1);
}
SQLCloseCursor(hstmt);
}
#endif
cout << "Done" << endl;
return;
}
--
=======================================================================
Life is short. | Craig Spannring
Ski hard, Bike fast. | cts AT internetcds.com
--------------------------------+------------------------------------
Any sufficiently perverted technology is indistinguishable from Perl.
=======================================================================
-
Does anyone know what this packet means?,
Craig Spannring, 09/14/1998
- <Possible follow-up(s)>
- Re: Does anyone know what this packet means?, Brian Bruns, 09/14/1998
- Re: Does anyone know what this packet means?, Craig Spannring, 09/14/1998
- Re: Does anyone know what this packet means?, Craig Spannring, 09/14/1998
Archive powered by MHonArc 2.6.24.