[ODBC] Need assistance with ODBC bytea data please - Mailing list pgsql-odbc

From Ben Postma
Subject [ODBC] Need assistance with ODBC bytea data please
Date
Msg-id BY2PR13MB0854FC414A7A54ECB44F9A7BE8710@BY2PR13MB0854.namprd13.prod.outlook.com
Whole thread Raw
Responses Re: [ODBC] Need assistance with ODBC bytea data please  ("Inoue, Hiroshi" <h-inoue@dream.email.ne.jp>)
List pgsql-odbc

Hi,


Please help me resolve this issue, as we have a client who wants to use PostgreSQL.


ODBC Driver version: pslODBC 09_05_0499-x86

PostgreSQL version: 9.6.1.1

Windows OS 64 bit.


I have a table created with this statement:


CREATE TABLE PS_BLOB (CollectionID BIGINT, BLOBID BIGINT, BLOBType VARCHAR(255), BLOBName VARCHAR(255), TheBLOB BYTEA);


Note the last column which is of type BYTEA. Then I am preparing an insert statement and binding columns.  The last column is bound as follows:


ret = SQLBindParameter(ist, paramNumber, SQL_PARAM_INPUT, SQL_C_BINARY, SQL_LONGVARBINARY, columnSize,  0,  (void*)(i+1), 0,              &myBlobSizeMacro);


myBlobSIzeMacro gets set to SQL_LEN_DATA_AT_EXEC(myBlobSize);


SQLExecute correctly returns 99 asking for data for the last column. And SQLPutData puts the correct amount of data, no issue. No errors. And you can see the blob size in the log file below.


And yet, if you look in pgAdmin4 then for the BLOB column it shows a number like 124618 or something. And in my code when you try and read the blob again, SQLGetData returns a size of 5 in the last argument, as if the blob is only 5 bytes, when it much larger than that.


The log details are below. Please note:

- The exact same blob code works perfectly fine with SQL Server, MariaDB etc. So it is unlikely to be my code I hope.

- The wrong blob data issue issue manifests only the very first time the blob is written, subsequent calls to write another blob succeeds and the correct data gets written and returned again.


I have tried calling SQLPutData with smaller chunks, but that has no impact.


Any ideas? Please advise!


I have looked at the relevant psqlODBC code but I do not see any obvious issue. One option would be for me to compile the source code and overwrite the installed DLLs and then step through SQLPutData in odbcapi.c and see what PGAPI_PutData in execute.c actually does. But the log file below is fairly detailed, maybe someone more familiar with it can go "Oh yes, for larger blobs we need to fix x, or you need to y". It looks like the code just ends up in SOCK_put_n_char which has to be doing the right thing. So I do not see any potential issues in the psqlODBC source code, it all looks good.


Please?

Thank you,

Ben.


