Pasar query a un arreglo

Pasar query a un arreglo

Postby Compuin » Sat Jun 29, 2019 6:25 pm

Hola foro,

Como puedo leer una tabla mysql y pasar su contenido a un arreglo?

Hay algun ejemplo en Fivewin?

Gracias
FWH 20.12
Hbmk2 32/64 Bits (Build 19.29.30133)
Microsoft Visual C 32 Bits
MySql 8.0.24 32/64 Bits
VS Code
Compuin
 
Posts: 1213
Joined: Tue Dec 28, 2010 1:29 pm
Location: Quebec, Canada

Re: Pasar query a un arreglo

Postby joseluisysturiz » Sun Jun 30, 2019 12:11 am

Usa oQry:fillarray...es lo mejor y mas rapido, saludos... :shock:

Code: Select all  Expand view

// FILLARRAY
oQry:FillArray( {| aRow | AAdd( oBrw:aArrayData, { aRow[2], aRow[4] } ) } ) // CON POSICION CAMPO

oBrw:aArrayData := oQry:FillArray( , { "vende_cedula", "vende_apellidos" } ) // CON CAMPOS. PARA LOS xBRW O UN ARRAY

oQry:FillArray( {| aRow | ( AAdd( Array1, cValToChar( aRow[1] ) ) ,; // PARA LOS COMBOBOX CON QRY
                             AAdd( Array2, aRow[2]) ) }, )
 
Dios no está muerto...

Gracias a mi Dios ante todo!
User avatar
joseluisysturiz
 
Posts: 2064
Joined: Fri Jan 06, 2006 9:28 pm
Location: Guatire - Caracas - Venezuela

Re: Pasar query a un arreglo

Postby Compuin » Sun Jun 30, 2019 1:51 am

joseluisysturiz wrote:Usa oQry:fillarray...es lo mejor y mas rapido, saludos... :shock:

Code: Select all  Expand view

// FILLARRAY
oQry:FillArray( {| aRow | AAdd( oBrw:aArrayData, { aRow[2], aRow[4] } ) } ) // CON POSICION CAMPO

oBrw:aArrayData := oQry:FillArray( , { "vende_cedula", "vende_apellidos" } ) // CON CAMPOS. PARA LOS xBRW O UN ARRAY

oQry:FillArray( {| aRow | ( AAdd( Array1, cValToChar( aRow[1] ) ) ,; // PARA LOS COMBOBOX CON QRY
                             AAdd( Array2, aRow[2]) ) }, )
 


Muchas gracias paisano
FWH 20.12
Hbmk2 32/64 Bits (Build 19.29.30133)
Microsoft Visual C 32 Bits
MySql 8.0.24 32/64 Bits
VS Code
Compuin
 
Posts: 1213
Joined: Tue Dec 28, 2010 1:29 pm
Location: Quebec, Canada

Re: Pasar query a un arreglo

Postby joseluisysturiz » Sun Jun 30, 2019 2:19 am

Olvide comentarte que esto es usando TDolphin, saludos... :shock:
Dios no está muerto...

Gracias a mi Dios ante todo!
User avatar
joseluisysturiz
 
Posts: 2064
Joined: Fri Jan 06, 2006 9:28 pm
Location: Guatire - Caracas - Venezuela

Re: Pasar query a un arreglo

Postby Compuin » Sun Jun 30, 2019 2:20 am

joseluisysturiz wrote:Olvide comentarte que esto es usando TDolphin, saludos... :shock:


Si, imagino que es TDolphin

Yo uso Eagle1, deberia funcionar ya que solo es el resultado del query
FWH 20.12
Hbmk2 32/64 Bits (Build 19.29.30133)
Microsoft Visual C 32 Bits
MySql 8.0.24 32/64 Bits
VS Code
Compuin
 
Posts: 1213
Joined: Tue Dec 28, 2010 1:29 pm
Location: Quebec, Canada

Re: Pasar query a un arreglo

Postby joseluisysturiz » Sun Jun 30, 2019 3:03 am

fillarray si no me equivoco, es un methodo de TDolphin, en FWMaria o algo asi nativo de FW se usa algo diferente, aun no he migrado a el nativo de FW, pero para alla voy Dios mediante, tambien puedes hacer un recorrido del qry y usar aadd(array, valores/{valores}), es lo mas clasico, saludos... :shock:
Dios no está muerto...

Gracias a mi Dios ante todo!
User avatar
joseluisysturiz
 
Posts: 2064
Joined: Fri Jan 06, 2006 9:28 pm
Location: Guatire - Caracas - Venezuela

Re: Pasar query a un arreglo

Postby nageswaragunupudi » Sun Jun 30, 2019 2:17 pm

Native FWH:
Simple and the fastest:

aData := oCn:Execute( cQry )

Example:
Code: Select all  Expand view

aStates := oCn:Execute( "select code,name from states" )
 
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10248
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Pasar query a un arreglo

Postby Compuin » Sun Jun 30, 2019 2:19 pm

nageswaragunupudi wrote:Native FWH:
Simple and the fastest:

aData := oCn:Execute( cQry )

Example:
Code: Select all  Expand view

aStates := oCn:Execute( "select code,name from states" )
 


Thanks Mr Rao
FWH 20.12
Hbmk2 32/64 Bits (Build 19.29.30133)
Microsoft Visual C 32 Bits
MySql 8.0.24 32/64 Bits
VS Code
Compuin
 
Posts: 1213
Joined: Tue Dec 28, 2010 1:29 pm
Location: Quebec, Canada

Re: Pasar query a un arreglo

Postby Compuin » Sun Jun 30, 2019 2:20 pm

