Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus-es / 2016-11

leer todos los Record con SQLdb

5 messages · 4 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

hfiandor

Amigos listeros:

En el documento SQLdb How to do se explica por qué solamente se leen los primeros 10 registros al ejecutar una consulta y brinda una solución para que lea todos los registros.

Tengo una aplicación donde hago lo siguiente:

  begin
    fdm.SQLQuery1.Active := False;
    fdm.dsSQLQuery1.DataSet:=fdm.tTemp2;
    fdm.SQLite3Connection1.DatabaseName:=camino_BD + '\temp.db';
    fdm.SQLQuery1.SQL.Text := 'SELECT * FROM Temp2 WHERE codNegSerAct =
:SelCodigoNegSerAct ORDER BY codNegSerAct';
    fdm.SQLQuery1.Params.ParamByName('SelCodigoNegSerAct').AsString :=
SelNSA;
    fdm.SQLQuery1.ExecSQL;
    fdm.tTemp2.Last; //para que lea completo
    if fdm.SQLQuery1.Active = False then fdm.SQLQuery1.Active := True
    else begin end;
    fEstadoCuenta_2.frDBDataSet2.DataSet := fdm.SQLQuery1;
fEstadoCuenta_2.frReport2.LoadFromFile(camino_actual+'\plantillas\Extendida_
2.lrf');
    fEstadoCuenta_2.frReport2.ShowReport;
    fdm.SQLQuery1.Close;
    fdm.SQLTransaction1.Active := False;
    fdm.SQLite3Connection1.Connected := False;
No tengo la certeza de haber escrito la instrucción    fdm.tTemp2.Last;
//para que lea completo en el lugar correcto.

Agradecería que alguien me comentara al respecto y cualquier otra sugerencia que deseen.

Saludos

Ing. Héctor F. Fiandor Rosario

------------ próxima parte ------------
Se ha borrado un adjunto en formato HTML...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus-es/attachments/20161104/e4f6188f/attachment.html>

Reply by email

Rafael Bidegain
to hfiandor

Hola Hector.

No puedo hacer pruebas como para darte una respuesta mas precisa. busqué el documento al que haces referencia y encontré un texto pero entiendo que 'el truco' de llamar a .last es solo para poder utilizar la propiedad RecordCount.

en el ejemplo que enviaste no veo que estés usando esa propiedad, ¿tenés dudas sobre el funcionamiento del select?

Creo que si tenés necesidad de ejecutar el método last deberías hacerlo así
 fdm.SQLQuery1.Last();

si yo tuviese que la necesidad de saber la cantidad de registros de un query setearía la propiedad .PacketRecords' en -1 tal como se indica en el documento.

Lamento disponer de un lazarus para hacer pruebas.

saludos cordiales, es un gusto leerte otra vez.

http://wiki.freepascal.org/SqlDBHowto

Why does TSQLQuery.RecordCount always return 10?

To count the records in a dataset, use '.RecordCount'. However, notice that '.RecordCount' shows the number of records that is already loaded from the server. For performance reasons, SqlDB does not read all records when opening TSQLQuery by default, only the first 10. Only when the eleventh record is accessed will the next set of 10 records be loaded, etc. Using '.Last', all records will be loaded.

When you want to know the real number of records on the server you can first call '.Last' and then call '.RecordCount'.

An alternative is available. The number of records returned by the server is set by the '.PacketRecords' property. The default value is 10; if you make it -1 then all records will be current stable FPC, '.RecordCount' does not take filters into account, i.e. it shows the unfiltered total.

If you need the exact number of records, it often is a better idea to directly query the number of records in a query using another SQL query, but you would have to do that in the same transaction, as other transactions may have changed the number of records in the meanwhile.

El 4 de noviembre de 2016, 7:20, hfiandor via Lazarus-es <

lazarus-es en lists.lazarus-ide.org> wrote 77 lines
Amigos listeros: En el documento SQLdb How to do se explica por qué solamente se leen los primeros 10 registros al ejecutar una consulta y brinda una solución para que lea todos los registros. Tengo una aplicación donde hago lo siguiente: begin fdm.SQLQuery1.Active := False; fdm.dsSQLQuery1.DataSet:=fdm.tTemp2; fdm.SQLite3Connection1.DatabaseName:=camino_BD + '\temp.db'; fdm.SQLQuery1.SQL.Text := 'SELECT * FROM Temp2 WHERE codNegSerAct = :SelCodigoNegSerAct ORDER BY codNegSerAct'; fdm.SQLQuery1.Params.ParamByName('SelCodigoNegSerAct').AsString := SelNSA; fdm.SQLQuery1.ExecSQL; fdm.tTemp2.Last; //para que lea completo if fdm.SQLQuery1.Active = False then fdm.SQLQuery1.Active := True else begin end; fEstadoCuenta_2.frDBDataSet2.DataSet := fdm.SQLQuery1; fEstadoCuenta_2.frReport2.LoadFromFile(camino_actual+'\ plantillas\Extendida_2.lrf'); fEstadoCuenta_2.frReport2.ShowReport; fdm.SQLQuery1.Close; fdm.SQLTransaction1.Active := False; fdm.SQLite3Connection1.Connected := False; No tengo la certeza de haber escrito la instrucción fdm.tTemp2.Last; //para que lea completo en el lugar correcto. Agradecería que alguien me comentara al respecto y cualquier otra sugerencia que deseen. Saludos Ing. Héctor F. Fiandor Rosario _______________________________________________ Lazarus-es mailing list Lazarus-es en lists.lazarus-ide.org http://lists.lazarus-ide.org/listinfo/lazarus-es
Rafael Bidegain Ya que los cuerdos no hablan, hablará el loco. (The Fool, Padraic Pearse) # yo quiero educación libre. ¡YA! ------------ próxima parte ------------ Se ha borrado un adjunto en formato HTML... URL: <http://lists.lazarus-ide.org/pipermail/lazarus-es/attachments/20161104/72b81a89/attachment.html>

Reply by email

Maxi
to Rafael Bidegain

como es un motor y uno trae datos "por la red" para no generar un trafico innecesario solo trae algunos registros. Al hacer last si o si debe recorrer la seleccion para obtener todos los registros. Me pasó en mySql

El 4 de noviembre de 2016, 8:37, Rafael Bidegain via Lazarus-es <

lazarus-es en lists.lazarus-ide.org> wrote 144 lines
Hola Hector. No puedo hacer pruebas como para darte una respuesta mas precisa. busqué el documento al que haces referencia y encontré un texto pero entiendo que 'el truco' de llamar a .last es solo para poder utilizar la propiedad RecordCount. en el ejemplo que enviaste no veo que estés usando esa propiedad, ¿tenés dudas sobre el funcionamiento del select? Creo que si tenés necesidad de ejecutar el método last deberías hacerlo así fdm.SQLQuery1.Last(); si yo tuviese que la necesidad de saber la cantidad de registros de un query setearía la propiedad .PacketRecords' en -1 tal como se indica en el documento. Lamento disponer de un lazarus para hacer pruebas. saludos cordiales, es un gusto leerte otra vez. http://wiki.freepascal.org/SqlDBHowto Why does TSQLQuery.RecordCount always return 10? To count the records in a dataset, use '.RecordCount'. However, notice that '.RecordCount' shows the number of records that is already loaded from the server. For performance reasons, SqlDB does not read all records when opening TSQLQuery by default, only the first 10. Only when the eleventh record is accessed will the next set of 10 records be loaded, etc. Using '.Last', all records will be loaded. When you want to know the real number of records on the server you can first call '.Last' and then call '.RecordCount'. An alternative is available. The number of records returned by the server is set by the '.PacketRecords' property. The default value is 10; if you make it -1 then all records will be loaded at once. In current stable FPC, '.RecordCount' does not take filters into account, i.e. it shows the unfiltered total. If you need the exact number of records, it often is a better idea to directly query the number of records in a query using another SQL query, but you would have to do that in the same transaction, as other transactions may have changed the number of records in the meanwhile. El 4 de noviembre de 2016, 7:20, hfiandor via Lazarus-es < lazarus-es en lists.lazarus-ide.org> escribió: > Amigos listeros: > > > > En el documento SQLdb How to do se explica por qué solamente se leen los > primeros 10 registros al ejecutar una consulta y brinda una solución para > que lea todos los registros. > > > > Tengo una aplicación donde hago lo siguiente: > > begin > > > > fdm.SQLQuery1.Active := False; > > fdm.dsSQLQuery1.DataSet:=fdm.tTemp2; > > fdm.SQLite3Connection1.DatabaseName:=camino_BD + '\temp.db'; > > fdm.SQLQuery1.SQL.Text := 'SELECT * FROM Temp2 WHERE codNegSerAct = > :SelCodigoNegSerAct ORDER BY codNegSerAct'; > > fdm.SQLQuery1.Params.ParamByName('SelCodigoNegSerAct').AsString := > SelNSA; > > fdm.SQLQuery1.ExecSQL; > > fdm.tTemp2.Last; //para que lea completo > > > > if fdm.SQLQuery1.Active = False then fdm.SQLQuery1.Active := True > > else begin end; > > fEstadoCuenta_2.frDBDataSet2.DataSet := fdm.SQLQuery1; > > fEstadoCuenta_2.frReport2.LoadFromFile(camino_actual+'\plant > illas\Extendida_2.lrf'); > > fEstadoCuenta_2.frReport2.ShowReport; > > > > fdm.SQLQuery1.Close; > > fdm.SQLTransaction1.Active := False; > > fdm.SQLite3Connection1.Connected := False; > > > > No tengo la certeza de haber escrito la instrucción fdm.tTemp2.Last; > //para que lea completo en el lugar correcto. > > > > Agradecería que alguien me comentara al respecto y cualquier otra > sugerencia que deseen. > > > > Saludos > > Ing. Héctor F. Fiandor Rosario > > > > _______________________________________________ > Lazarus-es mailing list > Lazarus-es en lists.lazarus-ide.org > http://lists.lazarus-ide.org/listinfo/lazarus-es > > -- Rafael Bidegain Ya que los cuerdos no hablan, hablará el loco. (The Fool, Padraic Pearse) # yo quiero educación libre. ¡YA! _______________________________________________ Lazarus-es mailing list Lazarus-es en lists.lazarus-ide.org http://lists.lazarus-ide.org/listinfo/lazarus-es
El que pregunta aprende, y el que contesta aprende a responder. No a la obsolecencia programada: http://www.rtve.es/noticias/20110104/productos-consumo-duran-cada-vez-menos/392498.shtml Linux User #495070 http://domonetic.com/blog ------------ próxima parte ------------ Se ha borrado un adjunto en formato HTML... URL: <http://lists.lazarus-ide.org/pipermail/lazarus-es/attachments/20161104/b6716489/attachment-0001.html>

Reply by email

Jose Antonio Cuello
to hfiandor: Amigos listeros: En el documento SQLdb How to do se explica por qué solamente se leen los

Hola, no termino de entender el problema respecto al código que introduces. Personalmente no realizaría un execute sino un open sobre el dataset. Eso debería traer todos los registros. "Traer" no significa que te lea de "golpe" todo sino que el cursor solicita los datos al servidor y este los tiene preparados. Cuando te vayas moviendo por el dataset el motor de bases de datos irá dando al dataset lo que necesite.

Creo que te bastaría con:

begin
fdm.SQLite3Connection1.DatabaseName:=camino_BD + '\temp.db';
fdm.SQLite3Connection1.Open;
fdm.dsSQLQuery1.DataSet:=fdm.tTemp2; // Esto no sé para que es
fdm.SQLQuery1.Close;
fdm.SQLQuery1.SQL.Text := 'SELECT * FROM Temp2 WHERE codNegSerAct = :SelCodigoNegSerAct ORDER BY codNegSerAct';
fdm.SQLQuery1.Params.ParamByName('SelCodigoNegSerAct').AsString := SelNSA;
fdm.SQLQuery1.Open;
fEstadoCuenta_2.frReport2.LoadFromFile(camino_actual+'\plantillas\Extendida_2.lrf');
fEstadoCuenta_2.frDBDataSet2.DataSet := fdm.SQLQuery1;
fEstadoCuenta_2.frReport2.ShowReport;
fdm.SQLQuery1.Close;
fdm.SQLite3Connection1.Close;

De: "hfiandor via Lazarus-es" <lazarus-es en lists.lazarus-ide.org> Para: lazarus-es en lists.lazarus-ide.org
CC: "hfiandor" <hfiandor en ceniai.inf.cu>
Enviados: Viernes, 4 de Noviembre 2016 11:20:07
Asunto: [Lazarus-es] leer todos los Record con SQLdb

Amigos listeros:

En el documento SQLdb How to do se explica por qué solamente se leen los primeros 10 registros al ejecutar una consulta y brinda una solución para que lea todos los registros.

Tengo una aplicación donde hago lo siguiente:

begin
fdm.SQLQuery1.Active := False;
fdm.dsSQLQuery1.DataSet:=fdm.tTemp2;
fdm.SQLite3Connection1.DatabaseName:=camino_BD + '\temp.db';
fdm.SQLQuery1.SQL.Text := 'SELECT * FROM Temp2 WHERE codNegSerAct = :SelCodigoNegSerAct ORDER BY codNegSerAct';
fdm.SQLQuery1.Params.ParamByName('SelCodigoNegSerAct').AsString := SelNSA;
fdm.SQLQuery1.ExecSQL;
fdm.tTemp2.Last; //para que lea completo
if fdm.SQLQuery1.Active = False then fdm.SQLQuery1.Active := True
else begin end;
fEstadoCuenta_2.frDBDataSet2.DataSet := fdm.SQLQuery1;
fEstadoCuenta_2.frReport2.LoadFromFile(camino_actual+'\plantillas\Extendida_2.lrf');
fEstadoCuenta_2.frReport2.ShowReport;
fdm.SQLQuery1.Close;
fdm.SQLTransaction1.Active := False;
fdm.SQLite3Connection1.Connected := False;
No tengo la certeza de haber escrito la instrucción fdm.tTemp2.Last; //para que lea completo en el lugar correcto.

Agradecería que alguien me comentara al respecto y cualquier otra sugerencia que deseen.

Saludos

Ing. Héctor F. Fiandor Rosario

Reply by email