[6340-26.785][SQLPrepareW][6340-26.785]PGAPI_Prepare: entering...
[6340-26.785]**** PGAPI_Prepare: STMT_ALLOCATED, copy
[6340-26.785][SQLSetStmtAttrW][6340-26.785]PGAPI_SetStmtAttr Handle=1FBBCDF8 18,0(00000000)
[6340-26.785][SQLBindParameter][6340-26.785]PGAPI_BindParameter: entering...
[6340-26.785]extend_parameter_bindings: entering ... self=1FBBCF08, parameters_allocated=0, num_params=1,00000000
[6340-26.785]exit extend_parameter_bindings=1FB52408
[6340-26.785]extend_iparameter_bindings: entering ... self=1FBBCF48, parameters_allocated=0, num_params=1
[6340-26.801]exit extend_iparameter_bindings=1FB52368
[6340-26.801]extend_putdata_info: entering ... self=1FBBCFC4, parameters_allocated=0, num_params=1
[6340-26.801]exit extend_putdata_info=1FBB5CE8
[6340-26.801]PGAPI_BindParameter: ipar=0, paramType=1, fCType=-25, fSqlType=-5, cbColDef=1, ibScale=0,[6340-26.801]rgbValue=07D6D238(8), pcbValue=1FD07F40
[6340-26.801][SQLBindParameter][6340-26.801]PGAPI_BindParameter: entering...
[6340-26.801]extend_parameter_bindings: entering ... self=1FBBCF08, parameters_allocated=1, num_params=2,1FB52408
[6340-26.801]exit extend_parameter_bindings=07D5E060
[6340-26.801]extend_iparameter_bindings: entering ... self=1FBBCF48, parameters_allocated=1, num_params=2
[6340-26.801]exit extend_iparameter_bindings=07D5E5D8
[6340-26.801]extend_putdata_info: entering ... self=1FBBCFC4, parameters_allocated=1, num_params=2
[6340-26.801]exit extend_putdata_info=1FB52308
[6340-26.801]PGAPI_BindParameter: ipar=1, paramType=1, fCType=-25, fSqlType=-5, cbColDef=1, ibScale=0,[6340-26.801]rgbValue=07D5E4E0(8), pcbValue=1FD08060
[6340-26.801][SQLBindParameter][6340-26.801]PGAPI_BindParameter: entering...
[6340-26.801]extend_parameter_bindings: entering ... self=1FBBCF08, parameters_allocated=2, num_params=3,07D5E060
[6340-26.801]exit extend_parameter_bindings=07FDC5D0
[6340-26.801]extend_iparameter_bindings: entering ... self=1FBBCF48, parameters_allocated=2, num_params=3
[6340-26.801]exit extend_iparameter_bindings=07FDC620
[6340-26.801]extend_putdata_info: entering ... self=1FBBCFC4, parameters_allocated=2, num_params=3
[6340-26.801]exit extend_putdata_info=1FD07B30
[6340-26.801]PGAPI_BindParameter: ipar=2, paramType=1, fCType=-8, fSqlType=-9, cbColDef=510, ibScale=0,[6340-26.801]rgbValue=1F7D5BC0(512), pcbValue=00000000
[6340-26.801][SQLBindParameter][6340-26.801]PGAPI_BindParameter: entering...
[6340-26.801]extend_parameter_bindings: entering ... self=1FBBCF08, parameters_allocated=3, num_params=4,07FDC5D0
[6340-26.801]exit extend_parameter_bindings=1FB7DB48
[6340-26.801]extend_iparameter_bindings: entering ... self=1FBBCF48, parameters_allocated=3, num_params=4
[6340-26.801]exit extend_iparameter_bindings=1FB7D6D0
[6340-26.801]extend_putdata_info: entering ... self=1FBBCFC4, parameters_allocated=3, num_params=4
[6340-26.801]exit extend_putdata_info=07D5E5D8
[6340-26.801]PGAPI_BindParameter: ipar=3, paramType=1, fCType=-8, fSqlType=-9, cbColDef=510, ibScale=0,[6340-26.801]rgbValue=1F7D44F0(512), pcbValue=00000000
[6340-26.801][SQLBindParameter][6340-26.801]PGAPI_BindParameter: entering...
[6340-26.801]extend_parameter_bindings: entering ... self=1FBBCF08, parameters_allocated=4, num_params=5,1FB7DB48
[6340-26.801]exit extend_parameter_bindings=07F310F8
[6340-26.801]extend_iparameter_bindings: entering ... self=1FBBCF48, parameters_allocated=4, num_params=5
[6340-26.801]exit extend_iparameter_bindings=07F31CF8
[6340-26.801]extend_putdata_info: entering ... self=1FBBCFC4, parameters_allocated=4, num_params=5
[6340-26.801]exit extend_putdata_info=1FAF3318
[6340-26.801]PGAPI_BindParameter: ipar=4, paramType=1, fCType=-2, fSqlType=-4, cbColDef=209715200, ibScale=0,[6340-26.801]rgbValue=00000001(0), pcbValue=07C643D9

[6340-26.801][SQLSetStmtAttrW][6340-26.801]PGAPI_SetStmtAttr Handle=1FBBCDF8 22,1(00000001)

[6340-26.801][SQLExecute][6340-26.801]PGAPI_Execute: entering...1
[6340-26.801]PGAPI_Execute: clear errors...
[6340-26.801]PGAPI_NumParams: entering...
[6340-26.801]SC_scanQueryAndCountParams: entering...
[6340-26.801]prepareParameters was not called, prepare state:7
[6340-26.817]SC_recycle_statement: self= 1FBBCDF8
[6340-26.817]PDATA_free_params:  ENTER, self=1FBBCFC4
[6340-26.817]PDATA_free_params:  EXIT
[6340-26.817]The 4th parameter of 0-row is data at exec(-124712)
[6340-26.817]retval=99
[6340-26.817][SQLParamData][6340-26.817]PGAPI_ParamData: entering...
[6340-26.817]PGAPI_ParamData: data_at_exec=1, params_alloc=5
[6340-26.817]PGAPI_ParamData: returning 99

