aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHiroshi Inoue <inoue@tpf.co.jp>2001-06-22 05:59:43 +0000
committerHiroshi Inoue <inoue@tpf.co.jp>2001-06-22 05:59:43 +0000
commita8dbe428de8f8c11a047c441c9f1b5b5433b0115 (patch)
tree6940c6aa8c0a5be92a116264a7d5ff67954a80b5 /src
parentd8d9ed931e8a2370d3995c40af2eb3bda18aecb0 (diff)
downloadpostgresql-a8dbe428de8f8c11a047c441c9f1b5b5433b0115.tar.gz
postgresql-a8dbe428de8f8c11a047c441c9f1b5b5433b0115.zip
Change SQLPrimaryKeys() so that it detects the primary key
other than tablename_pkey.
Diffstat (limited to 'src')
-rw-r--r--src/interfaces/odbc/bind.c3
-rw-r--r--src/interfaces/odbc/drvconn.c2
-rw-r--r--src/interfaces/odbc/execute.c2
-rw-r--r--src/interfaces/odbc/info.c91
-rw-r--r--src/interfaces/odbc/results.c8
-rw-r--r--src/interfaces/odbc/statement.c12
6 files changed, 74 insertions, 44 deletions
diff --git a/src/interfaces/odbc/bind.c b/src/interfaces/odbc/bind.c
index fc1f4b5c212..906dfdcc9c4 100644
--- a/src/interfaces/odbc/bind.c
+++ b/src/interfaces/odbc/bind.c
@@ -59,6 +59,7 @@ SQLBindParameter(
SC_log_error(func, "", NULL);
return SQL_INVALID_HANDLE;
}
+ SC_clear_error(stmt);
if (stmt->parameters_allocated < ipar)
{
@@ -292,6 +293,7 @@ SQLDescribeParam(
SC_log_error(func, "", NULL);
return SQL_INVALID_HANDLE;
}
+ SC_clear_error(stmt);
if ((ipar < 1) || (ipar > stmt->parameters_allocated))
{
@@ -366,6 +368,7 @@ SQLNumParams(
SC_log_error(func, "", NULL);
return SQL_INVALID_HANDLE;
}
+ SC_clear_error(stmt);
if (pcpar)
*pcpar = 0;
diff --git a/src/interfaces/odbc/drvconn.c b/src/interfaces/odbc/drvconn.c
index ea4c624679b..764424ad7e9 100644
--- a/src/interfaces/odbc/drvconn.c
+++ b/src/interfaces/odbc/drvconn.c
@@ -233,7 +233,7 @@ dialog:
{
result = SQL_SUCCESS_WITH_INFO;
conn->errornumber = CONN_TRUNCATED;
- conn->errormsg = "The buffer was too small for the result.";
+ conn->errormsg = "The buffer was too small for the ConnStrOut.";
}
}
diff --git a/src/interfaces/odbc/execute.c b/src/interfaces/odbc/execute.c
index ca9b2118887..fb64e8fe811 100644
--- a/src/interfaces/odbc/execute.c
+++ b/src/interfaces/odbc/execute.c
@@ -545,7 +545,7 @@ SQLNativeSql(
{
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 the NativeSQL.";
}
}
diff --git a/src/interfaces/odbc/info.c b/src/interfaces/odbc/info.c
index 173a1591bcd..39a0a49a988 100644
--- a/src/interfaces/odbc/info.c
+++ b/src/interfaces/odbc/info.c
@@ -677,7 +677,7 @@ SQLGetInfo(
{
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.";
}
}
}
@@ -2441,6 +2441,7 @@ SQLPrimaryKeys(
{
static char *func = "SQLPrimaryKeys";
StatementClass *stmt = (StatementClass *) hstmt;
+ ConnectionClass *conn;
TupleNode *row;
RETCODE result;
int seq = 0;
@@ -2451,6 +2452,7 @@ SQLPrimaryKeys(
SDWORD attname_len;
char pktab[MAX_TABLE_LEN + 1];
Int2 result_cols;
+ int qno, qstart, qend;
mylog("%s: entering...stmt=%u\n", func, stmt);
@@ -2511,37 +2513,6 @@ SQLPrimaryKeys(
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))
@@ -2553,7 +2524,61 @@ SQLPrimaryKeys(
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))
{
diff --git a/src/interfaces/odbc/results.c b/src/interfaces/odbc/results.c
index 56bca06bcb6..d861a3324ed 100644
--- a/src/interfaces/odbc/results.c
+++ b/src/interfaces/odbc/results.c
@@ -309,7 +309,7 @@ SQLDescribeCol(
{
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.";
}
}
@@ -619,7 +619,7 @@ SQLColAttributes(
{
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.";
}
}
@@ -799,7 +799,7 @@ SQLGetData(
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 */
@@ -1352,7 +1352,7 @@ SQLGetCursorName(
{
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.";
}
}
diff --git a/src/interfaces/odbc/statement.c b/src/interfaces/odbc/statement.c
index fd77eee6d6c..473d5709880 100644
--- a/src/interfaces/odbc/statement.c
+++ b/src/interfaces/odbc/statement.c
@@ -153,6 +153,7 @@ SQLFreeStmt(HSTMT hstmt,
SC_log_error(func, "", NULL);
return SQL_INVALID_HANDLE;
}
+ SC_clear_error(stmt);
if (fOption == SQL_DROP)
{
@@ -299,6 +300,7 @@ char
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;
@@ -438,6 +440,7 @@ SC_recycle_statement(StatementClass *self)
mylog("recycle statement: self= %u\n", self);
+ SC_clear_error(self);
/* This would not happen */
if (self->status == STMT_EXECUTING)
{
@@ -446,10 +449,6 @@ SC_recycle_statement(StatementClass *self)
return FALSE;
}
- self->errormsg = NULL;
- self->errornumber = 0;
- self->errormsg_created = FALSE;
-
switch (self->status)
{
case STMT_ALLOCATED:
@@ -836,7 +835,10 @@ SC_fetch(StatementClass *self)
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;