{
result = SQL_SUCCESS_WITH_INFO;
conn->errornumber = STMT_TRUNCATED;
- conn->errormsg = "The buffer was too small for the result.";
+ conn->errormsg = "The buffer was too small for tthe InfoValue.";
}
}
}
{
static char *func = "SQLPrimaryKeys";
StatementClass *stmt = (StatementClass *) hstmt;
+ ConnectionClass *conn;
TupleNode *row;
RETCODE result;
int seq = 0;
SDWORD attname_len;
char pktab[MAX_TABLE_LEN + 1];
Int2 result_cols;
+ int qno, qstart, qend;
mylog("%s: entering...stmt=%u\n", func, stmt);
return SQL_ERROR;
}
-#if 0
- sprintf(tables_query, "select distinct on (attnum) a2.attname, a2.attnum from pg_attribute a1, pg_attribute a2, pg_class c, pg_index i where c.relname = '%s_pkey' AND c.oid = i.indexrelid AND a1.attrelid = c.oid AND a2.attrelid = c.oid AND (i.indkey[0] = a1.attnum OR i.indkey[1] = a1.attnum OR i.indkey[2] = a1.attnum OR i.indkey[3] = a1.attnum OR i.indkey[4] = a1.attnum OR i.indkey[5] = a1.attnum OR i.indkey[6] = a1.attnum OR i.indkey[7] = a1.attnum) order by a2.attnum", pktab);
-#else
-
- /*
- * Simplified query to remove assumptions about number of possible
- * index columns. Courtesy of Tom Lane - thomas 2000-03-21
- */
- sprintf(tables_query, "select ta.attname, ia.attnum"
- " from pg_attribute ta, pg_attribute ia, pg_class c, pg_index i"
- " where c.relname = '%s_pkey'"
- " AND c.oid = i.indexrelid"
- " AND ia.attrelid = i.indexrelid"
- " AND ta.attrelid = i.indrelid"
- " AND ta.attnum = i.indkey[ia.attnum-1]"
- " order by ia.attnum", pktab);
-#endif
-
-
- mylog("SQLPrimaryKeys: tables_query='%s'\n", tables_query);
-
- result = SQLExecDirect(htbl_stmt, tables_query, strlen(tables_query));
- if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO))
- {
- stmt->errormsg = SC_create_errormsg(htbl_stmt);
- stmt->errornumber = tbl_stmt->errornumber;
- SC_log_error(func, "", stmt);
- SQLFreeStmt(htbl_stmt, SQL_DROP);
- return SQL_ERROR;
- }
-
result = SQLBindCol(htbl_stmt, 1, SQL_C_CHAR,
attname, MAX_INFO_STRING, &attname_len);
if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO))
return SQL_ERROR;
}
- result = SQLFetch(htbl_stmt);
+ conn = (ConnectionClass *) (stmt->hdbc);
+ if (PG_VERSION_LE(conn, 6.4))
+ qstart = 2;
+ else
+ qstart = 1;
+ qend = 2;
+ for (qno = qstart; qno <= qend; qno++)
+ {
+ switch (qno)
+ {
+ case 1:
+ /*
+ * Simplified query to remove assumptions about number of possible
+ * index columns. Courtesy of Tom Lane - thomas 2000-03-21
+ */
+ sprintf(tables_query, "select ta.attname, ia.attnum"
+ " from pg_attribute ta, pg_attribute ia, pg_class c, pg_index i"
+ " where c.relname = '%s'"
+ " AND c.oid = i.indrelid"
+ " AND i.indisprimary = 't'"
+ " AND ia.attrelid = i.indexrelid"
+ " AND ta.attrelid = i.indrelid"
+ " AND ta.attnum = i.indkey[ia.attnum-1]"
+ " order by ia.attnum", pktab);
+ break;
+ case 2:
+ /*
+ * Simplified query to search old fashoned primary key
+ */
+ sprintf(tables_query, "select ta.attname, ia.attnum"
+ " from pg_attribute ta, pg_attribute ia, pg_class c, pg_index i"
+ " where c.relname = '%s_pkey'"
+ " AND c.oid = i.indexrelid"
+ " AND ia.attrelid = i.indexrelid"
+ " AND ta.attrelid = i.indrelid"
+ " AND ta.attnum = i.indkey[ia.attnum-1]"
+ " order by ia.attnum", pktab);
+ break;
+ }
+ mylog("SQLPrimaryKeys: tables_query='%s'\n", tables_query);
+
+ result = SQLExecDirect(htbl_stmt, tables_query, strlen(tables_query));
+ if ((result != SQL_SUCCESS) && (result != SQL_SUCCESS_WITH_INFO))
+ {
+ stmt->errormsg = SC_create_errormsg(htbl_stmt);
+ stmt->errornumber = tbl_stmt->errornumber;
+ SC_log_error(func, "", stmt);
+ SQLFreeStmt(htbl_stmt, SQL_DROP);
+ return SQL_ERROR;
+ }
+
+ result = SQLFetch(htbl_stmt);
+ if (result != SQL_NO_DATA_FOUND)
+ break;
+ }
while ((result == SQL_SUCCESS) || (result == SQL_SUCCESS_WITH_INFO))
{
{
result = SQL_SUCCESS_WITH_INFO;
stmt->errornumber = STMT_TRUNCATED;
- stmt->errormsg = "The buffer was too small for the result.";
+ stmt->errormsg = "The buffer was too small for the colName.";
}
}
{
result = SQL_SUCCESS_WITH_INFO;
stmt->errornumber = STMT_TRUNCATED;
- stmt->errormsg = "The buffer was too small for the result.";
+ stmt->errormsg = "The buffer was too small for the rgbDesc.";
}
}
case COPY_RESULT_TRUNCATED:
stmt->errornumber = STMT_TRUNCATED;
- stmt->errormsg = "The buffer was too small for the result.";
+ stmt->errormsg = "The buffer was too small for the GetData.";
return SQL_SUCCESS_WITH_INFO;
case COPY_GENERAL_ERROR: /* error msg already filled in */
{
result = SQL_SUCCESS_WITH_INFO;
stmt->errornumber = STMT_TRUNCATED;
- stmt->errormsg = "The buffer was too small for the result.";
+ stmt->errormsg = "The buffer was too small for the GetCursorName.";
}
}
SC_log_error(func, "", NULL);
return SQL_INVALID_HANDLE;
}
+ SC_clear_error(stmt);
if (fOption == SQL_DROP)
{
SC_Destructor(StatementClass *self)
{
mylog("SC_Destructor: self=%u, self->result=%u, self->hdbc=%u\n", self, self->result, self->hdbc);
+ SC_clear_error(self);
if (STMT_EXECUTING == self->status)
{
self->errornumber = STMT_SEQUENCE_ERROR;
mylog("recycle statement: self= %u\n", self);
+ SC_clear_error(self);
/* This would not happen */
if (self->status == STMT_EXECUTING)
{
return FALSE;
}
- self->errormsg = NULL;
- self->errornumber = 0;
- self->errormsg_created = FALSE;
-
switch (self->status)
{
case STMT_ALLOCATED:
case COPY_RESULT_TRUNCATED:
self->errornumber = STMT_TRUNCATED;
- self->errormsg = "The buffer was too small for the result.";
+ self->errormsg = "Fetched item was truncated.";
+ qlog("The %dth item was truncated\n", lf + 1);
+ qlog("The buffer size = %d", self->bindings[lf].buflen);
+ qlog(" and the value is '%s'\n", value);
result = SQL_SUCCESS_WITH_INFO;
break;