@@ -705,8 +705,8 @@ Int2 sqlType;
705
705
set_nullfield_string (& row -> tuple [5 ],pgtype_create_params (stmt ,pgType ));
706
706
set_nullfield_int2 (& row -> tuple [9 ],pgtype_unsigned (stmt ,pgType ));
707
707
set_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 ));
710
710
711
711
QR_add_tuple (stmt -> result ,row );
712
712
}
@@ -1179,8 +1179,9 @@ StatementClass *col_stmt;
1179
1179
char columns_query [MAX_STATEMENT_LEN ];
1180
1180
RETCODE result ;
1181
1181
char 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 ;
1184
1185
char not_null [MAX_INFO_STRING ],relhasrules [MAX_INFO_STRING ];
1185
1186
ConnInfo * ci ;
1186
1187
@@ -1400,7 +1401,7 @@ ConnInfo *ci;
1400
1401
set_tuplefield_int4 (& row -> tuple [7 ],pgtype_length (stmt ,the_type ,PG_STATIC ,PG_STATIC ));
1401
1402
set_tuplefield_int4 (& row -> tuple [6 ],pgtype_precision (stmt ,the_type ,PG_STATIC ,PG_STATIC ));
1402
1403
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 ));
1404
1405
set_nullfield_int2 (& row -> tuple [9 ],pgtype_radix (stmt ,the_type ));
1405
1406
set_tuplefield_int2 (& row -> tuple [10 ],SQL_NO_NULLS );
1406
1407
set_tuplefield_string (& row -> tuple [11 ],"" );
@@ -1433,10 +1434,42 @@ ConnInfo *ci;
1433
1434
VARCHAR - the length is stored in the pg_attribute.atttypmod field
1434
1435
BPCHAR - the length is also stored as varchar is
1435
1436
1437
+ NUMERIC - the scale is stored in atttypmod as follows:
1438
+ precision = ((atttypmod - VARHDRSZ) >> 16) & 0xffff
1439
+ scale = (atttypmod - VARHDRSZ) & 0xffff
1440
+
1441
+
1436
1442
*/
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
+
1437
1468
if ((field_type == PG_TYPE_VARCHAR )||
1438
1469
(field_type == PG_TYPE_BPCHAR )) {
1439
1470
1471
+ useStaticPrecision = FALSE;
1472
+
1440
1473
if (mod_length >=4 )
1441
1474
mod_length -= 4 ;// the length is in atttypmod - 4
1442
1475
@@ -1445,19 +1478,21 @@ ConnInfo *ci;
1445
1478
1446
1479
mylog ("SQLColumns: field type is VARCHAR,BPCHAR: field_type = %d, mod_length = %d\n" ,field_type ,mod_length );
1447
1480
1448
- set_tuplefield_int4 (& row -> tuple [7 ],mod_length );
1481
+ set_tuplefield_int4 (& row -> tuple [7 ],mod_length );
1449
1482
set_tuplefield_int4 (& row -> tuple [6 ],mod_length );
1450
1483
set_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 ) {
1452
1488
mylog ("SQLColumns: field type is OTHER: field_type = %d, pgtype_length = %d\n" ,field_type ,pgtype_length (stmt ,field_type ,PG_STATIC ,PG_STATIC ));
1453
1489
1454
1490
set_tuplefield_int4 (& row -> tuple [7 ],pgtype_length (stmt ,field_type ,PG_STATIC ,PG_STATIC ));
1455
1491
set_tuplefield_int4 (& row -> tuple [6 ],pgtype_precision (stmt ,field_type ,PG_STATIC ,PG_STATIC ));
1456
1492
set_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 ));
1458
1494
}
1459
1495
1460
- set_nullfield_int2 (& row -> tuple [8 ],pgtype_scale (stmt ,field_type ));
1461
1496
set_nullfield_int2 (& row -> tuple [9 ],pgtype_radix (stmt ,field_type ));
1462
1497
set_tuplefield_int2 (& row -> tuple [10 ], (Int2 ) (not_null [0 ]== '1' ?SQL_NO_NULLS :pgtype_nullable (stmt ,field_type )));
1463
1498
set_tuplefield_string (& row -> tuple [11 ],"" );
@@ -1494,7 +1529,7 @@ ConnInfo *ci;
1494
1529
set_tuplefield_string (& row -> tuple [5 ],pgtype_to_name (stmt ,the_type ));
1495
1530
set_tuplefield_int4 (& row -> tuple [6 ],pgtype_precision (stmt ,the_type ,PG_STATIC ,PG_STATIC ));
1496
1531
set_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 ));
1498
1533
set_nullfield_int2 (& row -> tuple [9 ],pgtype_radix (stmt ,the_type ));
1499
1534
set_tuplefield_int2 (& row -> tuple [10 ],SQL_NO_NULLS );
1500
1535
set_tuplefield_string (& row -> tuple [11 ],"" );
@@ -1622,7 +1657,7 @@ mylog("%s: entering...stmt=%u\n", func, stmt);
1622
1657
set_tuplefield_string (& row -> tuple [3 ],"OID" );
1623
1658
set_tuplefield_int4 (& row -> tuple [4 ],pgtype_precision (stmt ,PG_TYPE_OID ,PG_STATIC ,PG_STATIC ));
1624
1659
set_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 ));
1626
1661
set_tuplefield_int2 (& row -> tuple [7 ],SQL_PC_PSEUDO );
1627
1662
1628
1663
QR_add_tuple (stmt -> result ,row );
@@ -1640,7 +1675,7 @@ mylog("%s: entering...stmt=%u\n", func, stmt);
1640
1675
set_tuplefield_string (& row -> tuple [3 ],pgtype_to_name (stmt ,the_type ));
1641
1676
set_tuplefield_int4 (& row -> tuple [4 ],pgtype_precision (stmt ,the_type ,PG_STATIC ,PG_STATIC ));
1642
1677
set_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 ));
1644
1679
set_tuplefield_int2 (& row -> tuple [7 ],SQL_PC_PSEUDO );
1645
1680
1646
1681
QR_add_tuple (stmt -> result ,row );