[6340-26.817][SQLPutData][6340-26.817]PGAPI_PutData: entering...
[6340-26.817]PGAPI_PutData: (1) cbValue = 124612
[6340-26.817]CC_send_query: conn=07E91130, query='BEGIN'
[6340-26.817]in QR_Constructor
[6340-26.817]exit QR_Constructor
[6340-26.817]send_query: ok - 'C' - BEGIN
[6340-26.817]send_query: setting cmdbuffer = 'BEGIN'
[6340-26.817]send_query: returning res = 1F89E428
[6340-26.817]CC_begin:  sending BEGIN!
[6340-26.817]QResult: enter DESTRUCTOR
[6340-26.817]QResult: in QR_close_result
[6340-26.817]QResult: free memory in, fcount=0
[6340-26.817]QResult: free memory out
[6340-26.817]QResult: exit close_result
[6340-26.817]QResult: exit DESTRUCTOR
[6340-26.817]send_function(): conn=07E91130, fn_name=lo_creat, result_is_int=1, nargs=1
[6340-26.817]  arg[0]: len = 4, isint = 1, integer = 393216, ptr = 00060000
[6340-26.817]send_function: done sending function
[6340-26.817]send_function(): got result with length 4
[6340-26.817]send_function(): conn=07E91130, fn_name=lo_open, result_is_int=1, nargs=2
[6340-26.817]  arg[0]: len = 4, isint = 1, integer = 16627, ptr = 000040F3
[6340-26.817]  arg[1]: len = 4, isint = 1, integer = 131072, ptr = 00020000
[6340-26.817]send_function: done sending function
[6340-26.817]send_function(): got result with length 4
[6340-26.817]send_function(): conn=07E91130, fn_name=lo_lseek, result_is_int=1, nargs=3
[6340-26.817]  arg[0]: len = 4, isint = 1, integer = 0, ptr = 00000000
[6340-26.817]  arg[1]: len = 4, isint = 1, integer = 0, ptr = 00000000
[6340-26.817]  arg[2]: len = 4, isint = 1, integer = 0, ptr = 00000000
[6340-26.817]send_function: done sending function
[6340-26.817]send_function(): got result with length 4
[6340-26.817]send_function(): conn=07E91130, fn_name=lowrite, result_is_int=1, nargs=2
[6340-26.817]  arg[0]: len = 4, isint = 1, integer = 0, ptr = 00000000
[6340-26.817]  arg[1]: len = 124612, isint = 0, integer = 534868008, ptr = 1FE17028
[6340-26.817]send_function: done sending function
[6340-26.817]send_function(): got result with length 4
[6340-26.832]lo_write: cbValue=124612, wrote -6460 bytes

[6340-26.832][SQLParamData][6340-26.832]PGAPI_ParamData: entering...
[6340-26.832]PGAPI_ParamData: data_at_exec=0, params_alloc=5
[6340-26.832]send_function(): conn=07E91130, fn_name=lo_close, result_is_int=1, nargs=1
[6340-26.832]  arg[0]: len = 4, isint = 1, integer = 0, ptr = 00000000
[6340-26.832]send_function: done sending function
[6340-26.832]send_function(): got result with length 4
[6340-26.832]CC_cursor_count: self=07E91130, num_stmts=16
[6340-26.832]CC_cursor_count: returning 0

[6340-26.832]Exec_with_parameters_resolved: copying statement params: trans_status=2, len=100, stmt='INSERT INTO PS_BLOB (CollectionID, BLOBID, BLOBType, BLOBName, TheBLOB) VALUES (?, ?, ?, ?, ?)'
[6340-26.832]   stmt_with_params = '(null)'
[6340-26.832]about to begin SC_execute
[6340-26.832]CC_send_query: conn=07E91130, query='SAVEPOINT _EXEC_SVP_1FBBCDF8'
[6340-26.832]in QR_Constructor
[6340-26.832]exit QR_Constructor
[6340-26.832]send_query: ok - 'C' - SAVEPOINT
[6340-26.832]send_query: setting cmdbuffer = 'SAVEPOINT'
[6340-26.832]send_query: returning res = 1F89D7F0
[6340-26.832]QResult: enter DESTRUCTOR
[6340-26.832]QResult: in QR_close_result
[6340-26.832]QResult: free memory in, fcount=0
[6340-26.832]QResult: free memory out
[6340-26.832]QResult: exit close_result
[6340-26.832]QResult: exit DESTRUCTOR
[6340-26.832]libpq_bind_and_exec: bind stmt=1FBBCDF8
[6340-26.832]ResolveOneParam: from(fcType)=-25, to(fSqlType)=-5(20), *pgType=20
[6340-26.832]cvt_null_date_string=0 pgtype=20 buf=00000000
[6340-26.832]ResolveOneParam: from(fcType)=-25, to(fSqlType)=-5(20), *pgType=20
[6340-26.832]cvt_null_date_string=0 pgtype=20 buf=00000000
[6340-26.832]ResolveOneParam: from(fcType)=-8, to(fSqlType)=-9(1043), *pgType=0
[6340-26.832]C_WCHAR=F(-3)
[6340-26.832]cvt_null_date_string=0 pgtype=1043 buf=1FC74180
[6340-26.832]ResolveOneParam: from(fcType)=-8, to(fSqlType)=-9(1043), *pgType=0
[6340-26.832]C_WCHAR=L(-3)
[6340-26.832]cvt_null_date_string=0 pgtype=1043 buf=1FD07B30
[6340-26.832]ResolveOneParam: from(fcType)=-2, to(fSqlType)=-4(4294966297), *pgType=0
[6340-26.832]cvt_null_date_string=0 pgtype=-999 buf=00000000
[6340-26.832]libpq_bind_and_exec: execute stmt=1FBBCDF8
[6340-26.832]SC_scanQueryAndCountParams: entering...
[6340-26.832]SC_scanQueryAndCountParams: entering...
[6340-26.832]process_statements:parsed for the first command length=-1(-1) num_p=5
[6340-26.832]ParseAndDescribeWithLibpq: plan_name=_PLAN1FBBCDF8 query=INSERT INTO PetroSIM_BLOB (CollectionID, BLOBID, BLOBType, BLOBName, TheBLOB) VALUES ($1, $2, $3, $4, $5)
[6340-26.832]in QR_Constructor
[6340-26.832]exit QR_Constructor
[6340-26.832]ParseWithLibpq: plan_name=_PLAN1FBBCDF8 query=INSERT INTO PetroSIM_BLOB (CollectionID, BLOBID, BLOBType, BLOBName, TheBLOB) VALUES ($1, $2, $3, $4, $5)
[6340-26.832]sta_pidx=0 end_pidx=4 num_p=5
[6340-26.832]ipdopts->allocated: 5
[6340-26.832]PQprepare was successful, plan=_PLAN1FBBCDF8
[6340-26.832]ParseAndDescribeWithLibpq: describing plan_name=_PLAN1FBBCDF8
[6340-26.848]extend_iparameter_bindings: entering ... self=1FBBCF48, parameters_allocated=5, num_params=5
[6340-26.848]exit extend_iparameter_bindings=07F31CF8
[6340-26.848]num_fields = 0
[6340-26.848]SC_set_Result(1fbbcdf8, 1f89d7f0)[6340-26.848]QResult: enter DESTRUCTOR
[6340-26.848]command response: INSERT 0 1
[6340-26.848]dequeueNeedDataCallback ret=0 count=0
[6340-26.848]PGAPI_ParamData: returning 0
[6340-26.848]CC_send_query: conn=07E91130, query='RELEASE _EXEC_SVP_1FBBCDF8'
[6340-26.848]in QR_Constructor
[6340-26.848]exit QR_Constructor
[6340-26.848]send_query: ok - 'C' - RELEASE
[6340-26.848]send_query: setting cmdbuffer = 'RELEASE'
[6340-26.848]send_query: returning res = 1F89EAA0
[6340-26.848]QResult: enter DESTRUCTOR
[6340-26.848]QResult: in QR_close_result
[6340-26.848]QResult: free memory in, fcount=0
[6340-26.848]QResult: free memory out
[6340-26.848]QResult: exit close_result
[6340-26.848]QResult: exit DESTRUCTOR
[6340-26.848][[SQLEndTran]][6340-26.848]entering PGAPI_Transact: hdbc=07E91130, henv=00000000
[6340-26.848]PGAPI_Transact: sending on conn 07E91130 '0'
[6340-26.848]CC_send_query: conn=07E91130, query='COMMIT'
[6340-26.848]in QR_Constructor
[6340-26.848]exit QR_Constructor
[6340-26.848]send_query: ok - 'C' - COMMIT
[6340-26.848]send_query: setting cmdbuffer = 'COMMIT'
[6340-26.848]send_query: returning res = 1F89DE68
[6340-26.848]CC_commit:  sending COMMIT!
[6340-26.848]QResult: enter DESTRUCTOR
[6340-26.848]QResult: in QR_close_result
[6340-26.848]QResult: free memory in, fcount=0
[6340-26.848]QResult: free memory out
[6340-26.848]QResult: exit close_result
[6340-26.848]QResult: exit DESTRUCTOR



pgsql-odbc by date:

Previous
From: Lindsay Stevens
Date:
Subject: Re: [ODBC] Fwd: Connection string parameter sslrootcert does not work
Next
From: "Inoue, Hiroshi"
Date:
Subject: Re: [ODBC] Fwd: Connection string parameter sslrootcert does not work