Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita8dbe42

Browse files
author
Hiroshi Inoue
committed
Change SQLPrimaryKeys() so that it detects the primary key
other than tablename_pkey.
1 parentd8d9ed9 commita8dbe42

File tree

6 files changed

+74
-44
lines changed

6 files changed

+74
-44
lines changed

‎src/interfaces/odbc/bind.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ SQLBindParameter(
5959
SC_log_error(func,"",NULL);
6060
returnSQL_INVALID_HANDLE;
6161
}
62+
SC_clear_error(stmt);
6263

6364
if (stmt->parameters_allocated<ipar)
6465
{
@@ -292,6 +293,7 @@ SQLDescribeParam(
292293
SC_log_error(func,"",NULL);
293294
returnSQL_INVALID_HANDLE;
294295
}
296+
SC_clear_error(stmt);
295297

296298
if ((ipar<1)|| (ipar>stmt->parameters_allocated))
297299
{
@@ -366,6 +368,7 @@ SQLNumParams(
366368
SC_log_error(func,"",NULL);
367369
returnSQL_INVALID_HANDLE;
368370
}
371+
SC_clear_error(stmt);
369372

370373
if (pcpar)
371374
*pcpar=0;

‎src/interfaces/odbc/drvconn.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ SQLDriverConnect(
233233
{
234234
result=SQL_SUCCESS_WITH_INFO;
235235
conn->errornumber=CONN_TRUNCATED;
236-
conn->errormsg="The buffer was too small for theresult.";
236+
conn->errormsg="The buffer was too small for theConnStrOut.";
237237
}
238238
}
239239

‎src/interfaces/odbc/execute.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ SQLNativeSql(
545545
{
546546
result=SQL_SUCCESS_WITH_INFO;
547547
conn->errornumber=STMT_TRUNCATED;
548-
conn->errormsg="The buffer was too small for theresult.";
548+
conn->errormsg="The buffer was too small for theNativeSQL.";
549549
}
550550
}
551551

‎src/interfaces/odbc/info.c

Lines changed: 58 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,7 @@ SQLGetInfo(
677677
{
678678
result=SQL_SUCCESS_WITH_INFO;
679679
conn->errornumber=STMT_TRUNCATED;
680-
conn->errormsg="The buffer was too small forthe result.";
680+
conn->errormsg="The buffer was too small fortthe InfoValue.";
681681
}
682682
}
683683
}
@@ -2441,6 +2441,7 @@ SQLPrimaryKeys(
24412441
{
24422442
staticchar*func="SQLPrimaryKeys";
24432443
StatementClass*stmt= (StatementClass*)hstmt;
2444+
ConnectionClass*conn;
24442445
TupleNode*row;
24452446
RETCODEresult;
24462447
intseq=0;
@@ -2451,6 +2452,7 @@ SQLPrimaryKeys(
24512452
SDWORDattname_len;
24522453
charpktab[MAX_TABLE_LEN+1];
24532454
Int2result_cols;
2455+
intqno,qstart,qend;
24542456

24552457
mylog("%s: entering...stmt=%u\n",func,stmt);
24562458

@@ -2511,37 +2513,6 @@ SQLPrimaryKeys(
25112513
returnSQL_ERROR;
25122514
}
25132515

2514-
#if0
2515-
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);
2516-
#else
2517-
2518-
/*
2519-
* Simplified query to remove assumptions about number of possible
2520-
* index columns. Courtesy of Tom Lane - thomas 2000-03-21
2521-
*/
2522-
sprintf(tables_query,"select ta.attname, ia.attnum"
2523-
" from pg_attribute ta, pg_attribute ia, pg_class c, pg_index i"
2524-
" where c.relname = '%s_pkey'"
2525-
" AND c.oid = i.indexrelid"
2526-
" AND ia.attrelid = i.indexrelid"
2527-
" AND ta.attrelid = i.indrelid"
2528-
" AND ta.attnum = i.indkey[ia.attnum-1]"
2529-
" order by ia.attnum",pktab);
2530-
#endif
2531-
2532-
2533-
mylog("SQLPrimaryKeys: tables_query='%s'\n",tables_query);
2534-
2535-
result=SQLExecDirect(htbl_stmt,tables_query,strlen(tables_query));
2536-
if ((result!=SQL_SUCCESS)&& (result!=SQL_SUCCESS_WITH_INFO))
2537-
{
2538-
stmt->errormsg=SC_create_errormsg(htbl_stmt);
2539-
stmt->errornumber=tbl_stmt->errornumber;
2540-
SC_log_error(func,"",stmt);
2541-
SQLFreeStmt(htbl_stmt,SQL_DROP);
2542-
returnSQL_ERROR;
2543-
}
2544-
25452516
result=SQLBindCol(htbl_stmt,1,SQL_C_CHAR,
25462517
attname,MAX_INFO_STRING,&attname_len);
25472518
if ((result!=SQL_SUCCESS)&& (result!=SQL_SUCCESS_WITH_INFO))
@@ -2553,7 +2524,61 @@ SQLPrimaryKeys(
25532524
returnSQL_ERROR;
25542525
}
25552526

2556-
result=SQLFetch(htbl_stmt);
2527+
conn= (ConnectionClass*) (stmt->hdbc);
2528+
if (PG_VERSION_LE(conn,6.4))
2529+
qstart=2;
2530+
else
2531+
qstart=1;
2532+
qend=2;
2533+
for (qno=qstart;qno <=qend;qno++)
2534+
{
2535+
switch (qno)
2536+
{
2537+
case1:
2538+
/*
2539+
* Simplified query to remove assumptions about number of possible
2540+
* index columns. Courtesy of Tom Lane - thomas 2000-03-21
2541+
*/
2542+
sprintf(tables_query,"select ta.attname, ia.attnum"
2543+
" from pg_attribute ta, pg_attribute ia, pg_class c, pg_index i"
2544+
" where c.relname = '%s'"
2545+
" AND c.oid = i.indrelid"
2546+
" AND i.indisprimary = 't'"
2547+
" AND ia.attrelid = i.indexrelid"
2548+
" AND ta.attrelid = i.indrelid"
2549+
" AND ta.attnum = i.indkey[ia.attnum-1]"
2550+
" order by ia.attnum",pktab);
2551+
break;
2552+
case2:
2553+
/*
2554+
* Simplified query to search old fashoned primary key
2555+
*/
2556+
sprintf(tables_query,"select ta.attname, ia.attnum"
2557+
" from pg_attribute ta, pg_attribute ia, pg_class c, pg_index i"
2558+
" where c.relname = '%s_pkey'"
2559+
" AND c.oid = i.indexrelid"
2560+
" AND ia.attrelid = i.indexrelid"
2561+
" AND ta.attrelid = i.indrelid"
2562+
" AND ta.attnum = i.indkey[ia.attnum-1]"
2563+
" order by ia.attnum",pktab);
2564+
break;
2565+
}
2566+
mylog("SQLPrimaryKeys: tables_query='%s'\n",tables_query);
2567+
2568+
result=SQLExecDirect(htbl_stmt,tables_query,strlen(tables_query));
2569+
if ((result!=SQL_SUCCESS)&& (result!=SQL_SUCCESS_WITH_INFO))
2570+
{
2571+
stmt->errormsg=SC_create_errormsg(htbl_stmt);
2572+
stmt->errornumber=tbl_stmt->errornumber;
2573+
SC_log_error(func,"",stmt);
2574+
SQLFreeStmt(htbl_stmt,SQL_DROP);
2575+
returnSQL_ERROR;
2576+
}
2577+
2578+
result=SQLFetch(htbl_stmt);
2579+
if (result!=SQL_NO_DATA_FOUND)
2580+
break;
2581+
}
25572582

25582583
while ((result==SQL_SUCCESS)|| (result==SQL_SUCCESS_WITH_INFO))
25592584
{

‎src/interfaces/odbc/results.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ SQLDescribeCol(
309309
{
310310
result=SQL_SUCCESS_WITH_INFO;
311311
stmt->errornumber=STMT_TRUNCATED;
312-
stmt->errormsg="The buffer was too small for theresult.";
312+
stmt->errormsg="The buffer was too small for thecolName.";
313313
}
314314
}
315315

@@ -619,7 +619,7 @@ SQLColAttributes(
619619
{
620620
result=SQL_SUCCESS_WITH_INFO;
621621
stmt->errornumber=STMT_TRUNCATED;
622-
stmt->errormsg="The buffer was too small for theresult.";
622+
stmt->errormsg="The buffer was too small for thergbDesc.";
623623
}
624624
}
625625

@@ -799,7 +799,7 @@ SQLGetData(
799799

800800
caseCOPY_RESULT_TRUNCATED:
801801
stmt->errornumber=STMT_TRUNCATED;
802-
stmt->errormsg="The buffer was too small for theresult.";
802+
stmt->errormsg="The buffer was too small for theGetData.";
803803
returnSQL_SUCCESS_WITH_INFO;
804804

805805
caseCOPY_GENERAL_ERROR:/* error msg already filled in */
@@ -1352,7 +1352,7 @@ SQLGetCursorName(
13521352
{
13531353
result=SQL_SUCCESS_WITH_INFO;
13541354
stmt->errornumber=STMT_TRUNCATED;
1355-
stmt->errormsg="The buffer was too small for theresult.";
1355+
stmt->errormsg="The buffer was too small for theGetCursorName.";
13561356
}
13571357
}
13581358

‎src/interfaces/odbc/statement.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ SQLFreeStmt(HSTMT hstmt,
153153
SC_log_error(func,"",NULL);
154154
returnSQL_INVALID_HANDLE;
155155
}
156+
SC_clear_error(stmt);
156157

157158
if (fOption==SQL_DROP)
158159
{
@@ -299,6 +300,7 @@ char
299300
SC_Destructor(StatementClass*self)
300301
{
301302
mylog("SC_Destructor: self=%u, self->result=%u, self->hdbc=%u\n",self,self->result,self->hdbc);
303+
SC_clear_error(self);
302304
if (STMT_EXECUTING==self->status)
303305
{
304306
self->errornumber=STMT_SEQUENCE_ERROR;
@@ -438,6 +440,7 @@ SC_recycle_statement(StatementClass *self)
438440

439441
mylog("recycle statement: self= %u\n",self);
440442

443+
SC_clear_error(self);
441444
/* This would not happen */
442445
if (self->status==STMT_EXECUTING)
443446
{
@@ -446,10 +449,6 @@ SC_recycle_statement(StatementClass *self)
446449
return FALSE;
447450
}
448451

449-
self->errormsg=NULL;
450-
self->errornumber=0;
451-
self->errormsg_created= FALSE;
452-
453452
switch (self->status)
454453
{
455454
caseSTMT_ALLOCATED:
@@ -836,7 +835,10 @@ SC_fetch(StatementClass *self)
836835

837836
caseCOPY_RESULT_TRUNCATED:
838837
self->errornumber=STMT_TRUNCATED;
839-
self->errormsg="The buffer was too small for the result.";
838+
self->errormsg="Fetched item was truncated.";
839+
qlog("The %dth item was truncated\n",lf+1);
840+
qlog("The buffer size = %d",self->bindings[lf].buflen);
841+
qlog(" and the value is '%s'\n",value);
840842
result=SQL_SUCCESS_WITH_INFO;
841843
break;
842844

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp