Page 1 of 1

[bug_fixed] postgreSQL array support

Posted: 21.01.2007, 12:10
by Malvo
i missed array support for postgreSQL, so i digged into sources and added some lines.
it's tested with pglib v8 against a postgres v8. i don't know, if it fits to other versions!

the array field is handled as a memo field. the formatting of array values is

{v1,v2,v3}

lines to be added:

in file "\src\dbc\ZDbcPostgreSqlUtils.pas":
function "PostgreSQLToSQLType" (around line 284)

Code: Select all

----- orig -----
  else if (TypeName = 'int2vector') or (TypeName = 'oidvector')
    or (TypeName = '_aclitem') then
    Result := stAsciiStream
----- new -----
  // CHANGED 2007-01 MS
  else if (TypeName[1] = '_') then // ARRAY TYPES
    Result := stAsciiStream
----- orig -----
  else
    Result := stUnknown;
end;
and
in file "\src\dbc\ZDbcPostgreSqlUtils.pas":
function "PostgreSQLToSQLType" (around line 328)

Code: Select all

----- orig -----
    1042: Result := stString; { bpchar }
    22,30: Result := stAsciiStream; { int2vector/oidvector. no '_aclitem' }
----- new -----
    // CHANGED 2007-01 MS
    651, 1000..1028: Result := stAsciiStream;
----- orig -----
    else
      Result := stUnknown;
  end;
end;
line numbers are from latest snapshot download (REV 208), but source is nearly the some in official 6.6.
if you use the official 6.6, you need to add one more line

in file "\src\plain\ZPlainPostgreSqlDriver.pas":
function "TZPostgreSQL8PlainDriver.DecodeBYTEA" (around line 995)

Code: Select all

----- orig -----
  decoded:=ZPlainPostgreSql8.PQunescapeBytea(pansichar(value),@len);
  SetLength(result,len);
  dest:=pchar(result);
----- new -----
    // CHANGED 2007-01 MS
  if len > 0 then
----- orig -----
    Move(decoded^,result[1],len);
  ZPlainPostgreSql8.PQFreemem(decoded);
end;
the last fix is already included in the svn.

Enjoy it!

Cheers,
Marco

Posted: 24.01.2007, 15:52
by mdaems
Hi Marco,

I can't check this as I'm not a postgresql user. It seems quite harmless for people who are not using array types, so I commited your patch.
(SVN testing Rev 209)

Please check. Have you ever run the zeoslib test suite? If you can, please do to see you didn't break up something. (Test trunk first and see if there are more failures in testing)

Mark