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

Commit4403591

Browse files
author
Byron Nikolaidis
committed
Added numeric and int8 types.
Bug fix for LongVarBinary -- begin transaction
1 parent3a1218d commit4403591

File tree

7 files changed

+334
-29
lines changed

7 files changed

+334
-29
lines changed

‎src/interfaces/odbc/convert.c

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#include<math.h>
4141
#include"convert.h"
4242
#include"statement.h"
43+
#include"qresult.h"
4344
#include"bind.h"
4445
#include"pgtypes.h"
4546
#include"lobj.h"
@@ -895,6 +896,30 @@ int lobj_fd, retval;
895896

896897
}
897898
else {
899+
900+
/* begin transaction if needed */
901+
if(!CC_is_in_trans(stmt->hdbc)) {
902+
QResultClass*res;
903+
charok;
904+
905+
res=CC_send_query(stmt->hdbc,"BEGIN",NULL);
906+
if (!res) {
907+
stmt->errormsg="Could not begin (in-line) a transaction";
908+
stmt->errornumber=STMT_EXEC_ERROR;
909+
SC_log_error(func,"",stmt);
910+
returnSQL_ERROR;
911+
}
912+
ok=QR_command_successful(res);
913+
QR_Destructor(res);
914+
if (!ok) {
915+
stmt->errormsg="Could not begin (in-line) a transaction";
916+
stmt->errornumber=STMT_EXEC_ERROR;
917+
SC_log_error(func,"",stmt);
918+
returnSQL_ERROR;
919+
}
920+
921+
CC_set_in_trans(stmt->hdbc);
922+
}
898923

899924
/*store the oid */
900925
lobj_oid=lo_creat(stmt->hdbc,INV_READ |INV_WRITE);
@@ -917,6 +942,30 @@ int lobj_fd, retval;
917942
retval=lo_write(stmt->hdbc,lobj_fd,buffer,used);
918943

919944
lo_close(stmt->hdbc,lobj_fd);
945+
946+
/* commit transaction if needed */
947+
if (!globals.use_declarefetch&&CC_is_in_autocommit(stmt->hdbc)) {
948+
QResultClass*res;
949+
charok;
950+
951+
res=CC_send_query(stmt->hdbc,"COMMIT",NULL);
952+
if (!res) {
953+
stmt->errormsg="Could not commit (in-line) a transaction";
954+
stmt->errornumber=STMT_EXEC_ERROR;
955+
SC_log_error(func,"",stmt);
956+
returnSQL_ERROR;
957+
}
958+
ok=QR_command_successful(res);
959+
QR_Destructor(res);
960+
if (!ok) {
961+
stmt->errormsg="Could not commit (in-line) a transaction";
962+
stmt->errornumber=STMT_EXEC_ERROR;
963+
SC_log_error(func,"",stmt);
964+
returnSQL_ERROR;
965+
}
966+
967+
CC_set_no_trans(stmt->hdbc);
968+
}
920969
}
921970

922971
/*the oid of the large object -- just put that in for the
@@ -1340,6 +1389,29 @@ BindInfoClass *bindInfo = NULL;
13401389
*/
13411390

