Use SPRINTF_FIXED() or SPRINTFCAT_FIXED() where they are available.
int errnum = CC_get_errornumber(self);
BOOL cmd_success;
- snprintf(query, sizeof(query), "set client_encoding to '%s'", encoding);
+ SPRINTF_FIXED(query, "set client_encoding to '%s'", encoding);
res = CC_send_query(self, query, NULL, IGNORE_ABORT_ON_CONN | ROLLBACK_ON_ERROR, NULL);
cmd_success = QR_command_maybe_successful(res);
QR_Destructor(res);
if (QR_needs_survival_check(res))
{
- snprintf(cmd, sizeof(cmd), "MOVE 0 in \"%s\"", QR_get_cursor(res));
+ SPRINTF_FIXED(cmd, "MOVE 0 in \"%s\"", QR_get_cursor(res));
CONNLOCK_RELEASE(self);
wres = CC_send_query(self, cmd, NULL, ROLLBACK_ON_ERROR | IGNORE_ABORT_ON_CONN, NULL);
QR_set_no_survival_check(res);
query_buf[0] = '\0';
if (issue_begin)
{
- snprintf_add(query_buf, query_buf_len, "%s;", bgncmd);
+ snprintfcat(query_buf, query_buf_len, "%s;", bgncmd);
discard_next_begin = TRUE;
}
if (query_rollback)
{
- snprintf_add(query_buf, query_buf_len, "%s %s;", svpcmd, per_query_svp);
+ snprintfcat(query_buf, query_buf_len, "%s %s;", svpcmd, per_query_svp);
discard_next_savepoint = TRUE;
}
strlcat(query_buf, query, query_buf_len);
if (appendq)
{
- snprintf_add(query_buf, query_buf_len, ";%s", appendq);
+ snprintfcat(query_buf, query_buf_len, ";%s", appendq);
}
if (query_rollback)
{
- snprintf_add(query_buf, query_buf_len, ";%s %s", rlscmd, per_query_svp);
+ snprintfcat(query_buf, query_buf_len, ";%s %s", rlscmd, per_query_svp);
}
/* Set up notice receiver */
if (CC_is_in_error_trans(self))
{
char tmpsqlbuf[100];
- snprintf(tmpsqlbuf, sizeof(tmpsqlbuf),
+ SPRINTF_FIXED(tmpsqlbuf,
"%s TO %s; %s %s",
rbkcmd, per_query_svp,
rlscmd, per_query_svp);
#define return DONT_CALL_RETURN_FROM_HERE???
ENTER_INNER_CONN_CS(self, func_cs_count);
- snprintf(sqlbuffer, sizeof(sqlbuffer), "SELECT pg_catalog.%s%s", fn_name,
+ SPRINTF_FIXED(sqlbuffer, "SELECT pg_catalog.%s%s", fn_name,
func_param_str[nargs]);
for (i = 0; i < nargs; ++i)
{
{
pname = conn->discardp[i];
if ('s' == pname[0])
- snprintf(cmd, sizeof(cmd), "DEALLOCATE \"%s\"", pname + 1);
+ SPRINTF_FIXED(cmd, "DEALLOCATE \"%s\"", pname + 1);
else
- snprintf(cmd, sizeof(cmd), "CLOSE \"%s\"", pname + 1);
+ SPRINTF_FIXED(cmd, "CLOSE \"%s\"", pname + 1);
res = CC_send_query(conn, cmd, NULL, ROLLBACK_ON_ERROR | IGNORE_ABORT_ON_CONN, NULL);
QR_Destructor(res);
free(conn->discardp[i]);
char emsg[200];
if (errmsg != NULL)
- snprintf(emsg, sizeof(emsg), "libpq connection parameter error:%s", errmsg);
+ SPRINTF_FIXED(emsg, "libpq connection parameter error:%s", errmsg);
else
STRCPY_FIXED(emsg, "memory error? in PQconninfoParse");
CC_set_error(self, CONN_OPENDB_ERROR, emsg, func);
if (vals[j] != NULL && strcmp(vals[j], val) == 0)
continue;
- snprintf(emsg, sizeof(emsg), "%s parameter in pqopt option conflicts with other ordinary option", keyword);
+ SPRINTF_FIXED(emsg, "%s parameter in pqopt option conflicts with other ordinary option", keyword);
CC_set_error(self, CONN_OPENDB_ERROR, emsg, func);
goto cleanup;
}
{
size_t length = (len > 0) ? len : strlen(s);
- snprintf_add(buf, buflen, fmt, length, s);
+ snprintfcat(buf, buflen, fmt, length, s);
return buf;
}
return NULL;
ssize_t length = strlen(s);
if (s1)
- snprintf_add(buf, buflen, fmt, s1, length, s);
+ snprintfcat(buf, buflen, fmt, s1, length, s);
else
- snprintf_add(buf, buflen, fmt, length, s);
+ snprintfcat(buf, buflen, fmt, length, s);
return buf;
}
return NULL;
switch (operation)
{
case PREPARE_TRANSACTION:
- snprintf(cmd, sizeof(cmd), "PREPARE TRANSACTION '%s'", gxid);
+ SPRINTF_FIXED(cmd, "PREPARE TRANSACTION '%s'", gxid);
break;
case COMMIT_PREPARED:
- snprintf(cmd, sizeof(cmd), "COMMIT PREPARED '%s'", gxid);
+ SPRINTF_FIXED(cmd, "COMMIT PREPARED '%s'", gxid);
break;
case ROLLBACK_PREPARED:
- snprintf(cmd, sizeof(cmd), "ROLLBACK PREPARED '%s'", gxid);
+ SPRINTF_FIXED(cmd, "ROLLBACK PREPARED '%s'", gxid);
break;
}
}
if (precision > 0 && st->fr)
{
- snprintf(precstr, sizeof(precstr), ".%09d", st->fr);
+ SPRINTF_FIXED(precstr, ".%09d", st->fr);
if (precision < 9)
precstr[precision + 1] = '\0';
else if (precision > 9)
zoneint -= 3600;
}
if (zoneint > 0)
- snprintf(zonestr, sizeof(zonestr), "-%02d", (int) zoneint / 3600);
+ SPRINTF_FIXED(zonestr, "-%02d", (int) zoneint / 3600);
else
- snprintf(zonestr, sizeof(zonestr), "+%02d", -(int) zoneint / 3600);
+ SPRINTF_FIXED(zonestr, "+%02d", -(int) zoneint / 3600);
}
#endif /* TIMEZONE_GLOBAL */
if (st->y < 0)
switch (field_type)
{
case PG_TYPE_DATE:
- len = snprintf(midtemp, midsize, "%.4d-%.2d-%.2d", std_time.y, std_time.m, std_time.d);
+ len = SPRINTF_FIXED(midtemp, "%.4d-%.2d-%.2d", std_time.y, std_time.m, std_time.d);
break;
case PG_TYPE_TIME:
- len = snprintf(midtemp, midsize, "%.2d:%.2d:%.2d", std_time.hh, std_time.mm, std_time.ss);
+ len = SPRINTF_FIXED(midtemp, "%.2d:%.2d:%.2d", std_time.hh, std_time.mm, std_time.ss);
if (std_time.fr > 0)
{
int wdt;
int fr = effective_fraction(std_time.fr, &wdt);
- len = snprintf(midtemp, midsize, "%s.%0*d", midtemp, wdt, fr);
+ len = SPRINTF_FIXED(midtemp, "%s.%0*d", midtemp, wdt, fr);
}
break;
}
if (SC_is_fetchcursor(stmt))
{
- snprintf_add(new_statement, qb->str_alsize,
+ snprintfcat(new_statement, qb->str_alsize,
"declare \"%s\"%s cursor%s for ",
SC_cursor_name(stmt), opt_scroll, opt_hold);
qb->npos = strlen(new_statement);
fraction /= 10;
prec--;
}
- snprintf_add(param_string, sizeof(param_string), ".%0*d", prec, fraction);
+ SPRINTFCAT_FIXED(param_string, ".%0*d", prec, fraction);
}
break;
case SQL_C_GUID:
* "unsigned int" on others.
*/
SQLGUID *g = (SQLGUID *) buffer;
- snprintf (param_string, sizeof(param_string),
+ SPRINTF_FIXED (param_string,
"%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X",
(unsigned int) g->Data1,
g->Data2, g->Data3,
if (!send_buf)
{
/* it was date,time,timestamp -- use m,d,y,hh,mm,ss */
- snprintf(tmp, sizeof(tmp), "%.4d-%.2d-%.2d %.2d:%.2d:%.2d",
+ SPRINTF_FIXED(tmp, "%.4d-%.2d-%.2d %.2d:%.2d:%.2d",
st.y, st.m, st.d, st.hh, st.mm, st.ss);
send_buf = tmp;
used = SQL_NTS;
{
/* Literal; return the escape part adding type cast */
F_ExtractOldTo(qp, buf_small, ODBC_ESCAPE_END, sizeof(buf_small));
- prtlen = snprintf(buf, sizeof(buf), "%s::date", buf_small);
+ prtlen = SPRINTF_FIXED(buf, "%s::date", buf_small);
CVT_APPEND_DATA(qb, buf, prtlen);
retval = QB_append_space_to_separate_identifiers(qb, qp);
}
{
/* Literal; return the escape part adding type cast */
F_ExtractOldTo(qp, buf_small, ODBC_ESCAPE_END, sizeof(buf_small));
- prtlen = snprintf(buf, sizeof(buf), "%s::time", buf_small);
+ prtlen = SPRINTF_FIXED(buf, "%s::time", buf_small);
CVT_APPEND_DATA(qb, buf, prtlen);
retval = QB_append_space_to_separate_identifiers(qb, qp);
}
{
/* Literal; return the escape part adding type cast */
F_ExtractOldTo(qp, buf_small, ODBC_ESCAPE_END, sizeof(buf_small));
- prtlen = snprintf(buf, sizeof(buf), "%s::timestamp", buf_small);
+ prtlen = SPRINTF_FIXED(buf, "%s::timestamp", buf_small);
CVT_APPEND_DATA(qb, buf, prtlen);
retval = QB_append_space_to_separate_identifiers(qb, qp);
}
{
/* Literal; return the escape part adding type cast */
F_ExtractOldTo(qp, buf_small, ODBC_ESCAPE_END, sizeof(buf_small));
- prtlen = snprintf(buf, sizeof(buf), "%s %s", key, buf_small);
+ prtlen = SPRINTF_FIXED(buf, "%s %s", key, buf_small);
CVT_APPEND_DATA(qb, buf, prtlen);
retval = QB_append_space_to_separate_identifiers(qb, qp);
}
if (ci->keepalive_interval >= 0)
{
if (abbrev)
- snprintf_add(buf, buflen, ABBR_KEEPALIVEINTERVAL "=%u;", ci->keepalive_interval);
+ snprintfcat(buf, buflen, ABBR_KEEPALIVEINTERVAL "=%u;", ci->keepalive_interval);
else
- snprintf_add(buf, buflen, INI_KEEPALIVEINTERVAL "=%u;", ci->keepalive_interval);
+ snprintfcat(buf, buflen, INI_KEEPALIVEINTERVAL "=%u;", ci->keepalive_interval);
}
return target;
}
char protocol_and[16];
if (ci->rollback_on_error >= 0)
- snprintf(protocol_and, sizeof(protocol_and), "7.4-%d", ci->rollback_on_error);
+ SPRINTF_FIXED(protocol_and, "7.4-%d", ci->rollback_on_error);
else
STRCPY_FIXED(protocol_and, "7.4");
olen = snprintf(&connect_string[hlen], nlen, ";"
ODBC_INI);
if (ci->rollback_on_error >= 0)
- snprintf(temp, sizeof(temp), "7.4-%d", ci->rollback_on_error);
+ SPRINTF_FIXED(temp, "7.4-%d", ci->rollback_on_error);
else
STRCPY_FIXED(temp, NULL_STRING);
SQLWritePrivateProfileString(DSN,
INI_INT8AS,
temp,
ODBC_INI);
- snprintf(temp, sizeof(temp), "%x", getExtraOptions(ci));
+ SPRINTF_FIXED(temp, "%x", getExtraOptions(ci));
SQLWritePrivateProfileString(DSN,
INI_EXTRAOPTIONS,
temp,
if (need_savep)
{
SPRINTF_FIXED(esavepoint, "_EXEC_SVP_%p", stmt);
- snprintf(cmd, sizeof(cmd), "SAVEPOINT %s", esavepoint);
+ SPRINTF_FIXED(cmd, "SAVEPOINT %s", esavepoint);
res = CC_send_query(conn, cmd, NULL, 0, NULL);
if (QR_command_maybe_successful(res))
{
{
if (SC_started_rbpoint(stmt))
{
- snprintf(cmd, sizeof(cmd), "ROLLBACK to %s", esavepoint);
+ SPRINTF_FIXED(cmd, "ROLLBACK to %s", esavepoint);
res = CC_send_query(conn, cmd, NULL, IGNORE_ABORT_ON_CONN, NULL);
cmd_success = QR_command_maybe_successful(res);
QR_Destructor(res);
inolog("ret=%d\n", ret);
if (SQL_NEED_DATA != ret && SC_started_rbpoint(stmt))
{
- snprintf(cmd, sizeof(cmd), "RELEASE %s", esavepoint);
+ SPRINTF_FIXED(cmd, "RELEASE %s", esavepoint);
res = CC_send_query(conn, cmd, NULL, IGNORE_ABORT_ON_CONN, NULL);
cmd_success = QR_command_maybe_successful(res);
QR_Destructor(res);
*/
/* version number to the dbms version string */
/*
- snprintf(tmp, sizeof(tmp) - 1, "%s %s", POSTGRESDRIVERVERSION, conn->pg_version);
+ SPRINTF_FIXED(tmp, "%s %s", POSTGRESDRIVERVERSION, conn->pg_version);
tmp[sizeof(tmp) - 1] = '\0'; */
if (CC_fake_mss(conn))
p = "09.00.1399";
break;
case SQL_DRIVER_ODBC_VER:
- snprintf(odbcver, sizeof(odbcver), "%02x.%02x", ODBCVER / 256, ODBCVER % 256);
+ SPRINTF_FIXED(odbcver, "%02x.%02x", ODBCVER / 256, ODBCVER % 256);
/* p = DRIVER_ODBC_VER; */
p = odbcver;
break;
{
schema_strcat1(tables_query, sizeof(tables_query), " and nspname %s'%.*s'", op_string, escSchemaName, szTableName, cbTableName, conn);
if (IS_VALID_NAME(escTableName))
- snprintf_add(tables_query, sizeof(tables_query),
+ SPRINTFCAT_FIXED(tables_query,
" and relname %s'%s'", op_string, escTableName);
}
* have the atttypmod field)
*/
op_string = gen_opestr(like_or_eq, conn);
- snprintf(columns_query, sizeof(columns_query),
+ SPRINTF_FIXED(columns_query,
"select n.nspname, c.relname, a.attname, a.atttypid, "
"t.typname, a.attnum, a.attlen, a.atttypmod, a.attnotnull, "
"c.relhasrules, c.relkind, c.oid, pg_get_expr(d.adbin, d.adrelid), "
"from (((pg_catalog.pg_class c "
"inner join pg_catalog.pg_namespace n on n.oid = c.relnamespace");
if (search_by_ids)
- snprintf_add(columns_query, sizeof(columns_query), " and c.oid = %u", reloid);
+ SPRINTFCAT_FIXED(columns_query, " and c.oid = %u", reloid);
else
{
if (escTableName)
- snprintf_add(columns_query, sizeof(columns_query), " and c.relname %s'%s'", op_string, escTableName);
+ SPRINTFCAT_FIXED(columns_query, " and c.relname %s'%s'", op_string, escTableName);
schema_strcat1(columns_query, sizeof(columns_query), " and n.nspname %s'%.*s'", op_string, escSchemaName, szTableName, cbTableName, conn);
}
STRCAT_FIXED(columns_query, ") inner join pg_catalog.pg_attribute a"
if (search_by_ids)
{
if (attnum != 0)
- snprintf_add(columns_query, sizeof(columns_query), " and a.attnum = %d", attnum);
+ SPRINTFCAT_FIXED(columns_query, " and a.attnum = %d", attnum);
}
else if (escColumnName)
- snprintf_add(columns_query, sizeof(columns_query), " and a.attname %s'%s'", op_string, escColumnName);
+ SPRINTFCAT_FIXED(columns_query, " and a.attname %s'%s'", op_string, escColumnName);
STRCAT_FIXED(columns_query,
" and a.attrelid = c.oid) inner join pg_catalog.pg_type t"
" on t.oid = a.atttypid) left outer join pg_attrdef d"
{
char tmp[32];
- snprintf(tmp, sizeof(tmp), "%s identity", field_type_name);
+ SPRINTF_FIXED(tmp, "%s identity", field_type_name);
set_tuplefield_string(&tuple[COLUMNS_TYPE_NAME], tmp);
break;
}
/* TableName cannot contain a string search pattern */
if (escTableName)
- snprintf_add(columns_query, sizeof(columns_query),
+ SPRINTFCAT_FIXED(columns_query,
" and c.relname %s'%s'", eq_string, escTableName);
/* SchemaName cannot contain a string search pattern */
schema_strcat1(columns_query, sizeof(columns_query), " and u.nspname %s'%.*s'", eq_string, escSchemaName, szTableName, cbTableName, conn);
escTableName = simpleCatalogEscape((SQLCHAR *) table_name, SQL_NTS, conn);
eq_string = gen_opestr(eqop, conn);
escSchemaName = simpleCatalogEscape((SQLCHAR *) table_schemaname, SQL_NTS, conn);
- snprintf(index_query, sizeof(index_query), "select c.relname, i.indkey, i.indisunique"
+ SPRINTF_FIXED(index_query, "select c.relname, i.indkey, i.indisunique"
", i.indisclustered, a.amname, c.relhasrules, n.nspname"
", c.oid, d.relhasoids, %s"
" from pg_catalog.pg_index i, pg_catalog.pg_class c,"
/* no index qualifier */
set_tuplefield_string(&tuple[STATS_INDEX_QUALIFIER], GET_SCHEMA_NAME(table_schemaname));
- snprintf(buf, sizeof(buf), "%s_idx_fake_oid", table_name);
+ SPRINTF_FIXED(buf, "%s_idx_fake_oid", table_name);
set_tuplefield_string(&tuple[STATS_INDEX_NAME], buf);
/*
QResultClass *res;
- snprintf(cmd, sizeof(cmd), "select pg_get_indexdef(%u, %d, true)", ioid, i);
+ SPRINTF_FIXED(cmd, "select pg_get_indexdef(%u, %d, true)", ioid, i);
res = CC_send_query(conn, cmd, NULL, IGNORE_ABORT_ON_CONN, stmt);
if (QR_command_maybe_successful(res))
set_tuplefield_string(&tuple[STATS_COLUMN_NAME], QR_get_value_backend_text(res, 0, 0));
else
snprintf(tbqry, tsize, " where tc.oid = %u", reloid);
- strlcat(tables_query,
+ STRCAT_FIXED(tables_query,
" AND tc.oid = i.indrelid"
" AND n.oid = tc.relnamespace"
" AND i.indisprimary = 't'"
" AND (NOT ta.attisdropped)"
" AND (NOT ia.attisdropped)"
" AND ic.oid = i.indexrelid"
- " order by ia.attnum"
- , sizeof(tables_query));
+ " order by ia.attnum");
break;
case 2:
/*
* Simplified query to search old fashoned primary key
*/
- snprintf(tables_query, sizeof(tables_query), "select ta.attname, ia.attnum, ic.relname, n.nspname, NULL"
+ SPRINTF_FIXED(tables_query, "select ta.attname, ia.attnum, ic.relname, n.nspname, NULL"
" from pg_catalog.pg_attribute ta,"
" pg_catalog.pg_attribute ia, pg_catalog.pg_class ic,"
" pg_catalog.pg_index i, pg_catalog.pg_namespace n"
}
if (!conn->server_encoding)
return ret;
- snprintf(query, sizeof(query), "SET CLIENT_ENCODING TO '%s'", conn->server_encoding);
+ SPRINTF_FIXED(query, "SET CLIENT_ENCODING TO '%s'", conn->server_encoding);
bError = (!QR_command_maybe_successful((res = CC_send_query(conn, query, NULL, flag, NULL))));
QR_Destructor(res);
eq_string = gen_opestr(eqop, conn);
if (!bError && continueExec)
{
- snprintf(query, sizeof(query), "select attnum from pg_attribute "
+ SPRINTF_FIXED(query, "select attnum from pg_attribute "
"where attrelid = %u and attname %s'%s'",
relid, eq_string, serverColumnName);
if (res = CC_send_query(conn, query, NULL, flag, NULL), QR_command_maybe_successful(res))
}
continueExec = (continueExec && !bError);
/* restore the cleint encoding */
- snprintf(query, sizeof(query), "SET CLIENT_ENCODING TO '%s'", conn->original_client_encoding);
+ SPRINTF_FIXED(query, "SET CLIENT_ENCODING TO '%s'", conn->original_client_encoding);
bError = (!QR_command_maybe_successful((res = CC_send_query(conn, query, NULL, flag, NULL))));
QR_Destructor(res);
if (bError || !continueExec)
return ret;
- snprintf(query, sizeof(query), "select attname from pg_attribute where attrelid = %u and attnum = %s", relid, saveattnum);
+ SPRINTF_FIXED(query, "select attname from pg_attribute where attrelid = %u and attnum = %s", relid, saveattnum);
if (res = CC_send_query(conn, query, NULL, flag, NULL), QR_command_maybe_successful(res))
{
if (QR_get_num_cached_tuples(res) > 0)
escFkTableName = simpleCatalogEscape((SQLCHAR *) fk_table_needed, SQL_NTS, conn);
schema_strcat(schema_needed, sizeof(schema_needed), "%.*s", szFkTableOwner, cbFkTableOwner, szFkTableName, cbFkTableName, conn);
escSchemaName = simpleCatalogEscape((SQLCHAR *) schema_needed, SQL_NTS, conn);
- snprintf(tables_query, sizeof(tables_query), "SELECT pt.tgargs, "
+ SPRINTF_FIXED(tables_query, "SELECT pt.tgargs, "
" pt.tgnargs, "
" pt.tgdeferrable, "
" pt.tginitdeferred, "
escPkTableName = simpleCatalogEscape((SQLCHAR *) pk_table_needed, SQL_NTS, conn);
schema_strcat(schema_needed, sizeof(schema_needed), "%.*s", szPkTableOwner, cbPkTableOwner, szPkTableName, cbPkTableName, conn);
escSchemaName = simpleCatalogEscape((SQLCHAR *) schema_needed, SQL_NTS, conn);
- snprintf(tables_query, sizeof(tables_query), "SELECT pt.tgargs, "
+ SPRINTF_FIXED(tables_query, "SELECT pt.tgargs, "
" pt.tgnargs, "
" pt.tgdeferrable, "
" pt.tginitdeferred, "
" p.pronamespace = n.oid and"
" (not proretset) and");
#endif /* PRORET_COUNT */
- snprintf_add(proc_query, sizeof(proc_query),
+ SPRINTFCAT_FIXED(proc_query,
" has_function_privilege(p.oid, 'EXECUTE')");
if (IS_VALID_NAME(escSchemaName))
- snprintf_add(proc_query, sizeof(proc_query),
+ SPRINTFCAT_FIXED(proc_query,
" and nspname %s'%s'",
op_string, escSchemaName);
if (escProcName)
- snprintf_add(proc_query, sizeof(proc_query),
+ SPRINTFCAT_FIXED(proc_query,
" and proname %s'%s'", op_string, escProcName);
- snprintf_add(proc_query, sizeof(proc_query),
+ SPRINTFCAT_FIXED(proc_query,
" order by nspname, proname, p.oid, attnum");
if (escSchemaName)
" where pg_proc.pronamespace = pg_namespace.oid");
schema_strcat1(proc_query, sizeof(proc_query), " and nspname %s'%.*s'", op_string, escSchemaName, szProcName, cbProcName, conn);
if (IS_VALID_NAME(escProcName))
- snprintf_add(proc_query, sizeof(proc_query),
+ SPRINTFCAT_FIXED(proc_query,
" and proname %s'%s'", op_string, escProcName);
res = CC_send_query(conn, proc_query, NULL, IGNORE_ABORT_ON_CONN, stmt);
schema_strcat1(proc_query, sizeof(proc_query), " nspname %s'%.*s' and", op_string, escSchemaName, szTableName, cbTableName, conn);
if (escTableName)
- snprintf_add(proc_query, sizeof(proc_query), " relname %s'%s' and", op_string, escTableName);
+ SPRINTFCAT_FIXED(proc_query, " relname %s'%s' and", op_string, escTableName);
STRCAT_FIXED(proc_query, " pg_namespace.oid = relnamespace and relkind in ('r', 'v') and");
if ((!escTableName) && (!escSchemaName))
STRCAT_FIXED(proc_query, " nspname not in ('pg_catalog', 'information_schema') and");
int i;
char *grolist, *uid, *delm;
- snprintf(proc_query, sizeof(proc_query) - 1, "select grolist from pg_group where groname = '%s'", user);
+ SPRINTF_FIXED(proc_query, "select grolist from pg_group where groname = '%s'", user);
if (gres = CC_send_query(conn, proc_query, NULL, IGNORE_ABORT_ON_CONN, stmt), !QR_command_maybe_successful(gres))
{
grolist = QR_get_value_backend_text(gres, 0, 0);
}
if (NULL != CurrCat(conn))
- snprintf(catName, sizeof(catName), "'%s'::name", CurrCat(conn));
+ SPRINTF_FIXED(catName, "'%s'::name", CurrCat(conn));
else
STRCPY_FIXED(catName, "NULL::name");
STRCPY_FIXED(scmName1, "n2.nspname");
STRCPY_FIXED(scmName2, "n1.nspname");
escSchemaName = simpleCatalogEscape((SQLCHAR *) schema_needed, SQL_NTS, conn);
- snprintf(tables_query, sizeof(tables_query),
+ SPRINTF_FIXED(tables_query,
"select"
" %s as PKTABLE_CAT"
",\n %s as PKTABLE_SCHEM"
{
free(escTableName);
escTableName = simpleCatalogEscape((SQLCHAR *) pk_table_needed, SQL_NTS, conn);
- snprintf_add(tables_query, sizeof(tables_query),
+ SPRINTFCAT_FIXED(tables_query,
"\n where c2.relname %s'%s'",
eq_string, escTableName);
}
#include "loadlib.h"
#include "pgenlist.h"
+#include "misc.h"
#ifdef WIN32
#ifdef _MSC_VER
_splitpath(szFileName, drive, dir, NULL, NULL);
GetSystemDirectory(sysdir, MAX_PATH);
- snprintf(szFileName, sizeof(szFileName), "%s%s%s.dll", drive, dir, module_name);
+ SPRINTF_FIXED(szFileName, "%s%s%s.dll", drive, dir, module_name);
if (_strnicmp(szFileName, sysdir, strlen(sysdir)) != 0)
{
hmodule = LoadLibraryEx(szFileName, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
}
/*
- * snprintf_add is a extension to snprintf
+ * snprintfcat is a extension to snprintf
* It add format to buf at given pos
*/
int
-snprintf_add(char *buf, size_t size, const char *format, ...)
+snprintfcat(char *buf, size_t size, const char *format, ...)
{
int len;
size_t pos = strlen(buf);
}
/*
- * snprintf_addlen is a extension to snprintf
+ * snprintf_len is a extension to snprintf
* It returns strlen of buf every time (not -1 when truncated)
*/
#ifndef HAVE_STRLCAT
size_t strlcat(char *, const char *, size_t);
#endif /* HAVE_STRLCAT */
-int snprintf_add(char *buf, size_t size, const char *format, ...);
+int snprintfcat(char *buf, size_t size, const char *format, ...);
size_t snprintf_len(char *buf, size_t size, const char *format, ...);
char *my_trim(char *string);
FUNCTION_END_MACRO
/* macro to safely sprintf() & cat to fixed arrays. */
-#define SPRINTF_FIXEDCAT(to, ...) \
+#define SPRINTFCAT_FIXED(to, ...) \
FUNCTION_BEGIN_MACRO \
CHECK_NOT_CHAR_P(to) \
- snprintf_add((to), sizeof(to), __VA_ARGS__) \
+ snprintfcat((to), sizeof(to), __VA_ARGS__) \
FUNCTION_END_MACRO
#define ITOA_FIXED(to, from) \
if (ptr)
strlcat(filename, ptr->pw_name, filenamelen);
#endif
- snprintf_add(filename, filenamelen, "%u%s", pid, ".log");
+ snprintfcat(filename, filenamelen, "%u%s", pid, ".log");
return;
}
int lasterror = GENERAL_ERRNO;
open_error = TRUE;
- snprintf(errbuf, sizeof(errbuf), "%s open error %d\n", filebuf, lasterror);
+ SPRINTF_FIXED(errbuf, "%s open error %d\n", filebuf, lasterror);
generate_homefile(MYLOGFILE, filebuf, sizeof(filebuf));
MLOGFP = fopen(filebuf, PG_BINARY_A);
}
if (NULL != conn->pqconn)
return FALSE;
SC_clear_error(stmt);
- snprintf(message, sizeof(message), "%s unable due to the connection lost", funcname);
+ SPRINTF_FIXED(message, "%s unable due to the connection lost", funcname);
SC_set_error(stmt, STMT_COMMUNICATION_ERROR, message, funcname);
return TRUE;
}
#include "pgapifunc.h"
#include "connection.h"
#include "statement.h"
+#include "misc.h"
RETCODE SQL_API
{
char errc[32];
- snprintf(errc, sizeof(errc), "Error: SqlState=%s", qstr_ansi);
+ SPRINTF_FIXED(errc, "Error: SqlState=%s", qstr_ansi);
tlen = utf8_to_ucs2(errc, -1, szErrorMsg, cbErrorMsgMax);
}
}
if (!stmt->ti || !stmt->ti[0])
return FALSE;
ti = stmt->ti[0];
- snprintf(query, sizeof(query),
+ SPRINTF_FIXED(query,
"select relhasoids, c.oid, relhassubclass from pg_class c, pg_namespace n where relname = '%s' and nspname = '%s' and c.relnamespace = n.oid",
SAFE_NAME(ti->table_name), SAFE_NAME(ti->schema_name));
res = CC_send_query(conn, query, NULL, ROLLBACK_ON_ERROR | IGNORE_ABORT_ON_CONN, NULL);
/*
* We also have to check as follows.
*/
- snprintf(token, sizeof(token),
+ SPRINTF_FIXED(token,
"select nspname from pg_namespace n, pg_class c"
" where c.relnamespace=n.oid and c.oid='\"%s\"'::regclass",
SAFE_NAME(table_name));
if (unsupported)
{
char msg[64];
- snprintf(msg, sizeof(msg), "Couldn't set unsupported connect attribute " FORMAT_INTEGER, Attribute);
+ SPRINTF_FIXED(msg, "Couldn't set unsupported connect attribute " FORMAT_INTEGER, Attribute);
CC_set_error(conn, CONN_OPTION_NOT_FOR_THE_DRIVER, msg, func);
return SQL_ERROR;
}
#include "psqlodbc.h"
#include "dlg_specific.h"
#include "loadlib.h"
+#include "misc.h"
HINSTANCE s_hModule; /* Saved module handle. */
char drive[_MAX_DRIVE], dir[_MAX_DIR];
_splitpath(dllPath, drive, dir, NULL, NULL);
- snprintf(dllPath, sizeof(dllPath), "%s%slibpq.dll", drive, dir);
+ SPRINTF_FIXED(dllPath, "%s%slibpq.dll", drive, dir);
if (s_hLModule = LoadLibraryEx(dllPath, NULL, LOAD_WITH_ALTERED_SEARCH_PATH), s_hLModule == NULL)
{
mylog("libpq in the folder %s%s couldn't be loaded\n", drive, dir);
- snprintf(message, sizeof(message), "libpq in neither %s nor %s%s could be loaded", PG_BIN, drive, dir);
+ SPRINTF_FIXED(message, "libpq in neither %s nor %s%s could be loaded", PG_BIN, drive, dir);
}
}
#ifdef PG_BIN
else
- snprintf(message, sizeof(message), "libpq in the folder %s couldn't be loaded", PG_BIN);
+ SPRINTF_FIXED(message, "libpq in the folder %s couldn't be loaded", PG_BIN);
#endif /* PG_BIN */
if (message[0])
MessageBox(NULL, message, "psqlsetup", MB_OK);
{
char plannm[32];
- snprintf(plannm, sizeof(plannm), "_KEYSET_%p", self);
+ SPRINTF_FIXED(plannm, "_KEYSET_%p", self);
if (CC_is_in_error_trans(conn))
{
CC_mark_a_object_to_discard(conn, 's',plannm);
QResultClass *res;
char cmd[64];
- snprintf(cmd, sizeof(cmd), "DEALLOCATE \"%s\"", plannm);
+ SPRINTF_FIXED(cmd, "DEALLOCATE \"%s\"", plannm);
res = CC_send_query(conn, cmd, NULL, IGNORE_ABORT_ON_CONN | ROLLBACK_ON_ERROR, NULL);
QR_Destructor(res);
}
if (QR_needs_survival_check(self))
flag = ROLLBACK_ON_ERROR | IGNORE_ABORT_ON_CONN;
- snprintf(buf, sizeof(buf), "close \"%s\"", QR_get_cursor(self));
+ SPRINTF_FIXED(buf, "close \"%s\"", QR_get_cursor(self));
/* End the transaction if there are no cursors left on this conn */
if (CC_is_in_trans(conn) &&
CC_does_autocommit(conn) &&
mylog("QResult: END transaction on conn=%p\n", conn);
if ((ROLLBACK_ON_ERROR & flag) == 0)
{
- strlcat(buf, ";commit", sizeof(buf));
+ STRCAT_FIXED(buf, ";commit");
flag |= END_WITH_COMMIT;
QR_set_cursor(self, NULL);
}
if (QR_once_reached_eof(self) &&
self->cursTuple >= self->num_total_read)
return 0;
- snprintf(movecmd, sizeof(movecmd),
+ SPRINTF_FIXED(movecmd,
"move all in \"%s\"", QR_get_cursor(self));
res = CC_send_query(conn, movecmd, NULL, 0, stmt);
if (!QR_command_maybe_successful(res))
else
self->cache_size = req_size;
inolog("cache=%d rowset=%d movement=" FORMAT_ULEN "\n", self->cache_size, req_size, movement);
- snprintf(movecmd, sizeof(movecmd),
+ SPRINTF_FIXED(movecmd,
"move backward " FORMAT_ULEN " in \"%s\"",
movement, QR_get_cursor(self));
}
else if (QR_is_moving_forward(self))
- snprintf(movecmd, sizeof(movecmd),
+ SPRINTF_FIXED(movecmd,
"move " FORMAT_ULEN " in \"%s\"",
movement, QR_get_cursor(self));
else
{
- snprintf(movecmd, sizeof(movecmd),
+ SPRINTF_FIXED(movecmd,
"move all in \"%s\"",
QR_get_cursor(self));
movement = INT_MAX;
RETURN(FALSE)
/* Send a FETCH command to get more rows */
- snprintf(fetch, sizeof(fetch),
+ SPRINTF_FIXED(fetch,
"fetch %d in \"%s\"",
fetch_size, QR_get_cursor(self));
char emsg[128];
QR_set_rstatus(self, PORES_INTERNAL_ERROR);
- snprintf(emsg, sizeof(emsg), "Internal Error -- this_keyset == NULL ci_num_fields=%d effective_cols=%d", ci_num_fields, effective_cols);
+ SPRINTF_FIXED(emsg, "Internal Error -- this_keyset == NULL ci_num_fields=%d effective_cols=%d", ci_num_fields, effective_cols);
QR_set_message(self, emsg);
return FALSE;
}
if (icol >= QR_NumPublicResultCols(res))
{
SC_set_error(stmt, STMT_INVALID_COLUMN_NUMBER_ERROR, "Invalid column number in DescribeCol.", func);
- snprintf(buf, sizeof(buf), "Col#=%d, #Cols=%d,%d keys=%d", icol, QR_NumResultCols(res), QR_NumPublicResultCols(res), res->num_key_fields);
+ SPRINTF_FIXED(buf, "Col#=%d, #Cols=%d,%d keys=%d", icol, QR_NumResultCols(res), QR_NumPublicResultCols(res), res->num_key_fields);
SC_log_error(func, buf, stmt);
result = SQL_ERROR;
goto cleanup;
QResultClass *res;
char *ret = "";
- snprintf(query, sizeof(query), "select relname, nspname from pg_class c, pg_namespace n where c.oid=%u and c.relnamespace=n.oid", tableoid);
+ SPRINTF_FIXED(query, "select relname, nspname from pg_class c, pg_namespace n where c.oid=%u and c.relnamespace=n.oid", tableoid);
res = CC_send_query(SC_get_conn(stmt), query, NULL, 0, stmt);
if (QR_command_maybe_successful(res) &&
QR_get_num_cached_tuples(res) == 1)
RETCODE ret = FALSE;
const char *bestqual = GET_NAME(ti->bestqual);
- snprintf(selstr, sizeof(selstr),
+ SPRINTF_FIXED(selstr,
"select 1 from %s where ctid = '(%u,%u)'",
ti_quote(stmt, keyset->oid),
keyset->blocknum, keyset->offset);
if (NULL != bestqual && 0 != keyset->oid && !TI_has_subclass(ti))
{
- snprintf_add(selstr, sizeof(selstr), " and ");
- snprintf_add(selstr, sizeof(selstr), bestqual, keyset->oid);
+ SPRINTFCAT_FIXED(selstr, " and ");
+ SPRINTFCAT_FIXED(selstr, bestqual, keyset->oid);
}
res = CC_send_query(SC_get_conn(stmt), selstr, NULL, 0, NULL);
if (QR_command_maybe_successful(res) && 1 == res->num_cached_rows)
char tidval[32];
Oid oid = wkey->oid;
- snprintf(tidval, sizeof(tidval),
+ SPRINTF_FIXED(tidval,
"(%u,%u)", wkey->blocknum, wkey->offset);
qres = positioned_load(stmt, 0, &oid, tidval);
if (QR_command_maybe_successful(qres) &&
else
{
STRCPY_FIXED(oideqstr, andqual);
- snprintf_add(oideqstr, sizeof(oideqstr), bestqual, *oidint);
+ SPRINTFCAT_FIXED(oideqstr, bestqual, *oidint);
}
len = strlen(load_stmt);
len += strlen(oideqstr);
else if (bestqual && oidint)
{
snprintf(selstr, len, "%s where ", load_stmt);
- snprintf_add(selstr, len, bestqual, *oidint);
+ snprintfcat(selstr, len, bestqual, *oidint);
}
else
{
char tid[32];
oidint = keyset->oid;
- snprintf(tid, sizeof(tid), "(%u,%hu)", keyset->blocknum, keyset->offset);
+ SPRINTF_FIXED(tid, "(%u,%hu)", keyset->blocknum, keyset->offset);
qres = positioned_load(stmt, 0, &oidint, tid);
}
else
{
strlcat(qval, j ? ",tid" : "(tid", allen);
}
- snprintf_add(qval, allen, ") as %s where ctid in ", stmt->load_statement);
+ snprintfcat(qval, allen, ") as %s where ctid in ", stmt->load_statement);
for (j = 0; j < keys_per_fetch; j++)
{
if (j == 0)
strlcat(qval, "($1", allen);
else
- snprintf_add(qval, allen, ",$%d", j + 1);
+ snprintfcat(qval, allen, ",$%d", j + 1);
}
strlcat(qval, ")", allen);
qres = CC_send_query(conn, qval, NULL, 0, stmt);
{
getTid(res, kres_ridx, &blocknum, &offset);
if (rowc)
- snprintf_add(qval, allen, ",'(%u,%u)'", blocknum, offset);
+ snprintfcat(qval, allen, ",'(%u,%u)'", blocknum, offset);
else
- snprintf_add(qval, allen, "'(%u,%u)'", blocknum, offset);
+ snprintfcat(qval, allen, "'(%u,%u)'", blocknum, offset);
rowc++;
rcnt++;
}
oid = new_oid;
getTid(res, kres_ridx, &blocknum, &offset);
if (rowc)
- snprintf_add(qval, allen, ",'(%u,%u)'", blocknum, offset);
+ snprintfcat(qval, allen, ",'(%u,%u)'", blocknum, offset);
else
- snprintf_add(qval, allen, "'(%u,%u)'", blocknum, offset);
+ snprintfcat(qval, allen, "'(%u,%u)'", blocknum, offset);
rowc++;
rcnt++;
}
ti = s.stmt->ti[0];
- snprintf(updstr, sizeof(updstr),
+ SPRINTF_FIXED(updstr,
"update %s set", ti_quote(stmt, oid));
num_cols = s.irdflds->nfields;
if (*used != SQL_IGNORE && fi[i]->updatable)
{
if (upd_cols)
- snprintf_add(updstr, sizeof(updstr),
+ SPRINTFCAT_FIXED(updstr,
", \"%s\" = ?", GET_NAME(fi[i]->column_name));
else
- snprintf_add(updstr, sizeof(updstr),
+ SPRINTFCAT_FIXED(updstr,
" \"%s\" = ?", GET_NAME(fi[i]->column_name));
upd_cols++;
}
const char *bestqual = GET_NAME(ti->bestqual);
int unknown_sizes = ci->drivers.unknown_sizes;
- snprintf_add(updstr, sizeof(updstr),
+ SPRINTFCAT_FIXED(updstr,
" where ctid = '(%u, %u)'",
blocknum, pgoffset);
if (bestqual)
{
- snprintf_add(updstr, sizeof(updstr), " and ");
- snprintf_add(updstr, sizeof(updstr), bestqual, oid);
+ SPRINTFCAT_FIXED(updstr, " and ");
+ SPRINTFCAT_FIXED(updstr, bestqual, oid);
}
if (PG_VERSION_GE(conn, 8.2))
{
- snprintf_add(updstr, sizeof(updstr), " returning ctid");
+ SPRINTFCAT_FIXED(updstr, " returning ctid");
if (bestitem)
{
- snprintf_add(updstr, sizeof(updstr), ", ");
- snprintf_add(updstr, sizeof(updstr), "\"%s\"", bestitem);
+ SPRINTFCAT_FIXED(updstr, ", ");
+ SPRINTFCAT_FIXED(updstr, "\"%s\"", bestitem);
}
}
mylog("updstr=%s\n", updstr);
blocknum = keyset->blocknum;
offset = keyset->offset;
}
- snprintf(dltstr, sizeof(dltstr),
+ SPRINTF_FIXED(dltstr,
"delete from %s where ctid = '(%u, %u)'",
ti_quote(stmt, oid), blocknum, offset);
if (bestqual && !TI_has_subclass(ti))
{
- snprintf_add(dltstr, sizeof(dltstr), " and ");
- snprintf_add(dltstr, sizeof(dltstr), bestqual, oid);
+ SPRINTFCAT_FIXED(dltstr, " and ");
+ SPRINTFCAT_FIXED(dltstr, bestqual, oid);
}
mylog("dltstr=%s\n", dltstr);
{
KeySetSet(tres->backend_tuples, QR_NumResultCols(tres), QR_NumResultCols(tres), &keys, TRUE);
oid = keys.oid;
- snprintf(tidv, sizeof(tidv), "(%u,%hu)", keys.blocknum, keys.offset);
+ SPRINTF_FIXED(tidv, "(%u,%hu)", keys.blocknum, keys.offset);
tidval = tidv;
}
if (0 != oid)
num_cols = s.irdflds->nfields;
conn = SC_get_conn(s.stmt);
- snprintf(addstr, sizeof(addstr),
+ SPRINTF_FIXED(addstr,
"insert into %s (",
ti_quote(s.stmt, 0));
if (PGAPI_AllocStmt(conn, &hstmt, 0) != SQL_SUCCESS)
/* fieldtype = QR_get_field_type(s.res, i); */
fieldtype = getEffectiveOid(conn, fi[i]);
if (add_cols)
- snprintf_add(addstr, sizeof(addstr),
+ SPRINTFCAT_FIXED(addstr,
", \"%s\"", GET_NAME(fi[i]->column_name));
else
- snprintf_add(addstr, sizeof(addstr),
+ SPRINTFCAT_FIXED(addstr,
"\"%s\"", GET_NAME(fi[i]->column_name));
PIC_set_pgtype(ipdopts->parameters[add_cols], fieldtype);
PGAPI_BindParameter(hstmt,
ENTER_INNER_CONN_CS(conn, func_cs_count);
if (add_cols > 0)
{
- snprintf_add(addstr, sizeof(addstr), ") values (");
+ SPRINTFCAT_FIXED(addstr, ") values (");
for (i = 0; i < add_cols; i++)
{
if (i)
- snprintf_add(addstr, sizeof(addstr), ", ?");
+ SPRINTFCAT_FIXED(addstr, ", ?");
else
- snprintf_add(addstr, sizeof(addstr), "?");
+ SPRINTFCAT_FIXED(addstr, "?");
}
- snprintf_add(addstr, sizeof(addstr), ")");
+ SPRINTFCAT_FIXED(addstr, ")");
if (PG_VERSION_GE(conn, 8.2))
{
TABLE_INFO *ti = stmt->ti[0];
const char *bestitem = GET_NAME(ti->bestitem);
- snprintf_add(addstr, sizeof(addstr), " returning ctid");
+ SPRINTFCAT_FIXED(addstr, " returning ctid");
if (bestitem)
{
- snprintf_add(addstr, sizeof(addstr), ", ");
- snprintf_add(addstr, sizeof(addstr), "\"%s\"", bestitem);
+ SPRINTFCAT_FIXED(addstr, ", ");
+ SPRINTFCAT_FIXED(addstr, "\"%s\"", bestitem);
}
}
mylog("addstr=%s\n", addstr);
goto cleanup;
if (!SQLWritePrivateProfileString(lpszDriver, "ConnectFunctions", "YYN", ODBCINST_INI))
goto cleanup;
- snprintf(ver_string, sizeof(ver_string), "%02x.%02x",
+ SPRINTF_FIXED(ver_string, "%02x.%02x",
ODBCVER / 256,
ODBCVER % 256);
if (!SQLWritePrivateProfileString(lpszDriver, "DriverODBCVer",
{
char query[64];
- snprintf(query, sizeof(query), "SET statement_timeout = %d",
+ SPRINTF_FIXED(query, "SET statement_timeout = %d",
(int) self->options.stmt_timeout * 1000);
res = CC_send_query(conn, query, NULL, 0, NULL);
if (QR_command_maybe_successful(res))
qi.result_in = NULL;
qi.cursor = SC_cursor_name(self);
qi.fetch_size = qi.row_size = ci->drivers.fetch_max;
- snprintf(fetch, sizeof(fetch),
+ SPRINTF_FIXED(fetch,
"fetch " FORMAT_LEN " in \"%s\"",
qi.fetch_size, SC_cursor_name(self));
qryi = &qi;
qi.result_in = NULL;
qi.cursor = SC_cursor_name(self);
qi.cache_size = qi.row_size = ci->drivers.fetch_max;
- snprintf(fetch, sizeof(fetch), "fetch " FORMAT_LEN " in \"%s\"", qi.fetch_size, SC_cursor_name(self));
+ SPRINTF_FIXED(fetch, "fetch " FORMAT_LEN " in \"%s\"", qi.fetch_size, SC_cursor_name(self));
res = CC_send_query(conn, fetch, &qi, qflag, SC_get_ancestor(self));
if (NULL != res)
SC_set_Result(self, res);
{
char emsg[128];
- snprintf(emsg, sizeof(emsg), "internal savepoint error in %s", func);
+ SPRINTF_FIXED(emsg, "internal savepoint error in %s", func);
SC_set_error_if_not_set(stmt, STMT_INTERNAL_ERROR, emsg, func);
return FALSE;
}