@@ -705,8 +705,8 @@ Int2 sqlType;
705705set_nullfield_string (& row -> tuple [5 ],pgtype_create_params (stmt ,pgType ));
706706set_nullfield_int2 (& row -> tuple [9 ],pgtype_unsigned (stmt ,pgType ));
707707set_nullfield_int2 (& row -> tuple [11 ],pgtype_auto_increment (stmt ,pgType ));
708- set_nullfield_int2 (& row -> tuple [13 ],pgtype_scale (stmt ,pgType ));
709- set_nullfield_int2 (& row -> tuple [14 ],pgtype_scale (stmt ,pgType ));
708+ set_nullfield_int2 (& row -> tuple [13 ],pgtype_scale (stmt ,pgType , PG_STATIC ));
709+ set_nullfield_int2 (& row -> tuple [14 ],pgtype_scale (stmt ,pgType , PG_STATIC ));
710710
711711QR_add_tuple (stmt -> result ,row );
712712}
@@ -1179,8 +1179,9 @@ StatementClass *col_stmt;
11791179char columns_query [MAX_STATEMENT_LEN ];
11801180RETCODE result ;
11811181char table_owner [MAX_INFO_STRING ],table_name [MAX_INFO_STRING ],field_name [MAX_INFO_STRING ],field_type_name [MAX_INFO_STRING ];
1182- Int2 field_number ,result_cols ;
1183- Int4 field_type ,the_type ,field_length ,mod_length ;
1182+ Int2 field_number ,result_cols ,scale ;
1183+ Int4 field_type ,the_type ,field_length ,mod_length ,precision ;
1184+ char useStaticPrecision ;
11841185char not_null [MAX_INFO_STRING ],relhasrules [MAX_INFO_STRING ];
11851186ConnInfo * ci ;
11861187
@@ -1400,7 +1401,7 @@ ConnInfo *ci;
14001401set_tuplefield_int4 (& row -> tuple [7 ],pgtype_length (stmt ,the_type ,PG_STATIC ,PG_STATIC ));
14011402set_tuplefield_int4 (& row -> tuple [6 ],pgtype_precision (stmt ,the_type ,PG_STATIC ,PG_STATIC ));
14021403
1403- set_nullfield_int2 (& row -> tuple [8 ],pgtype_scale (stmt ,the_type ));
1404+ set_nullfield_int2 (& row -> tuple [8 ],pgtype_scale (stmt ,the_type , PG_STATIC ));
14041405set_nullfield_int2 (& row -> tuple [9 ],pgtype_radix (stmt ,the_type ));
14051406set_tuplefield_int2 (& row -> tuple [10 ],SQL_NO_NULLS );
14061407set_tuplefield_string (& row -> tuple [11 ],"" );
@@ -1433,10 +1434,42 @@ ConnInfo *ci;
14331434VARCHAR - the length is stored in the pg_attribute.atttypmod field
14341435BPCHAR - the length is also stored as varchar is
14351436
1437+ NUMERIC - the scale is stored in atttypmod as follows:
1438+ precision = ((atttypmod - VARHDRSZ) >> 16) & 0xffff
1439+ scale = (atttypmod - VARHDRSZ) & 0xffff
1440+
1441+
14361442*/
1443+ qlog ("SQLColumns: table='%s',field_name='%s',type=%d,sqltype=%d,name='%s'\n" ,
1444+ table_name ,field_name ,field_type ,pgtype_to_sqltype ,field_type_name );
1445+
1446+ useStaticPrecision = TRUE;
1447+
1448+ if (field_type == PG_TYPE_NUMERIC ) {
1449+ if (mod_length >=4 )
1450+ mod_length -= 4 ;// the length is in atttypmod - 4
1451+
1452+ if (mod_length >=0 ) {
1453+ useStaticPrecision = FALSE;
1454+
1455+ precision = (mod_length >>16 )& 0xffff ;
1456+ scale = mod_length & 0xffff ;
1457+
1458+ mylog ("SQLColumns: field type is NUMERIC: field_type = %d, mod_length=%d, precision=%d, scale=%d\n" ,field_type ,mod_length ,precision ,scale );
1459+
1460+ set_tuplefield_int4 (& row -> tuple [7 ],precision + 2 );// sign+dec.point
1461+ set_tuplefield_int4 (& row -> tuple [6 ],precision );
1462+ set_tuplefield_int4 (& row -> tuple [12 ],precision + 2 );// sign+dec.point
1463+ set_nullfield_int2 (& row -> tuple [8 ],scale );
1464+ }
1465+ }
1466+
1467+
14371468if ((field_type == PG_TYPE_VARCHAR )||
14381469 (field_type == PG_TYPE_BPCHAR )) {
14391470
1471+ useStaticPrecision = FALSE;
1472+
14401473if (mod_length >=4 )
14411474mod_length -= 4 ;// the length is in atttypmod - 4
14421475
@@ -1445,19 +1478,21 @@ ConnInfo *ci;
14451478
14461479mylog ("SQLColumns: field type is VARCHAR,BPCHAR: field_type = %d, mod_length = %d\n" ,field_type ,mod_length );
14471480
1448- set_tuplefield_int4 (& row -> tuple [7 ],mod_length );
1481+ set_tuplefield_int4 (& row -> tuple [7 ],mod_length );
14491482set_tuplefield_int4 (& row -> tuple [6 ],mod_length );
14501483set_tuplefield_int4 (& row -> tuple [12 ],mod_length );
1451- }else {
1484+ set_nullfield_int2 (& row -> tuple [8 ],pgtype_scale (stmt ,field_type ,PG_STATIC ));
1485+ }
1486+
1487+ if (useStaticPrecision ) {
14521488mylog ("SQLColumns: field type is OTHER: field_type = %d, pgtype_length = %d\n" ,field_type ,pgtype_length (stmt ,field_type ,PG_STATIC ,PG_STATIC ));
14531489
14541490set_tuplefield_int4 (& row -> tuple [7 ],pgtype_length (stmt ,field_type ,PG_STATIC ,PG_STATIC ));
14551491set_tuplefield_int4 (& row -> tuple [6 ],pgtype_precision (stmt ,field_type ,PG_STATIC ,PG_STATIC ));
14561492set_tuplefield_int4 (& row -> tuple [12 ],pgtype_display_size (stmt ,field_type ,PG_STATIC ,PG_STATIC ));
1457-
1493+ set_nullfield_int2 ( & row -> tuple [ 8 ], pgtype_scale ( stmt , field_type , PG_STATIC ));
14581494 }
14591495
1460- set_nullfield_int2 (& row -> tuple [8 ],pgtype_scale (stmt ,field_type ));
14611496set_nullfield_int2 (& row -> tuple [9 ],pgtype_radix (stmt ,field_type ));
14621497set_tuplefield_int2 (& row -> tuple [10 ], (Int2 ) (not_null [0 ]== '1' ?SQL_NO_NULLS :pgtype_nullable (stmt ,field_type )));
14631498set_tuplefield_string (& row -> tuple [11 ],"" );
@@ -1494,7 +1529,7 @@ ConnInfo *ci;
14941529set_tuplefield_string (& row -> tuple [5 ],pgtype_to_name (stmt ,the_type ));
14951530set_tuplefield_int4 (& row -> tuple [6 ],pgtype_precision (stmt ,the_type ,PG_STATIC ,PG_STATIC ));
14961531set_tuplefield_int4 (& row -> tuple [7 ],pgtype_length (stmt ,the_type ,PG_STATIC ,PG_STATIC ));
1497- set_nullfield_int2 (& row -> tuple [8 ],pgtype_scale (stmt ,the_type ));
1532+ set_nullfield_int2 (& row -> tuple [8 ],pgtype_scale (stmt ,the_type , PG_STATIC ));
14981533set_nullfield_int2 (& row -> tuple [9 ],pgtype_radix (stmt ,the_type ));
14991534set_tuplefield_int2 (& row -> tuple [10 ],SQL_NO_NULLS );
15001535set_tuplefield_string (& row -> tuple [11 ],"" );
@@ -1622,7 +1657,7 @@ mylog("%s: entering...stmt=%u\n", func, stmt);
16221657set_tuplefield_string (& row -> tuple [3 ],"OID" );
16231658set_tuplefield_int4 (& row -> tuple [4 ],pgtype_precision (stmt ,PG_TYPE_OID ,PG_STATIC ,PG_STATIC ));
16241659set_tuplefield_int4 (& row -> tuple [5 ],pgtype_length (stmt ,PG_TYPE_OID ,PG_STATIC ,PG_STATIC ));
1625- set_tuplefield_int2 (& row -> tuple [6 ],pgtype_scale (stmt ,PG_TYPE_OID ));
1660+ set_tuplefield_int2 (& row -> tuple [6 ],pgtype_scale (stmt ,PG_TYPE_OID , PG_STATIC ));
16261661set_tuplefield_int2 (& row -> tuple [7 ],SQL_PC_PSEUDO );
16271662
16281663QR_add_tuple (stmt -> result ,row );
@@ -1640,7 +1675,7 @@ mylog("%s: entering...stmt=%u\n", func, stmt);
16401675set_tuplefield_string (& row -> tuple [3 ],pgtype_to_name (stmt ,the_type ));
16411676set_tuplefield_int4 (& row -> tuple [4 ],pgtype_precision (stmt ,the_type ,PG_STATIC ,PG_STATIC ));
16421677set_tuplefield_int4 (& row -> tuple [5 ],pgtype_length (stmt ,the_type ,PG_STATIC ,PG_STATIC ));
1643- set_tuplefield_int2 (& row -> tuple [6 ],pgtype_scale (stmt ,the_type ));
1678+ set_tuplefield_int2 (& row -> tuple [6 ],pgtype_scale (stmt ,the_type , PG_STATIC ));
16441679set_tuplefield_int2 (& row -> tuple [7 ],SQL_PC_PSEUDO );
16451680
16461681QR_add_tuple (stmt -> result ,row );