13421391
if ( !bindInfo||bindInfo->data_left==-1) {
1392+
1393+
/* begin transaction if needed */
1394+
if(!CC_is_in_trans(stmt->hdbc)) {
1395+
QResultClass*res;
1396+
charok;
1397+
1398+
res=CC_send_query(stmt->hdbc,"BEGIN",NULL);
1399+
if (!res) {
1400+
stmt->errormsg="Could not begin (in-line) a transaction";
1401+
stmt->errornumber=STMT_EXEC_ERROR;
1402+
returnCOPY_GENERAL_ERROR;
1403+
}
1404+
ok=QR_command_successful(res);
1405+
QR_Destructor(res);
1406+
if (!ok) {
1407+
stmt->errormsg="Could not begin (in-line) a transaction";
1408+
stmt->errornumber=STMT_EXEC_ERROR;
1409+
returnCOPY_GENERAL_ERROR;
1410+
}
1411+
1412+
CC_set_in_trans(stmt->hdbc);
1413+
}
1414+
13431415
oid=atoi(value);
13441416
stmt->lobj_fd=lo_open(stmt->hdbc,oid,INV_READ);
13451417
if (stmt->lobj_fd<0) {
@@ -1374,6 +1446,29 @@ BindInfoClass *bindInfo = NULL;
13741446
retval=lo_read(stmt->hdbc,stmt->lobj_fd, (char*)rgbValue,cbValueMax);
13751447
if (retval<0) {
13761448
lo_close(stmt->hdbc,stmt->lobj_fd);
1449+
1450+
/* commit transaction if needed */
1451+
if (!globals.use_declarefetch&&CC_is_in_autocommit(stmt->hdbc)) {
1452+
QResultClass*res;
1453+
charok;
1454+
1455+
res=CC_send_query(stmt->hdbc,"COMMIT",NULL);
1456+
if (!res) {
1457+
stmt->errormsg="Could not commit (in-line) a transaction";
1458+
stmt->errornumber=STMT_EXEC_ERROR;
1459+
returnCOPY_GENERAL_ERROR;
1460+
}
1461+
ok=QR_command_successful(res);
1462+
QR_Destructor(res);
1463+
if (!ok) {
1464+
stmt->errormsg="Could not commit (in-line) a transaction";
1465+
stmt->errornumber=STMT_EXEC_ERROR;
1466+
returnCOPY_GENERAL_ERROR;
1467+
}
1468+
1469+
CC_set_no_trans(stmt->hdbc);
1470+
}
1471+
13771472
stmt->lobj_fd=-1;
13781473

13791474
stmt->errornumber=STMT_EXEC_ERROR;
@@ -1396,6 +1491,29 @@ BindInfoClass *bindInfo = NULL;
13961491

13971492
if (!bindInfo||bindInfo->data_left==0) {
13981493
lo_close(stmt->hdbc,stmt->lobj_fd);
1494+
1495+
/* commit transaction if needed */
1496+
if (!globals.use_declarefetch&&CC_is_in_autocommit(stmt->hdbc)) {
1497+
QResultClass*res;
1498+
charok;
1499+
1500+
res=CC_send_query(stmt->hdbc,"COMMIT",NULL);
1501+
if (!res) {
1502+
stmt->errormsg="Could not commit (in-line) a transaction";
1503+
stmt->errornumber=STMT_EXEC_ERROR;
1504+
returnCOPY_GENERAL_ERROR;
1505+
}
1506+
ok=QR_command_successful(res);
1507+
QR_Destructor(res);
1508+
if (!ok) {
1509+
stmt->errormsg="Could not commit (in-line) a transaction";
1510+
stmt->errornumber=STMT_EXEC_ERROR;
1511+
returnCOPY_GENERAL_ERROR;
1512+
}
1513+
1514+
CC_set_no_trans(stmt->hdbc);
1515+
}
1516+
13991517
stmt->lobj_fd=-1;/* prevent further reading */
14001518
}
14011519

‎src/interfaces/odbc/execute.c

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,31 @@ int i, retval;
517517
/* close the large object */
518518
if (stmt->lobj_fd >=0) {
519519
lo_close(stmt->hdbc,stmt->lobj_fd);
520+
521+
/* commit transaction if needed */
522+
if (!globals.use_declarefetch&&CC_is_in_autocommit(stmt->hdbc)) {
523+
QResultClass*res;
524+
charok;
525+
526+
res=CC_send_query(stmt->hdbc,"COMMIT",NULL);
527+
if (!res) {
528+
stmt->errormsg="Could not commit (in-line) a transaction";
529+
stmt->errornumber=STMT_EXEC_ERROR;
530+
SC_log_error(func,"",stmt);
531+
returnSQL_ERROR;
532+
}
533+
ok=QR_command_successful(res);
534+
QR_Destructor(res);
535+
if (!ok) {
536+
stmt->errormsg="Could not commit (in-line) a transaction";
537+
stmt->errornumber=STMT_EXEC_ERROR;
538+
SC_log_error(func,"",stmt);
539+
returnSQL_ERROR;
540+
}
541+
542+
CC_set_no_trans(stmt->hdbc);
543+
}
544+
520545
stmt->lobj_fd=-1;
521546
}
522547

@@ -607,6 +632,30 @@ char *buffer;
607632
/*Handle Long Var Binary with Large Objects */
608633
if (current_param->SQLType==SQL_LONGVARBINARY) {
609634

635+
/* begin transaction if needed */
636+
if(!CC_is_in_trans(stmt->hdbc)) {
637+
QResultClass*res;
638+
charok;
639+
640+
res=CC_send_query(stmt->hdbc,"BEGIN",NULL);
641+
if (!res) {
642+
stmt->errormsg="Could not begin (in-line) a transaction";
643+
stmt->errornumber=STMT_EXEC_ERROR;
644+
SC_log_error(func,"",stmt);
645+
returnSQL_ERROR;
646+
}
647+
ok=QR_command_successful(res);
648+
QR_Destructor(res);
649+
if (!ok) {
650+
stmt->errormsg="Could not begin (in-line) a transaction";
651+
stmt->errornumber=STMT_EXEC_ERROR;
652+
SC_log_error(func,"",stmt);
653+
returnSQL_ERROR;
654+
}
655+
656+
CC_set_in_trans(stmt->hdbc);
657+
}
658+
610659
/*store the oid */
611660
current_param->lobj_oid=lo_creat(stmt->hdbc,INV_READ |INV_WRITE);
612661
if (current_param->lobj_oid==0) {

‎src/interfaces/odbc/info.c

Lines changed: 47 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -705,8 +705,8 @@ Int2 sqlType;
705705
set_nullfield_string(&row->tuple[5],pgtype_create_params(stmt,pgType));
706706
set_nullfield_int2(&row->tuple[9],pgtype_unsigned(stmt,pgType));
707707
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));
710710

711711
QR_add_tuple(stmt->result,row);
712712
}
@@ -1179,8 +1179,9 @@ StatementClass *col_stmt;
11791179
charcolumns_query[MAX_STATEMENT_LEN];
11801180
RETCODEresult;
11811181
chartable_owner[MAX_INFO_STRING],table_name[MAX_INFO_STRING],field_name[MAX_INFO_STRING],field_type_name[MAX_INFO_STRING];
1182-
Int2field_number,result_cols;
1183-
Int4field_type,the_type,field_length,mod_length;
1182+
Int2field_number,result_cols,scale;
1183+
Int4field_type,the_type,field_length,mod_length,precision;
1184+
charuseStaticPrecision;
11841185
charnot_null[MAX_INFO_STRING],relhasrules[MAX_INFO_STRING];
11851186
ConnInfo*ci;
11861187

@@ -1400,7 +1401,7 @@ ConnInfo *ci;
14001401
set_tuplefield_int4(&row->tuple[7],pgtype_length(stmt,the_type,PG_STATIC,PG_STATIC));
14011402
set_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));
14041405
set_nullfield_int2(&row->tuple[9],pgtype_radix(stmt,the_type));
14051406
set_tuplefield_int2(&row->tuple[10],SQL_NO_NULLS);
14061407
set_tuplefield_string(&row->tuple[11],"");
@@ -1433,10 +1434,42 @@ ConnInfo *ci;
14331434
VARCHAR - the length is stored in the pg_attribute.atttypmod field
14341435
BPCHAR - 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+
14371468
if((field_type==PG_TYPE_VARCHAR)||
14381469
(field_type==PG_TYPE_BPCHAR)) {
14391470

1471+
useStaticPrecision= FALSE;
1472+
14401473
if (mod_length >=4)
14411474
mod_length-=4;// the length is in atttypmod - 4
14421475

@@ -1445,19 +1478,21 @@ ConnInfo *ci;
14451478

14461479
mylog("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);
14491482
set_tuplefield_int4(&row->tuple[6],mod_length);
14501483
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) {
14521488
mylog("SQLColumns: field type is OTHER: field_type = %d, pgtype_length = %d\n",field_type,pgtype_length(stmt,field_type,PG_STATIC,PG_STATIC));
14531489

14541490
set_tuplefield_int4(&row->tuple[7],pgtype_length(stmt,field_type,PG_STATIC,PG_STATIC));
14551491
set_tuplefield_int4(&row->tuple[6],pgtype_precision(stmt,field_type,PG_STATIC,PG_STATIC));
14561492
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));
14581494
}
14591495

