📄 pgsqlbindparam.cpp
字号:
/* * PostgresqlBindParam object defines the needed conversion of bind parameters * Copyright (C) 2003 Johnathan Ingram, jingram@rogueware.org * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 US * */#include "pgsqlBindParam.h"#include "dbconnectTypes.h"#include "libpq-fe.h"// -----------------------------------------------------------------------------// PRIVATE:// -----------------------------------------------------------------------------// -----------------------------------------------------------------------------// PUBLIC:// -----------------------------------------------------------------------------// -----------------------------------------------------------------------------// PostgresqlBindParam::paramToPostgreSQLString// -----------------------------------------------------------------------------string PostgresqlBindParam::paramToPostgreSQLString(){ // Check if the value is null and return the appropriate null string if (!valuePtr.ptr) return "NULL"; string res; char* to; switch(type) { case BP_STRING: // Escape any funny characters in the string or binary data. // In the worse case, each character may need to be encoded as using two bytes, to = (char*)malloc(valueSize*2 +1); PQescapeString(to, valuePtr.charPtr, valueSize); res = "'"; res += to; res += "'"; free(to); break; case BP_BINARY: // Escape any funny characters in the string or binary data. // TODO: May need to use PQescapeBytea instead of PQescapeString. // In the worse case, each character may need to be encoded as using two bytes, to = (char*)malloc(valueSize*2 +1); PQescapeString(to, (const char*)valuePtr.ptr, valueSize); res = "'"; res += to; res += "'"; free(to); break; case BP_LONG: to = (char*)malloc(512); sprintf(to, DBLONG_SPRINTF, *valuePtr.longPtr); res = to; free(to); break; case BP_ULONG: to = (char*)malloc(512); sprintf(to, DBULONG_SPRINTF, *valuePtr.unsignedLongPtr); res = to; free(to); break; case BP_DOUBLE: to = (char*)malloc(512); sprintf(to, "%.25E", *valuePtr.doublePtr); // Use a precision of 25 for the conversion res = "'"; res += to; res += "'"; free(to); break; case BP_DATETIME: // 'yyyy-mm-dd hh:mm:ss' string format res = "'"; res += valuePtr.JDatePtr->asString("%Y-%m-%d %H:%M:%S"); res += "'"; break; case BP_DATE: // 'yyyy-mm-dd' string format res = "'"; res += valuePtr.JDatePtr->asString("%Y-%m-%d"); res += "'"; break; case BP_TIME: // 'hh:mm:ss' string format res = "'"; res += valuePtr.JDatePtr->asString("%H:%M:%S"); res += "'"; break; case BP_BOOLEAN: // Convert a boolean to an integer value. if (*valuePtr.boolPtr) res = "1"; else res = "0"; break; } return res;} // PostgresqlBindParam::paramToPostgreSQLString
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -