En el siguiente fragmento de código, estoy recuperando datos de una tabla en mi base de datos MariaDB. Dado que los datos pueden ser bastante grandes, los estoy recuperando 50 filas a la vez.
¿Cómo puedo almacenar estas filas en un TDataSet de forma más directa, sin tener que pasar los datos a un array y luego insertarlos todos a la vez en un TMenDataSet?
Y otra pregunta: Cuando ocurre un error en la instrucción Select, ¿por qué no se ejecuta la instrucción Try...Catch?
Gracias de antemano por su atención.
Código: Seleccionar todo
METHOD GeraArqAuxiliar( ) CLASS TfrmRelNotasFiscaisRecebidas
Local bResp := .T.,;
Cont := 0,;
intQtdeRegistros := 0,;
vetData := {},;
aryData := {},;
aryFieldNames := {}
Try
// Verifica a quantidade de registro será retornada
intQtdeRegistros := AppData:oMariaDB:QueryValue( 'Select Count(*) from dfe ' +;
' where CAlmoDfe = ' + Alltrim(Str(::aCodAlmoxarifado[ ::oCbxAlmoxarifado:nIndex ])) + ' and ' + ;
' dhEmiDfe between "' + HB_TSToStr(::oEdtDtInicial:Value) + '" and "' + HB_TSToStr(::oEdtDtFinal:Value + HB_DToT(CToD('') , 86399)) + '" ', 0)
::oPgBrExportacao:nMax := intQtdeRegistros
aryData := {}
For Cont := 0 To intQtdeRegistros Step 50
::oDataSetReport := AppData:oMariaDB:QueryReport( 'Select CAlmoDfe, CodForDfe, CPFCNPJDfe, NEmitenteDfe, dhEmiDFe, NumNontaDfe, ' +;
' SerieDfe, ValorNFDfe, SituacaoNFDfe, ChaveDfe ' +;
' from dfe ' +;
' where CAlmoDfe = ' + Alltrim(Str(::aCodAlmoxarifado[ ::oCbxAlmoxarifado:nIndex ])) + ' and ' + ;
' dhEmiDfe between "' + HB_TSToStr(::oEdtDtInicial:Value) + '" and "' + HB_TSToStr(::oEdtDtFinal:Value + HB_DToT(CToD('') , 86399)) + '" ' +;
' order by dhEmiDFe limit 50 offset ' + AllTrim(Str(Cont)))
::oDataSetReport:Open()
For Each vetData in ::oDataSetReport:GetRows()
AAdd(aryData, vetData)
Next
aryFieldNames := ::oDataSetReport:FieldNames()
::oDataSetReport:Close()
Next Cont
::oMemDataSet:Open(aryData, aryFieldNames)
Catch
bResp := .F.
End // Begin Sequence
RETURN( bResp )