1460-
set_nullfield_int2(&row->tuple[8],pgtype_scale(stmt,field_type));
14611496
set_nullfield_int2(&row->tuple[9],pgtype_radix(stmt,field_type));
14621497
set_tuplefield_int2(&row->tuple[10], (Int2) (not_null[0]=='1' ?SQL_NO_NULLS :pgtype_nullable(stmt,field_type)));
14631498
set_tuplefield_string(&row->tuple[11],"");
@@ -1494,7 +1529,7 @@ ConnInfo *ci;
14941529
set_tuplefield_string(&row->tuple[5],pgtype_to_name(stmt,the_type));
14951530
set_tuplefield_int4(&row->tuple[6],pgtype_precision(stmt,the_type,PG_STATIC,PG_STATIC));
14961531
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));
14981533
set_nullfield_int2(&row->tuple[9],pgtype_radix(stmt,the_type));
14991534
set_tuplefield_int2(&row->tuple[10],SQL_NO_NULLS);
15001535
set_tuplefield_string(&row->tuple[11],"");
@@ -1622,7 +1657,7 @@ mylog("%s: entering...stmt=%u\n", func, stmt);
16221657
set_tuplefield_string(&row->tuple[3],"OID");
16231658
set_tuplefield_int4(&row->tuple[4],pgtype_precision(stmt,PG_TYPE_OID,PG_STATIC,PG_STATIC));
16241659
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));
16261661
set_tuplefield_int2(&row->tuple[7],SQL_PC_PSEUDO);
16271662

16281663
QR_add_tuple(stmt->result,row);
@@ -1640,7 +1675,7 @@ mylog("%s: entering...stmt=%u\n", func, stmt);
16401675
set_tuplefield_string(&row->tuple[3],pgtype_to_name(stmt,the_type));
16411676
set_tuplefield_int4(&row->tuple[4],pgtype_precision(stmt,the_type,PG_STATIC,PG_STATIC));
16421677
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));
16441679
set_tuplefield_int2(&row->tuple[7],SQL_PC_PSEUDO);
16451680

16461681
QR_add_tuple(stmt->result,row);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp