Hi,
I am using SAP DB version 7.3 (Kernel 7.3.0 Build 025.000.085.923) and ODBC
Diver 7.3 (7.3.0.28).
I do the following: (see file attached)
1) I create table testtable (i integer default 10)
2) I try to insert NULL into this table using SQL statement via ODBC.
If I use:
insert into testtable (i) values (NULL)
everithing works fine.
But if I try to bind parameter
insert into testtable (i) values (?)
and to set to this parameter to SQL_NULL_DATA
I receive error: [SAP AG][SQLOD32 DLL]Integrity constraint violation
What integrity constraint is violated?
This is error in ODBC Driver or in SQL DB server because I do not set "not
null" attribute to this column.
I attach a small program (SAPDBDefaultNull.c) which shows this problem.
Milen Manev
--
+++ GMX - Mail, Messaging & more http://www.gmx.net +++
NEU: Mit GMX ins Internet. Rund um die Uhr f�r 1 ct/ Min. surfen!
#include <windows.h>
#include <sql.h>
#include <sqlext.h>
#include <stdio.h>
HENV hEnv = NULL;
HDBC hDbc = NULL;
HSTMT hStmt = NULL;
SQLCHAR sqlstate[SQL_SQLSTATE_SIZE];
SQLCHAR errmsg[SQL_MAX_MESSAGE_LENGTH];
SQLINTEGER native_err;
void CheckForError(RETCODE rc)
{
if (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO)
return;
while ( SQL_NO_DATA_FOUND !=
SQLError ( hEnv, hDbc, hStmt, sqlstate,
&native_err, errmsg,
SQL_MAX_MESSAGE_LENGTH - 1, NULL
)
)
{
printf("%s", errmsg);
};
}
main()
{
SQLINTEGER lValue = 0, lIndicator = 0;
CheckForError(SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &hEnv));
CheckForError(SQLSetEnvAttr(hEnv, SQL_ATTR_ODBC_VERSION, (void *)SQL_OV_ODBC3,
SQL_IS_INTEGER));
CheckForError(SQLAllocHandle(SQL_HANDLE_DBC, hEnv, &hDbc));
CheckForError(SQLDriverConnect(hDbc,
NULL,
(SQLCHAR *)"Driver={SAP DB
7.3};ServerNode=localhost;ServerDB=tst;UID=dba;PWD=dba",
SQL_NTS,
NULL,
0,
NULL,
SQL_DRIVER_COMPLETE
)
);
CheckForError(SQLAllocHandle(SQL_HANDLE_STMT, hDbc, &hStmt));
CheckForError(SQLExecDirect(hStmt, (SQLCHAR *)"create table testtable(i integer
default 10)", SQL_NTS));
CheckForError(SQLPrepare(hStmt, (SQLCHAR *)"insert into testtable (i) values (?)",
SQL_NTS));
CheckForError(SQLBindParameter(hStmt, 1, SQL_PARAM_INPUT, SQL_C_ULONG, SQL_INTEGER,
10, 0, &lValue, 0, &lIndicator));
lIndicator = SQL_NULL_DATA;
CheckForError(SQLExecute(hStmt));
CheckForError(SQLExecDirect(hStmt, (SQLCHAR *)"drop table testtable", SQL_NTS));
return 0;
}