trinh
asked on
SQLPutData example in ODBC3.0
Does anyone have success in using the example provided
under SQLPutData command of ODBC3.0 ? I've tried the
example, the return code is OK but I see nothing
updated in my SQL database. I also checked the ODBC
tracing and it indicated the operation is successful but
where does the data go ???. I also tried various
data type such as HEX, BIN and ASCII but no success.
under SQLPutData command of ODBC3.0 ? I've tried the
example, the return code is OK but I see nothing
updated in my SQL database. I also checked the ODBC
tracing and it indicated the operation is successful but
where does the data go ???. I also tried various
data type such as HEX, BIN and ASCII but no success.
SQLPutData allows an application to send data for a parameter or column to the driver at statement execution time.
This function can be used to send character or binary data values in parts to a column with a character, binary, or data source-specific data type (for example, parameters of the SQL_LONGVARBINARY or SQL_LONGVARCHAR types).
This function can be used to send character or binary data values in parts to a column with a character, binary, or data source-specific data type (for example, parameters of the SQL_LONGVARBINARY or SQL_LONGVARCHAR types).
ASKER
I am not asking for the definition of SQLPutData. I am asking
if anyone has used the example in the ODBC reference successfully.
By the way, you answer text is exact copy (word for word)
of the SQLPutData explanation summary in the reference.
if anyone has used the example in the ODBC reference successfully.
By the way, you answer text is exact copy (word for word)
of the SQLPutData explanation summary in the reference.
I'm actually using some slightly modified Sample code
to put image/text fields into a database. It works really
without problems. can you post the part of your source that uses the Putdata?
to put image/text fields into a database. It works really
without problems. can you post the part of your source that uses the Putdata?
ASKER
This is the sample source that uses the PutData statement
void main()
{
int sID;
char* Err;
int Errlen;
FILE* fp1;
if(ODBCopenconnection()){
retcode = SQLPrepare(hstmt,"INSERT INTO SPEECH (ID,AUDIO) VALUES (?,?)", SQL_NTS);
if (retcode== SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
{
SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT, SQL_C_ULONG, SQL_INTEGER, 0,0,&sID,0, &cbsID);
SQLBindParameter(hstmt, 2, SQL_PARAM_INPUT, SQL_C_BINARY, SQL_LONGVARBINARY,0,0,(SQL POINTER) 2,0, &cbbin);
cbbin = SQL_LEN_DATA_AT_EXEC(0);
sID = 10;// hardcoded for testing
retcode = SQLExecute(hstmt);
while(retcode == SQL_NEED_DATA){
retcode = SQLParamData(hstmt, &ptoken);
if (retcode == SQL_NEED_DATA) {
fp1 = InitUserData((SQLSMALLINT) ptoken);
while(GetUserData(fp1, (SQLSMALLINT)ptoken,Data,& cbData)){
retcode = SQLPutData(hstmt,Data,cbDa ta);
if (retcode== SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
printf("successfull put data into DB\n");
else {
SQLGetDiagRec(SQL_HANDLE_S TMT,hstmt, 1,Err,0,0, 1024,&Errl en);
printf("error code:%s\n",Err);
}
}
}
}
}
ODBCcloseconnection();
}
else {
printf("Something unknown happened\n");
exit(-1);
}
}
FILE* InitUserData(SQLSMALLINT Ptoken) {
FILE* fp;
if (Ptoken == 2){ // parmameter 2
printf("open the file\n");
fp = fopen("audio.bin","rb"); // this is the binary data
return (fp);
}
}
int GetUserData(FILE* fp1,SQLSMALLINT Ptoken,char* Data,int* cbD){
if (Ptoken == 2) {
memset(Data,0,sizeof(Data) );
*cbD = fread(Data,sizeof(char),MA X_DATA_LEN ,fp1);
if(cbD == 0){
fclose(fp1);
return (TRUE);
}
}
return (FALSE);
}
void main()
{
int sID;
char* Err;
int Errlen;
FILE* fp1;
if(ODBCopenconnection()){
retcode = SQLPrepare(hstmt,"INSERT INTO SPEECH (ID,AUDIO) VALUES (?,?)", SQL_NTS);
if (retcode== SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
{
SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT, SQL_C_ULONG, SQL_INTEGER, 0,0,&sID,0, &cbsID);
SQLBindParameter(hstmt, 2, SQL_PARAM_INPUT, SQL_C_BINARY, SQL_LONGVARBINARY,0,0,(SQL
cbbin = SQL_LEN_DATA_AT_EXEC(0);
sID = 10;// hardcoded for testing
retcode = SQLExecute(hstmt);
while(retcode == SQL_NEED_DATA){
retcode = SQLParamData(hstmt, &ptoken);
if (retcode == SQL_NEED_DATA) {
fp1 = InitUserData((SQLSMALLINT)
while(GetUserData(fp1, (SQLSMALLINT)ptoken,Data,&
retcode = SQLPutData(hstmt,Data,cbDa
if (retcode== SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
printf("successfull put data into DB\n");
else {
SQLGetDiagRec(SQL_HANDLE_S
printf("error code:%s\n",Err);
}
}
}
}
}
ODBCcloseconnection();
}
else {
printf("Something unknown happened\n");
exit(-1);
}
}
FILE* InitUserData(SQLSMALLINT Ptoken) {
FILE* fp;
if (Ptoken == 2){ // parmameter 2
printf("open the file\n");
fp = fopen("audio.bin","rb"); // this is the binary data
return (fp);
}
}
int GetUserData(FILE* fp1,SQLSMALLINT Ptoken,char* Data,int* cbD){
if (Ptoken == 2) {
memset(Data,0,sizeof(Data)
*cbD = fread(Data,sizeof(char),MA
if(cbD == 0){
fclose(fp1);
return (TRUE);
}
}
return (FALSE);
}
This might be totally redundant but just curious..because I have seen this happening when I try to execute DML statements from Access to SQL Server(using a ODBC DSN). It would not allow me to do any DML against any backend table till you have a primary key on the backend table or atleast an index. So try this..just in case it is not already there. Create a Primary key or index on the backend table and execute SQLPutData.
ASKER
The index on the backend table was in fact created but
it still doesn't work.
it still doesn't work.
Is the Table replicated? If yes is the size of the data you
try to put > 'max text repl size' (sp_configure)? If yes set it to a bigger value :)
exec sp_configure 'max text repl size',xxxx
reconfigure
oh and btw .. You cannot see TEXT/IMAGE field in Access, unless you fill in an OLE-Object .)
try to put > 'max text repl size' (sp_configure)? If yes set it to a bigger value :)
exec sp_configure 'max text repl size',xxxx
reconfigure
oh and btw .. You cannot see TEXT/IMAGE field in Access, unless you fill in an OLE-Object .)
ASKER
I am not sure if you answer my question since I don't
use Access. I am using SQLServer Database. Beside
the IMAGE field in the table is capable of storing upto
2Giga bytes of information while I am trying to
put in only 1 byte and it doesn't work. Thanks for
the comments but it's totally useless.
use Access. I am using SQLServer Database. Beside
the IMAGE field in the table is capable of storing upto
2Giga bytes of information while I am trying to
put in only 1 byte and it doesn't work. Thanks for
the comments but it's totally useless.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER