Ticket #1623 (closed defect: fixed)

Opened 1 year ago

Last modified 1 year ago

BLOB support in SQLite driver not working

Reported by: Kosta Assigned to: mloskot
Priority: normal Milestone: 1.4.2
Component: OGR_SF Version: unspecified
Severity: normal Keywords: SQLite BLOB
Cc: warmerdam

Description

The BLOB support in the SQLite driver is completely messed up. There are similar issues as in the MySQL driver (ticket #1622)...

A patch fixing the issues is attached...

Attachments

sqlite_blob.patch (4.3 kB) - added by Kosta on 05/09/07 07:19:52.
bug fix for BLOB support in the SQLite driver
sqlite_blob_simple_test.zip (2.6 kB) - added by mloskot on 05/11/07 12:26:03.
This is simple test of read and write BLOB data to SQLite database. This test uses WKB stream read from multipoint.wkb file, as a sample binary data.

Change History

05/09/07 07:19:52 changed by Kosta

  • attachment sqlite_blob.patch added.

bug fix for BLOB support in the SQLite driver

05/09/07 09:20:34 changed by warmerdam

  • owner changed from warmerdam to mloskot.
  • cc set to warmerdam.
  • severity changed from major to normal.
  • milestone set to 1.4.2.

Matuesz,

Please verify the problem, incorporate the patch with checking and then add a test script entry for blob support. If this slips past 1.4.2 that is ok. If it seems quite dangerous you can limit it to trunk.

05/10/07 08:53:32 changed by mloskot

  • status changed from new to assigned.

05/11/07 04:14:05 changed by mloskot

There is a need for a mechanism of escaping special bytes like \0 in binary stream. The ExecuteSQL() function is passed with complete SQL statement, so I don't think we can provide this functionality there. I think it should be clearly stated that user is responsible to encode binary stream before putting it inside the SQL statement.

Most DBMS interfaces for Python offer their own functionality, special class or function to wrap BLOB data before sending to the SQL command. GDAL (CPL) also provides some functions for that, but I'm not if they are exposed in SWIG bindings.

I'd appreciate some comments about what strategy we should follow.

05/11/07 04:17:13 changed by mloskot

Small addition to my last comment. There are exposed functions like EscapeString? and UnescapeString? by the traditional Python bindings.

05/11/07 04:24:41 changed by Kosta

Why do you need to escape these special characters?

The binary data is sent to the SQL processor in hex-string-format, such as: x'ab12f3'

I used the CPLBinaryToHex() function in my patch, to create this hex-string representations...

(follow-up: ↓ 8 ) 05/11/07 04:30:40 changed by mloskot

Kosta,

I understand it but this solution introduces, implicitly, requirement that all binary data in SQL statements should be encoede in HEX string. Am I right?

At least, it should be documented and clearly said it's not possible to use any other encoding.

05/11/07 04:52:08 changed by mloskot

Kosta,

Could you attach a piece of code presenting your patch in action: - insert binary data into SQLite - fetch binary data into SQLite

In C, C++, Python, whatever.

Simply, I'm not sure of all assumptions you've made, so the patch in action would help.

(in reply to: ↑ 6 ) 05/11/07 06:45:56 changed by Kosta

Replying to mloskot:

Kosta, I understand it but this solution introduces, implicitly, requirement that all binary data in SQL statements should be encoede in HEX string. Am I right?

This is possibly not true for all SQL-drivers; but every driver uses its own mechanism to create the ExecuteSQL() command string. So each driver can individually use the right method for constructing the SQL INSERT string. The MySQL driver and the SQLite driver both use the method of providing binary data as hex strings described above...

05/11/07 11:49:51 changed by mloskot

Kosta, you're perfectly right.

I've clarified it with Frank and the ExecuteSQL() function is not assumed to work in unified way across DBMS drivers.

So, if a user wants to operate binary data with raw SQL statements, he has to encode/decode it according requirements of given DBMS. The only unified way to set binary data to a feature attribute is through OGRFeature::SetField?().

Sorry for making confusions :-)

05/11/07 12:26:03 changed by mloskot

  • attachment sqlite_blob_simple_test.zip added.

This is simple test of read and write BLOB data to SQLite database. This test uses WKB stream read from multipoint.wkb file, as a sample binary data.

05/11/07 12:42:21 changed by mloskot

  • status changed from assigned to closed.
  • resolution set to fixed.

The patch is applied (r11484).

Kosta, great job, big thanks!

05/11/07 13:11:22 changed by mloskot

I ported this patch to the branches/1.4 stable branch] targeting 1.4.2 milestone (r11486).

The Buildbot still shows green.