在使用C/C++、PostgreSQL连接器进行ODBC编程时,遇到了一些问题。
我只想用C/C++,ODBC把一些BLOB数据放在我的PostgreSQL中
这是我的DB表创建查询
CREATE TABLE BLOB_TEST
(
id number(20),
data BYTEA
);
这是我的密码
.
.
.
int retcode = 0;
SQLCHAR sql[1024] =
"BEGIN \n"
"insert into BLOB_TEST "
"values(9, ?); \n"
"EXCEPTION \n"
"when DUP_VAL_ON_INDEX then \n"
"dbms_output.put_line(1); \n"
"END; ";
char * temp_str = "this is a BLOB input TEST";
retcode = SQLPrepareA(hstmt, sql, SQL_NTS);
.
.
.
SQLBindParameter(hstmt,
1, /* Parameter number, starting at 1 */
SQL_PARAM_INPUT, /* in, out, inout */
SQL_C_BINARY, /* C data type of the parameter */
SQL_LONGVARBINARY, /* SQL data type of the parameter : char(8)*/
0, /* size of the column or expression, precision */
0, /* The decimal digits, scale */
temp_str, /* A pointer to a buffer for the parameter’s data */
0, /* Length of the ParameterValuePtr buffer in bytes */
NULL /* indicator */
);
.
.
.
retcode = SQLExecute(hstmt);
if (retcode == SQL_SUCCESS)
{
printf("Query Execute Success\n");
}
else
{
SQLGetDiagRecA(SQL_HANDLE_STMT, hstmt, ++rec, state, &native, message, sizeof(message), &length);
printf("%s : %ld : %ld : %s\n", state, rec, native, message);
printf("Query Execute ERROR : %d\n", retcode);
}
SQLExecute返回-1(SQL_ERROR)和错误消息如下:
末尾
我知道PostgreSQL BLOB(BYTEA)类型在使用SQLBindParameter时匹配SQL_LONGVARBINARY选项,但这会导致错误.
我准备好的查询中是否有奇怪的表达式?
或者,是否有任何方法检查值-- SQLExcute函数创建的组合查询?
我很困惑,因为我准备的查询在使用PgAdmin查询工具时工作得很好.
所以,我想检查SQLExcute函数所做的值-组合查询。
发布于 2020-11-25 23:20:56
您正在尝试在不是Oracle的数据库上运行PL/SQL块。这是怎么回事?
PostgreSQL有一个具有类似用途的DO
语句,但不能与它一起使用参数。您应该只发送INSERT
语句,并在C客户机代码中执行异常处理。
https://stackoverflow.com/questions/65016722
复制