Recent

Author Topic: Problem with ZEOS ZQuery  (Read 9681 times)

simonl

  • Newbie
  • Posts: 1
Problem with ZEOS ZQuery
« on: April 29, 2010, 05:56:50 pm »
hello i been trying to exacute a command in zquery but i keep getting index out of bounds message

my code is as follows

Code: [Select]
   ZQuery1.SQL.Text := 'SELECT count(*) FROM groups,rooms WHERE groups.n=rooms.id and groups.n=' + LobbysTable.FieldByName('n').AsString;
   ZQuery1.ExecSQL;
   ZQuery1.Open;

i get the error with

Code: [Select]
ZQuery1.Params[0].AsString
am trying to get counts of all rooms in each of my lobbys! can sumone help me pin point problem cheers

fredycc

  • Sr. Member
  • ****
  • Posts: 265
Re: Problem with ZEOS ZQuery
« Reply #1 on: April 29, 2010, 07:04:41 pm »
hi, I use Zeos too, this is an example, how to use params, and how you can pass any other data from another query and how retrieve Id('SELECT @@IDENTITY AS IdTransaccion'  <- just works for MS sql server).

Qry2.SQL.Add ('insert into PdaPagoHeader (Modulo,TipoCliente,CodUsuario,FechaReunion,MonTotal,CodPrestamo,IdTranPDA,Status) ');
                Qry2.SQL.Add ('values (:Modulo,:TipoCliente,:CodUsuario,:FechaReunion,:MonTotal,:CodPrestamo,:IdTranPDA,:Status) ');
                Qry2.SQL.Add ('SELECT @@IDENTITY AS IdTransaccion ');
                Qry2.ParamByName('Modulo').AsString := 'PAGO';
                Qry2.ParamByName('TipoCliente').AsString := 'G';
                Qry2.ParamByName('CodUsuario').AsString := Qry1.FieldByName('CodGrupo').AsString;
                Qry2.ParamByName('FechaReunion').AsDateTime := Now;
                Qry2.ParamByName('MonTotal').AsCurrency := Qry1.FieldByName('Total').AsCurrency;
                Qry2.ParamByName('CodPrestamo').AsString := Qry1.FieldByName('CodPrestamo').AsString;
                Qry2.ParamByName('IdTranPDA').AsString := FileName;
                Qry2.ParamByName('Status').AsString := 'OK';    

Zoran

  • Hero Member
  • *****
  • Posts: 1574
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: Problem with ZEOS ZQuery
« Reply #2 on: April 29, 2010, 07:32:56 pm »
hello i been trying to exacute a command in zquery but i keep getting index out of bounds message

my code is as follows

Code: [Select]
  ZQuery1.SQL.Text := 'SELECT count(*) FROM groups,rooms WHERE groups.n=rooms.id and groups.n=' + LobbysTable.FieldByName('n').AsString;
   ZQuery1.ExecSQL;
   ZQuery1.Open;

i get the error with

Code: [Select]
ZQuery1.Params[0].AsString
am trying to get counts of all rooms in each of my lobbys! can sumone help me pin point problem cheers

Your ZQuery1 has NO parameters. The parameters are given with colon ( : ) prefix.
If you had written
Code: [Select]
SELECT count(*) FROM groups,rooms WHERE groups.n=rooms.id and groups.n = :n
then ZQuery1 would have had one parameter named n and you would have been able to use for example
Code: [Select]
ZQuery1.ParamByName('n').AsString := LobbysTable.FieldByName('n').AsString;or (which does the same)
Code: [Select]
ZQuery1.Params[0].AsString := LobbysTable.FieldByName('n').AsString;
And this is provided groups.n is string field. If it is of type integer, you should use .AsInteger instead.
« Last Edit: April 29, 2010, 07:36:45 pm by Zoran »

Zoran

  • Hero Member
  • *****
  • Posts: 1574
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: Problem with ZEOS ZQuery
« Reply #3 on: April 29, 2010, 07:42:46 pm »
If you actually want to read field value, then you should just use Fields[0] instead of params[0].

 

TinyPortal © 2005-2018