[development] DB support as contribute: is it a good idea?

Edison Wong hswong3i at edin.no-ip.com
Mon Feb 18 01:54:03 UTC 2008

Hash: SHA1
Hmm... From my point of view, it is just similar as 
http://netevil.org/uuid/4365876a-cee9-3009-7726-365876a51802 (although 
it is target for pdo_oci, it share the same idea as pdo_pgsql):
$db = new PDO("oci:", "scott", "tiger");
$db->beginTransaction(); // Essential!
$stmt = $db->prepare(
~  "INSERT INTO blobtest (id, contenttype, blob) ".
~  "VALUES (:id, :type, EMPTY_BLOB()) ".
~  "RETURNING blob INTO :blob");
$stmt->bindParam(':id', $id);
$stmt->bindParam(':type', $type);
$stmt->bindParam(':blob', $blob, PDO::PARAM_LOB);
$type = 'image/gif';
$id = 1; // generate your own unique id here
$blob = fopen('/path/to/a/graphic.gif', 'rb');

http://php.net/pdo#pdo.lobs also come with some example (BTW, this level 
of code snippet is TOTALLY NOT ENOUGH for a Drupal-style db_query() 
$db = new PDO('odbc:SAMPLE', 'db2inst1', 'ibmdb2');
$stmt = $db->prepare("insert into images (id, contenttype, imagedata) 
values (?, ?, ?)");
$id = get_new_id(); // some function to allocate a new ID

// assume that we are running as part of a file upload form
// You can find more information in the PHP documentation

$fp = fopen($_FILES['file']['tmp_name'], 'rb');

$stmt->bindParam(1, $id);
$stmt->bindParam(2, $_FILES['file']['type']);
$stmt->bindParam(3, $fp, PDO::PARAM_LOB);


On the other hand, I get a functional implementation of pdo_pgsql *done* 
with correct PDO + PostgreSQL BLOB handling, based on our existing D6 DB 
API with minimal amount of logic change:

Like this one? Don't forget that they are parallel developed with 
pdo_mysql, pdo_oci, pdo_sqlite, and pdo_ibm, where all of the other are 
both function correctly. I am not trying to trigger a war of 
implementation; BTW, a tiny amount brain-storming-level code snippet 
(which similar implementation is all around the world...) is not enough 
for supporting a positive technical-based discussion ;-(

Karoly Negyesi wrote:
|> delegation (including asking Karoly to write pg drivers <g>)... but
| $db = new PDO('pgsql:dbname=drupal', 'drupal', 'drupal');
| $binarydata = "abcdefg\x00a\x00\x01\x02";
| $db->exec('CREATE TABLE test (data bytea, comment varchar(64), len 
| $db->beginTransaction();
| $stmt = $db->prepare("INSERT INTO test (data, comment, len) VALUES 
(:data, :comment, :len)");
| $stmt->bindParam(':len', $len);
| $stmt->bindParam(':data', $blob, PDO::PARAM_LOB);
| $blob = fopen('php://memory', 'a');
| $len = fwrite($blob, $binarydata);
| rewind($blob);
| $comment = 'lob';
| $stmt->bindParam(':comment', $comment);
| $stmt->execute();
| $db->commit();
| Like that? I *did* write the skeleton of LOB handling for postgresql, 
mind ya.

- --
Edison Wong
hswong3i at gmail.com
Version: GnuPG v1.4.7 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.drupal.org/pipermail/development/attachments/20080218/d7747ff6/attachment-0004.htm 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.drupal.org/pipermail/development/attachments/20080218/d7747ff6/attachment-0005.htm 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.drupal.org/pipermail/development/attachments/20080218/d7747ff6/attachment-0006.htm 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.drupal.org/pipermail/development/attachments/20080218/d7747ff6/attachment-0007.htm 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: hswong3i.vcf
Type: text/x-vcard
Size: 187 bytes
Desc: not available
Url : http://lists.drupal.org/pipermail/development/attachments/20080218/d7747ff6/attachment-0001.vcf 

More information about the development mailing list