#1 Re: mORMot 1 » Problem with PostgreSQL 'money' fields » 2016-12-14 23:25:27

OK, I've now tried accessing the same table with money fields using ZEOSLib and I'm still seeing mostly incorrect results.
If I display money fields using IZResultSet.GetString(I) the values are displayed correctly (though in an annoying format that includes a '$').
But if I try to get the raw (un-formatted) currency values using IZResultSet.GetCurrency(I) then results are completely wrong (even though the column type is stCurrency).
It seems that I should avoid using 'money' fields in PostgreSQL and instead use numeric.

#2 Re: mORMot 1 » Problem with PostgreSQL 'money' fields » 2016-12-14 09:30:32

Hi Arnaud.
No. I didn't think to do that. I will investigate now.
Thanks again for your fantastic software libraries.
Angus

#3 mORMot 1 » Problem with PostgreSQL 'money' fields » 2016-12-13 21:07:14

angusj
Replies: 3

Hi.

I have PostgreSQL 9.6 installed on Windows 10 Prof.
I have installed the latest available PostgreSQL ODBC driver (psqlodbc_09_05_0400.zip) from here:
https://www.postgresql.org/ftp/odbc/versions/msi/

With Synopse mORMot, I've created a database with a table containing a 'money' field and populated the table with data.
This table with money values appears exactly as expected in the PostgreSQL tool pgAdmin III.
However, when I try to view this table with Synopse mORMot, all the money values are ZERO ...

var
  i,j: integer;
  fields: TSQLDBColumnDefineDynArray;
  rows: ISQLDBRows;
begin
  props.GetFields(table_name, fields); //this returns money fields correctly as columntype = ftCurrency 
  rows := props.Execute('SELECT * FROM ' + table_name  +';', []);
  i := 0;
  //nb: pseudocode with result[][]
  while rows.Step do
  begin 
    for j := 0 to high(fields) do
      result[i][j] := rows.ColumnString(j); //this is always wrong for 'money' fields
    inc(i);
  end;
end;

I think I've narrowed the problem to TODBCStatement.BindColumns which calls DescribeColW() to fill a DataType and I believe this returned value is incorrect for 'money' fields. Is this an PostgreSQL ODBC driver issue?

ps: if I change the money field to numeric then data is displayed correctly.
pps: I've also tried older ODBC drivers but this problem remains.
ppps: TSQLDBConnectionProperties.GetFields() does return the expected ColumnType (ftCurrency) on 'money' fields.

#4 Re: mORMot 1 » Error Database table is locked (SQLite newbie) » 2016-12-04 13:01:00

OK, I found the solution ... I needed to complete stepping the row before nil-ing it.

  rows := props.Execute('SELECT sql FROM sqlite_master WHERE type="table" AND name=?', [tableName]);
  if not rows.Step then exit;
  defs := rows.ColumnString(0);
  while rows.Step do; //this is important
  rows := nil;

#5 mORMot 1 » Error Database table is locked (SQLite newbie) » 2016-12-02 18:55:32

angusj
Replies: 1

Firstly, apologies for what is probably a very basic question but I'm a complete novice with SQL and to SQLite and to this fantastic Synopse library.
Also, if there's a better forum for this kind of question then please direct me there.

Anyhow, I'm writing a function that drops a column from an SQLite table but I'm encountering the following error:
Error SQLITE_LOCKED (6) - database table is locked

This seems to be the critical code ...

  rows := props.Execute('SELECT sql FROM sqlite_master WHERE type="table" AND name=?', [tableName]);
  if not rows.Step then exit;
  defs := rows.ColumnString(0);
  rows := nil;
  //this is a very crude workaround that avoids the table is locked error ...
  //props.MainConnection.Disconnect;
  //props.MainConnection.Connect;    
  
  //other code that has no bearing on my problem

  //error raised at this line ...
  props.ExecuteNoResult(RawUTF8(format('DROP TABLE %s;', [tableName])), []);

It seems to me that somehow I need to finalize or reset the SELECT statement, but I can't see a good way to do that (apart from the crude workaround above).
Evidently rows := nil; isn't sufficient.
I'd appreciate any help ...

Board footer

Powered by FluxBB