Query not populated

Discussion of open issues, suggestions and bugs regarding PgDAC (PostgreSQL Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
piopio1
Posts: 32
Joined: Thu 10 Jan 2013 23:13

Query not populated

Post by piopio1 » Mon 05 Aug 2013 22:36

Hello,

I have a problem in running a query. The following is the code:

a:='Select Array_To_String(Array(( Select Query1.customer_code From (Select tbl_invoices.customer_code, Sum(tbl_invoices.balance_amount * tbl_currencies.exchange_rate) As AROverdue From tbl_invoices Inner Join tbl_currencies On tbl_invoices.currency = tbl_currencies.id Where tbl_invoices.update_date = Current_Date And tbl_invoices.due_date <= Current_Date Group By tbl_invoices.customer_code)Query1 Left Join tbl_customer_master_data On tbl_customer_master_data.customer_code = Query1.customer_code , (Select 100000 as fixedvalue)Query2 Where Query1.AROverdue>Query2.fixedvalue And (tbl_customer_master_data.collection_category = 787 And tbl_customer_master_data.collection_step = 1) Group By Query1.customer_code , tbl_customer_master_data.collection_category,tbl_customer_master_data.collection_step )),''~'') AS customerids'
dummy2:=TPgQuery.Create(nil);
dummy2.Connection:=DM.PgConnection1;
dummy2.Close;
dummy2.SQL.Clear;
dummy2.SQL.Text:=a;
dummy2.Open;
b:=dummy2.FieldByName('customerids').AsString;

after the "Open" instruction the query shows dummy2.recordcount=1 but there is no data in the field "customerids" nor in the variable "b".
If I run the same query in PGAdmin III I have the query correctly populated with the relevant data.

Am I doing anything incorrectly ?


Many thanks
Pio Pio

DemetrionQ
Devart Team
Posts: 271
Joined: Wed 23 Jan 2013 11:21

Re: Query not populated

Post by DemetrionQ » Tue 06 Aug 2013 16:08

Hello.

We couldn't determine the problem when using SQL queries like

Code: Select all

Select Array_To_String(Array[ ... ], '~');
Please provide the following information:
  - the server version;
  - the exact version of PgDAC, you can learn it from the About sheet of TPgConnection Editor;
  - the script for creating the tables.
  - the script for filling in the tables with the test data.

piopio1
Posts: 32
Joined: Thu 10 Jan 2013 23:13

Re: Query not populated

Post by piopio1 » Tue 06 Aug 2013 20:39

DemetrionQ wrote:Hello.

We couldn't determine the problem when using SQL queries like

Code: Select all

Select Array_To_String(Array[ ... ], '~');
Please provide the following information:
  - the server version;
  - the exact version of PgDAC, you can learn it from the About sheet of TPgConnection Editor;
  - the script for creating the tables.
  - the script for filling in the tables with the test data.

Hello DemetrionQ,
I have just sent an email containing all the information you have requested.

Many thanks
Pio Pio

DemetrionQ
Devart Team
Posts: 271
Joined: Wed 23 Jan 2013 11:21

Re: Query not populated

Post by DemetrionQ » Thu 08 Aug 2013 10:07

Hello.

I have received your letter and performed a test. I couldn't reproduce the issue.
I used the following code:

Code: Select all

var
  a: string;
  dummy2: TPgQuery;
begin
  a :=  'Select Array_To_String(Array(( Select Query1.customer_code From (Select tbl_invoices.customer_code, Sum(tbl_invoices.balance_amount * tbl_currencies.exchange_rate) As AROverdue From tbl_invoices Inner Join tbl_currencies '
        +
        'On tbl_invoices.currency = tbl_currencies.id Where tbl_invoices.update_date = Current_Date And tbl_invoices.due_date <= Current_Date Group By tbl_invoices.customer_code)Query1 Left Join tbl_customer_master_data '
        +
        'On tbl_customer_master_data.customer_code = Query1.customer_code , (Select 100000 as fixedvalue)Query2 Where Query1.AROverdue>Query2.fixedvalue And (tbl_customer_master_data.collection_category = 787 And '
        +
        'tbl_customer_master_data.collection_step = 1) Group By Query1.customer_code , tbl_customer_master_data.collection_category,tbl_customer_master_data.collection_step )),''~'') AS customerids';

  dummy2 := TPgQuery.Create(nil);
  try
    dummy2.Connection := DM.PgConnection1;
    dummy2.SQL.Text := a;
    dummy2.Open;
    ShowMessage(dummy2.FieldByName('customerids').AsString);
  finally
    dummy2.Free;
  end;
end;
and got the following as an execution result:

Code: Select all

694~1184~189~902~525
Please check the code. If it shows an empty string, make sure that PgAdmin and your application connect to the same database.

piopio1
Posts: 32
Joined: Thu 10 Jan 2013 23:13

Re: Query not populated

Post by piopio1 » Fri 09 Aug 2013 21:31

I found out the issue: right before running the query I ran another update query but not committed the transaction.

Thank you for your help, your test help me to find the solution
Pio Pio

DemetrionQ
Devart Team
Posts: 271
Joined: Wed 23 Jan 2013 11:21

Re: Query not populated

Post by DemetrionQ » Mon 12 Aug 2013 08:12

Glad to see that you solved the issue. If any other questions come up, please contact us.

Post Reply