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

Commit5abaa77

Browse files
committed
Fix for HASH for index lookups in ODBC.
1 parent014f98d commit5abaa77

File tree

3 files changed

+164
-20
lines changed

3 files changed

+164
-20
lines changed

‎src/interfaces/jdbc/org/postgresql/jdbc1/DatabaseMetaData.java

Lines changed: 60 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1688,16 +1688,16 @@ public java.sql.ResultSet getTables(String catalog, String schemaPattern, String
16881688

16891689
StringrelKind;
16901690
switch (r.getBytes(3)[0]) {
1691-
case'r':
1691+
case(byte)'r':
16921692
relKind ="TABLE";
16931693
break;
1694-
case'i':
1694+
case(byte)'i':
16951695
relKind ="INDEX";
16961696
break;
1697-
case'S':
1697+
case(byte)'S':
16981698
relKind ="SEQUENCE";
16991699
break;
1700-
case'v':
1700+
case(byte)'v':
17011701
relKind ="VIEW";
17021702
break;
17031703
default:
@@ -2623,11 +2623,10 @@ public java.sql.ResultSet getTypeInfo() throws SQLException
26232623
* @return ResultSet each row is an index column description
26242624
*/
26252625
// Implementation note: This is required for Borland's JBuilder to work
2626-
publicjava.sql.ResultSetgetIndexInfo(Stringcatalog,Stringschema,Stringtable,booleanunique,booleanapproximate)throwsSQLException
2626+
publicjava.sql.ResultSetgetIndexInfo(Stringcatalog,Stringschema,StringtableName,booleanunique,booleanapproximate)throwsSQLException
26272627
{
2628-
// for now, this returns an empty result set.
26292628
Fieldf[] =newField[13];
2630-
ResultSetr;// ResultSet for the SQL query that we need to do
2629+
java.sql.ResultSetr;// ResultSet for the SQL query that we need to do
26312630
Vectorv =newVector();// The new ResultSet tuple stuff
26322631

26332632
f[0] =newField(connection,"TABLE_CAT",iVarcharOid,32);
@@ -2644,6 +2643,60 @@ public java.sql.ResultSet getIndexInfo(String catalog, String schema, String tab
26442643
f[11] =newField(connection,"PAGES",iInt4Oid,4);
26452644
f[12] =newField(connection,"FILTER_CONDITION",iVarcharOid,32);
26462645

2646+
2647+
r =connection.ExecSQL("select " +
2648+
"c.relname, " +
2649+
"x.indisunique, " +
2650+
"i.relname, " +
2651+
"x.indisclustered, " +
2652+
"a.amname, " +
2653+
"x.indkey, " +
2654+
"c.reltuples, " +
2655+
"c.relpages " +
2656+
"FROM pg_index x, pg_class c, pg_class i, pg_am a " +
2657+
"WHERE ((c.relname = '" +tableName.toLowerCase() +"') " +
2658+
" AND (c.oid = x.indrelid) " +
2659+
" AND (i.oid = x.indexrelid) " +
2660+
" AND (c.relam = a.oid)) " +
2661+
"ORDER BY x.indisunique DESC, " +
2662+
" x.indisclustered, a.amname, i.relname");
2663+
while (r.next()) {
2664+
// indkey is an array of column ordinals (integers). In the JDBC
2665+
// interface, this has to be separated out into a separate
2666+
// tuple for each indexed column. Also, getArray() is not yet
2667+
// implemented for Postgres JDBC, so we parse by hand.
2668+
StringcolumnOrdinalString =r.getString(6);
2669+
StringTokenizerstok =newStringTokenizer(columnOrdinalString);
2670+
int []columnOrdinals =newint[stok.countTokens()];
2671+
into =0;
2672+
while (stok.hasMoreTokens()) {
2673+
columnOrdinals[o++] =Integer.parseInt(stok.nextToken());
2674+
}
2675+
for (inti =0;i <columnOrdinals.length;i++) {
2676+
byte [] []tuple =newbyte [13] [];
2677+
tuple[0] ="".getBytes();
2678+
tuple[1] ="".getBytes();
2679+
tuple[2] =r.getBytes(1);
2680+
tuple[3] =r.getBoolean(2) ?"f".getBytes() :"t".getBytes();
2681+
tuple[4] =null;
2682+
tuple[5] =r.getBytes(3);
2683+
tuple[6] =r.getBoolean(4) ?
2684+
Integer.toString(tableIndexClustered).getBytes() :
2685+
r.getString(5).equals("hash") ?
2686+
Integer.toString(tableIndexHashed).getBytes() :
2687+
Integer.toString(tableIndexOther).getBytes();
2688+
tuple[7] =Integer.toString(i +1).getBytes();
2689+
java.sql.ResultSetcolumnNameRS =connection.ExecSQL("select a.attname FROM pg_attribute a, pg_class c WHERE (a.attnum = " +columnOrdinals[i] +") AND (a.attrelid = " +r.getInt(8) +")");
2690+
columnNameRS.next();
2691+
tuple[8] =columnNameRS.getBytes(1);
2692+
tuple[9] =null;// sort sequence ???
2693+
tuple[10] =r.getBytes(7);// inexact
2694+
tuple[11] =r.getBytes(8);
2695+
tuple[12] =null;
2696+
v.addElement(tuple);
2697+
}
2698+
}
2699+
26472700
returnnewResultSet(connection,f,v,"OK",1);
26482701
}
26492702
}

‎src/interfaces/jdbc/org/postgresql/jdbc2/DatabaseMetaData.java

Lines changed: 59 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1688,16 +1688,16 @@ public java.sql.ResultSet getTables(String catalog, String schemaPattern, String
16881688

16891689
StringrelKind;
16901690
switch (r.getBytes(3)[0]) {
1691-
case'r':
1691+
case(byte)'r':
16921692
relKind ="TABLE";
16931693
break;
1694-
case'i':
1694+
case(byte)'i':
16951695
relKind ="INDEX";
16961696
break;
1697-
case'S':
1697+
case(byte)'S':
16981698
relKind ="SEQUENCE";
16991699
break;
1700-
case'v':
1700+
case(byte)'v':
17011701
relKind ="VIEW";
17021702
break;
17031703
default:
@@ -2622,11 +2622,10 @@ public java.sql.ResultSet getTypeInfo() throws SQLException
26222622
* @return ResultSet each row is an index column description
26232623
*/
26242624
// Implementation note: This is required for Borland's JBuilder to work
2625-
publicjava.sql.ResultSetgetIndexInfo(Stringcatalog,Stringschema,Stringtable,booleanunique,booleanapproximate)throwsSQLException
2625+
publicjava.sql.ResultSetgetIndexInfo(Stringcatalog,Stringschema,StringtableName,booleanunique,booleanapproximate)throwsSQLException
26262626
{
2627-
// for now, this returns an empty result set.
26282627
Fieldf[] =newField[13];
2629-
ResultSetr;// ResultSet for the SQL query that we need to do
2628+
java.sql.ResultSetr;// ResultSet for the SQL query that we need to do
26302629
Vectorv =newVector();// The new ResultSet tuple stuff
26312630

26322631
f[0] =newField(connection,"TABLE_CAT",iVarcharOid,32);
@@ -2643,6 +2642,59 @@ public java.sql.ResultSet getIndexInfo(String catalog, String schema, String tab
26432642
f[11] =newField(connection,"PAGES",iInt4Oid,4);
26442643
f[12] =newField(connection,"FILTER_CONDITION",iVarcharOid,32);
26452644

2645+
r =connection.ExecSQL("select " +
2646+
"c.relname, " +
2647+
"x.indisunique, " +
2648+
"i.relname, " +
2649+
"x.indisclustered, " +
2650+
"a.amname, " +
2651+
"x.indkey, " +
2652+
"c.reltuples, " +
2653+
"c.relpages " +
2654+
"FROM pg_index x, pg_class c, pg_class i, pg_am a " +
2655+
"WHERE ((c.relname = '" +tableName.toLowerCase() +"') " +
2656+
" AND (c.oid = x.indrelid) " +
2657+
" AND (i.oid = x.indexrelid) " +
2658+
" AND (c.relam = a.oid)) " +
2659+
"ORDER BY x.indisunique DESC, " +
2660+
" x.indisclustered, a.amname, i.relname");
2661+
while (r.next()) {
2662+
// indkey is an array of column ordinals (integers). In the JDBC
2663+
// interface, this has to be separated out into a separate
2664+
// tuple for each indexed column. Also, getArray() is not yet
2665+
// implemented for Postgres JDBC, so we parse by hand.
2666+
StringcolumnOrdinalString =r.getString(6);
2667+
StringTokenizerstok =newStringTokenizer(columnOrdinalString);
2668+
int []columnOrdinals =newint[stok.countTokens()];
2669+
into =0;
2670+
while (stok.hasMoreTokens()) {
2671+
columnOrdinals[o++] =Integer.parseInt(stok.nextToken());
2672+
}
2673+
for (inti =0;i <columnOrdinals.length;i++) {
2674+
byte [] []tuple =newbyte [13] [];
2675+
tuple[0] ="".getBytes();
2676+
tuple[1] ="".getBytes();
2677+
tuple[2] =r.getBytes(1);
2678+
tuple[3] =r.getBoolean(2) ?"f".getBytes() :"t".getBytes();
2679+
tuple[4] =null;
2680+
tuple[5] =r.getBytes(3);
2681+
tuple[6] =r.getBoolean(4) ?
2682+
Integer.toString(tableIndexClustered).getBytes() :
2683+
r.getString(5).equals("hash") ?
2684+
Integer.toString(tableIndexHashed).getBytes() :
2685+
Integer.toString(tableIndexOther).getBytes();
2686+
tuple[7] =Integer.toString(i +1).getBytes();
2687+
java.sql.ResultSetcolumnNameRS =connection.ExecSQL("select a.attname FROM pg_attribute a, pg_class c WHERE (a.attnum = " +columnOrdinals[i] +") AND (a.attrelid = " +r.getInt(8) +")");
2688+
columnNameRS.next();
2689+
tuple[8] =columnNameRS.getBytes(1);
2690+
tuple[9] =null;// sort sequence ???
2691+
tuple[10] =r.getBytes(7);// inexact
2692+
tuple[11] =r.getBytes(8);
2693+
tuple[12] =null;
2694+
v.addElement(tuple);
2695+
}
2696+
}
2697+
26462698
returnnewResultSet(connection,f,v,"OK",1);
26472699
}
26482700

‎src/interfaces/odbc/info.c

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2009,7 +2009,9 @@ SQLStatistics(
20092009
char*table_name;
20102010
charindex_name[MAX_INFO_STRING];
20112011
shortfields_vector[16];
2012-
charisunique[10];
2012+
charisunique[10],
2013+
isclustered[10],
2014+
ishash[MAX_INFO_STRING];
20132015
SDWORDindex_name_len,
20142016
fields_vector_len;
20152017
TupleNode*row;
@@ -2169,10 +2171,13 @@ SQLStatistics(
21692171
indx_stmt= (StatementClass*)hindx_stmt;
21702172

21712173
sprintf(index_query,"select c.relname, i.indkey, i.indisunique"
2172-
", c.relhasrules"
2173-
" from pg_index i, pg_class c, pg_class d"
2174-
" where c.oid = i.indexrelid and d.relname = '%s'"
2175-
" and d.oid = i.indrelid",table_name);
2174+
", x.indisclustered, a.amname, i.relhasrules"
2175+
" from pg_index x, pg_class i, pg_class c, pg_am a"
2176+
" where c.relname = '%s'"
2177+
" and c.oid = x.indrelid"
2178+
" and x.indexrelid = i.oid"
2179+
" and i.relam = a.oid"
2180+
,table_name);
21762181

21772182
result=SQLExecDirect(hindx_stmt,index_query,strlen(index_query));
21782183
if ((result!=SQL_SUCCESS)&& (result!=SQL_SUCCESS_WITH_INFO))
@@ -2224,7 +2229,33 @@ SQLStatistics(
22242229
gotoSEEYA;
22252230
}
22262231

2232+
/* bind the "is clustered" column */
22272233
result=SQLBindCol(hindx_stmt,4,SQL_C_CHAR,
2234+
isclustered,sizeof(isclustered),NULL);
2235+
if ((result!=SQL_SUCCESS)&& (result!=SQL_SUCCESS_WITH_INFO))
2236+
{
2237+
stmt->errormsg=indx_stmt->errormsg;/* "Couldn't bind column
2238+
* in SQLStatistics."; */
2239+
stmt->errornumber=indx_stmt->errornumber;
2240+
SQLFreeStmt(hindx_stmt,SQL_DROP);
2241+
gotoSEEYA;
2242+
2243+
}
2244+
2245+
/* bind the "is hash" column */
2246+
result=SQLBindCol(hindx_stmt,5,SQL_C_CHAR,
2247+
ishash,sizeof(ishash),NULL);
2248+
if ((result!=SQL_SUCCESS)&& (result!=SQL_SUCCESS_WITH_INFO))
2249+
{
2250+
stmt->errormsg=indx_stmt->errormsg;/* "Couldn't bind column
2251+
* in SQLStatistics."; */
2252+
stmt->errornumber=indx_stmt->errornumber;
2253+
SQLFreeStmt(hindx_stmt,SQL_DROP);
2254+
gotoSEEYA;
2255+
2256+
}
2257+
2258+
result=SQLBindCol(hindx_stmt,6,SQL_C_CHAR,
22282259
relhasrules,MAX_INFO_STRING,NULL);
22292260
if ((result!=SQL_SUCCESS)&& (result!=SQL_SUCCESS_WITH_INFO))
22302261
{
@@ -2255,6 +2286,9 @@ SQLStatistics(
22552286
sprintf(buf,"%s_idx_fake_oid",table_name);
22562287
set_tuplefield_string(&row->tuple[5],buf);
22572288

2289+
/*
2290+
* Clustered/HASH index?
2291+
*/
22582292
set_tuplefield_int2(&row->tuple[6], (Int2)SQL_INDEX_OTHER);
22592293
set_tuplefield_int2(&row->tuple[7], (Int2)1);
22602294

@@ -2297,7 +2331,12 @@ SQLStatistics(
22972331
set_tuplefield_string(&row->tuple[4],"");
22982332
set_tuplefield_string(&row->tuple[5],index_name);
22992333

2300-
set_tuplefield_int2(&row->tuple[6], (Int2)SQL_INDEX_OTHER);
2334+
/*
2335+
* Clustered/HASH index?
2336+
*/
2337+
set_tuplefield_int2(&row->tuple[6], (Int2)
2338+
(atoi(isclustered) ?SQL_INDEX_CLUSTERED :
2339+
(!strncmp(ishash,"hash",4)) ?SQL_INDEX_HASHED :SQL_INDEX_OTHER);
23012340
set_tuplefield_int2(&row->tuple[7], (Int2) (i+1));
23022341

23032342
if (fields_vector[i]==OID_ATTNUM)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp