PQexecPrepared 插入的值不是我输入的值
时间:2009-05-11
来源:互联网
关键代码如下:
char sql[256];
sprintf(sql, "insert into table1(intId, indexId, double1, double2) values($1,$2,$3,$4)");
Oid types[4] = { 23, 23, 701, 701 };
PQprepare(con, "insert_table1", sql, sizeof(types)/sizeof(Oid), types);
int paramLengths[4] = { sizeof(int), sizeof(int), sizeof(double), sizeof(double)};
int paramFormats[4] = { 1, 1, 1, 1};
int iParam[2];
double paramBuffer[2];
char * paramValues[4] = { (char*)&iParam[0], (char*)&iParam[1], (char*)¶mBuffer[0], (char*)¶mBuffer[1]};
loop(i)...{
iParam[0] = i + 10;
iParam[1] = 1;
paramBuffer[0] = doublex1;
paramBuffer[1] = doublex2;
PQexecPrepared( con, "insert_table1", sizeof(paramValues)/sizeof(char *), paramValues, paramLengths, paramFormats, 0);
...
}
作者: Jazzlover 发布时间: 2009-05-11
作者: wwwwb 发布时间: 2009-05-11
作者: Jazzlover 发布时间: 2009-05-11
楼主,检查一下你的数据类型。你传的是数字还是char ?
char * paramValues[4] = { (char*)&iParam[0], (char*)&iParam[1], (char*)¶mBuffer[0], (char*)¶mBuffer[1]};
很显然: 16777216 = 0x1000000
[color=#FFFFFF][/color]
作者: ACMAIN_CHM 发布时间: 2009-05-11
你将
完整的SQL语句显示出来看看
作者: WWWWA 发布时间: 2009-05-11
毛病就是ACMAIN_CHM 所说的那样,改成下列形式试试:
char * paramValues[4] = {"1", "1", "1.0", "1.0"};
作者: zxb0412 发布时间: 2009-10-31
Submits a command to the server and waits for the result, with the ability to pass parameters separately from the SQL command text.
PGresult *PQexecParams(PGconn *conn,
const char *command,
int nParams,
const Oid *paramTypes,
const char * const *paramValues,
const int *paramLengths,
const int *paramFormats,
int resultFormat);
PQexecParams is like PQexec, but offers additional functionality: parameter values can be specified separately from the command string proper, and query results can be requested in either text or binary format. PQexecParams is supported only in protocol 3.0 and later connections; it will fail when using protocol 2.0.
The function arguments are:
conn
The connection object to send the command through.
command
The SQL command string to be executed. If parameters are used, they are referred to in the command string as $1, $2, etc.
nParams
The number of parameters supplied; it is the length of the arrays paramTypes[], paramValues[], paramLengths[], and paramFormats[]. (The array pointers can be NULL when nParams is zero.)
paramTypes[]
Specifies, by OID, the data types to be assigned to the parameter symbols. If paramTypes is NULL, or any particular element in the array is zero, the server infers a data type for the parameter symbol in the same way it would do for an untyped literal string.
paramValues[]
Specifies the actual values of the parameters. A null pointer in this array means the corresponding parameter is null; otherwise the pointer points to a zero-terminated text string (for text format) or binary data in the format expected by the server (for binary format).
paramLengths[]
Specifies the actual data lengths of binary-format parameters. It is ignored for null parameters and text-format parameters. The array pointer can be null when there are no binary parameters.
paramFormats[]
Specifies whether parameters are text (put a zero in the array entry for the corresponding parameter) or binary (put a one in the array entry for the corresponding parameter). If the array pointer is null then all parameters are presumed to be text strings.
Values passed in binary format require knowledge of the internal representation expected by the backend. For example, integers must be passed in network byte order. Passing numeric values requires knowledge of the server storage format, as implemented in src/backend/utils/adt/numeric.c::numeric_send() and src/backend/utils/adt/numeric.c::numeric_recv().
resultFormat
Specify zero to obtain results in text format, or one to obtain results in binary format. (There is not currently a provision to obtain different result columns in different formats, although that is possible in the underlying protocol.)
作者: tigeroar 发布时间: 2011-09-08
作者: tigeroar 发布时间: 2011-09-08
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28