joseluisysturiz wrote:fillarray si no me equivoco, es un methodo de TDolphin, en FWMaria o algo asi nativo de FW se usa algo diferente, aun no he migrado a el nativo de FW, pero para alla voy Dios mediante, tambien puedes hacer un recorrido del qry y usar aadd(array, valores/{valores}), es lo mas clasico, saludos... :shock:


Gracias Jose Luis por la aclaratoria
FWH 20.12
Hbmk2 32/64 Bits (Build 19.29.30133)
Microsoft Visual C 32 Bits
MySql 8.0.24 32/64 Bits
VS Code
Compuin
 
Posts: 1213
Joined: Tue Dec 28, 2010 1:29 pm
Location: Quebec, Canada

Re: Pasar query a un arreglo

Postby joseluisysturiz » Sun Jun 30, 2019 4:47 pm

nageswaragunupudi wrote:Native FWH:
Simple and the fastest:

aData := oCn:Execute( cQry )

Example:
Code: Select all  Expand view

aStates := oCn:Execute( "select code,name from states" )
 


Buen dia Mr. NAO, si ya tengo un queri hecho con fillarray selecciono solo los campos que deseo pasar al array sin necesidad de hacer la consulta al momento, como lo haria con la nativa de FW.? gracias... :shock:
Dios no está muerto...

Gracias a mi Dios ante todo!
User avatar
joseluisysturiz
 
Posts: 2064
Joined: Fri Jan 06, 2006 9:28 pm
Location: Guatire - Caracas - Venezuela

Re: Pasar query a un arreglo

Postby nageswaragunupudi » Sun Jun 30, 2019 5:00 pm

If you already made a query (we call it RowSet), then you can use method GetRows(), which is similar to FillArray() of Dolphin.

aData := oRs:GetRows( [nRows], [nFromRow], [aFieldNames] )

Example:
Code: Select all  Expand view

oRs := oCn:RowSet( "customer" )
aDataFull := oRs:GetRows()
aDataPart := oRs:GetRows( 20, 101, { "first", "city", "salary" } )
 


But, if you did not read query (rowset) already, we can save lot of time by directly reading the data into an array, instead of first reading into a query and then copying data from query into an array.
This is simple and fast
Code: Select all  Expand view

aData := oCn:Execute( "select first, city, salary from customer where id between 101 and 120" )
 
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10248
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Pasar query a un arreglo

Postby joseluisysturiz » Sun Jun 30, 2019 7:27 pm

nageswaragunupudi wrote:If you already made a query (we call it RowSet), then you can use method GetRows(), which is similar to FillArray() of Dolphin.

aData := oRs:GetRows( [nRows], [nFromRow], [aFieldNames] )

Example:
Code: Select all  Expand view

oRs := oCn:RowSet( "customer" )
aDataFull := oRs:GetRows()
aDataPart := oRs:GetRows( 20, 101, { "first", "city", "salary" } )
 


But, if you did not read query (rowset) already, we can save lot of time by directly reading the data into an array, instead of first reading into a query and then copying data from query into an array.
This is simple and fast
Code: Select all  Expand view

aData := oCn:Execute( "select first, city, salary from customer where id between 101 and 120" )
 



Excelente, veo que se porta igual que fillarray, ahora otra duda...se puede agrgar un valor que no sea de la consulta, como por ejemplo un valor booleano o el valor de una variable.?

ejemplo:

Code: Select all  Expand view

aDataPart := oRs:GetRows( 20, 101, { "first", "city", "salary", .f. } )
// Esto seriviria para usar un xbrowse y usar setcheck()

aDataPart := oRs:GetRows( 20, 101, { "first", "city", "salary", nom_var } )

// nom_var seria una VAR externa al query, con fillarray no se como hacerlo, gracias... :shock:
 
Dios no está muerto...

Gracias a mi Dios ante todo!
User avatar
joseluisysturiz
 
Posts: 2064
Joined: Fri Jan 06, 2006 9:28 pm
Location: Guatire - Caracas - Venezuela

Re: Pasar query a un arreglo

Postby joseluisysturiz » Sun Jun 30, 2019 7:30 pm

Quiero empezar a migrar de TDolphin a FWMaria la nativa de FW, por donde inicio.? gracias... :shock:
Dios no está muerto...

Gracias a mi Dios ante todo!
User avatar
joseluisysturiz
 
Posts: 2064
Joined: Fri Jan 06, 2006 9:28 pm
Location: Guatire - Caracas - Venezuela

Re: Pasar query a un arreglo

Postby nageswaragunupudi » Mon Jul 01, 2019 2:03 am

Excelente, veo que se porta igual que fillarray, ahora otra duda...se puede agrgar un valor que no sea de la consulta, como por ejemplo un valor booleano o el valor de una variable.?


Every element of the array should be a field name or field number or a character expression using or not using field names.

Example:
Code: Select all  Expand view

   PRIVATE n

   oRs   := oCn:customer   // where customer is the table name
   n     := 100
   aData := oRs:GetRows( 5, 11, ;
      { "first-', '+last", "salary/100", "FW_MTHSLAPSED(HireDate,Date())", "n := n + 1" } )
 


Image
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10248
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Pasar query a un arreglo

Postby joseluisysturiz » Mon Jul 01, 2019 2:15 am

Super excelente Mr NAO...Quiero empezar a migrar de TDolphin a FWMaria la nativa de FW, por donde inicio.? gracias... :shock:
Dios no está muerto...

Gracias a mi Dios ante todo!
User avatar
joseluisysturiz
 
Posts: 2064
Joined: Fri Jan 06, 2006 9:28 pm
Location: Guatire - Caracas - Venezuela

Next

Return to FiveWin para Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 73 guests