From: Oliver M. B. <ol...@go...> - 2003-02-09 19:52:10
|
Hi! On Thu, Feb 06, 2003 at 06:41:15PM +0100, "Oliver M. Bolzer" <ol...@go...> wrote... > On Thu, Feb 06, 2003 at 05:21:00PM +0100, "Oliver M. Bolzer" <ol...@go...> wrote... > > A really quick glance into DBD::Pg shows that the type conversion is > > done according to type_map and the type of a column according to pg_result.type Either nobody is interested or everybody is on vacation, so I added support for PostgreSQL-Arrays into DBD::Pg this weekend. Too much snow outside to do anything else :-) This code handles all array-types that use an ',' as delimitor (all built-in except box), even with dimensions depper than 1. The array-parsing code started as port from the JDBC-driver included in PostgerSQL but is now better than it, because of multi-dimension support. Perl's DBD::Pg does not seem to contain support for Arrays. Using the following table with Arrays: CREATE TABLE test ( strings varchar(10)[], ints integer[][] ); INSERT INTO test VALUES ( '{"fo,o", "bar{baz"}', '{{1,2},{2,3}}'); testdb=> SELECT * FROM test; strings | ints --------------------+--------------- {"fo,o","bar{baz"} | {{1,2},{2,3}} (1 row) While the current implementation of DBD::Pg only results in a String that is excatly "{{1,2},{2,3}}", with my patch, the arrays are properly converted to Ruby's Arrays and the elements converted to the correct type. dbh = DBI.connect( driver_url, dbuser, dbpass ) row = dbh.select_one( 'SELECT * FROM test' ) p row[0] # => ["fo,o", "bar{baz"] p row[1] # => [[1, 2], [2, 3]] Please consided applying the patch. Tested with PostgrSQL 7.2.1 and 7.3.1, based on $Id: Pg.rb,v 1.27 2002/09/26 13:40:32 mneumann Exp $ -- Oliver M. Bolzer ol...@go... GPG (PGP) Fingerprint = 621B 52F6 2AC1 36DB 8761 018F 8786 87AD EF50 D1FF |