Code: Select all
function FWAdoSaveRecord( oRS, aRecord, nRecNo )
local n, oField, uVal, uNew
local lUpdated := .f., lSaved := .f.
if ! Empty( nRecNo ) .and. oRs:BookMark != nRecNo
oRs:BookMark = nRecNo
endif
for n = 1 to oRS:Fields:Count
oField = oRs:Fields( n - 1 )
if FW_AdoFieldUpdateable( oRs, oField ) == .f.
LOOP
endif
uVal = oField:Value
uNew = aRecord[ n, 2 ]
if Empty( uVal ) .and. Empty( uNew )
LOOP
endif
#ifdef __XHARBOUR__
if Empty( uNew ) .and. lAnd( oField:Attributes, 0x20 ) // nullable field
oField:Value = VTWrapper( 1 ) // assigning NULL
LOOP
endif
#endif
// assume that uNew is not NIL .and. is correct data type
if ValType( uNew ) == 'C'
if oField:Type == adChar // Fixed width
uNew = PadR( uNew, oField:DefinedSize )
else
uNew = Left( Trim( uNew ), oField:DefinedSize )
endif
endif
if ! ( ValType( uVal ) == ValType( uNew ) .and. uVal == uNew )
if AScan( { adBinary, adVarBinary, adLongVarBinary }, oField:Type ) != 0
uNew = HB_StrToHex( uNew )
endif
#ifndef __XHARBOUR__
// Harbour has problem in assigning Empty Dates
//
if ValType( uVal ) $ 'DT' .and. Empty( uNew ) .and. ;
! ( FW_RDBMSName( oRs:ActiveConnection ) == "MSACCESS" )
uNew = 0
endif
#endif
/*
if ValType( uNew ) == "L"
uNew = If( uNew, 1, 0 )
endif
*/
TRY
oField:Value = uNew
lUpdated = .T.
catch oError
? oField:Name, uNew
END
endif
next
if lUpdated
TRY
oRS:Update()
lSaved := .t.
catch oError
// here
MsgInfo( oError:Description )
oRS:CancelUpdate()
END
endif
return lSaved
it has 183 columns
source code follows the opening:
Code: Select all
Function SqlQuery( cSqlSintax )
local uRet := {} // Retorno com Registros
local nAt // Objetos de controle para o ODBC e o Registro
Local aSqlDados:={}, lInstancia := .f. , lExecute:=.f. , oResultSetAnterior := nil
hINI := Time()
Try
aSqlDados := (HB_ATokens(strtran(strtran(oSqlConexao:OleValue,"]"),"["),";"))
if len(aSqlDados) > 0
if !(aSqlDados[3] == "Data Source="+alltrim(cDiretorioDeDados))
lInstancia:=.t.
endif
endif
catch
public oSqlConexao
lInstancia:=.t.
end
if lInstancia
oSqlConexao := FW_OpenAdoConnection( [Provider=Microsoft.Jet.OLEDB.4.0;Data Source=]+cDiretorioDeDados+[ ;Extended Properties=dBASE IV;User ID=Admin;Password=] ,.t.)
endif
cSql := Upper( alltrim(cSqlSintax) )
lExecute := !( LEFT( cSql, 7 ) == "SELECT " )
if oSqlConexao != nil
if lExecute
TRY
uRet := oSqlConexao:Execute( cSql )
CATCH
END
else
oRecordSetConsulta := FW_OpenRecordSet( oSqlConexao, cSql )
if oResultSetAnterior == nil
oResultSetAnterior:= oRecordSetConsulta
endif
if oRecordSetConsulta != nil
if oRecordSetConsulta:RecordCount() > 0
oBrowserDeDados:SetAdo( oRecordSetConsulta, .t., .t.) // ADO object
else
oRecordSetConsulta:=oResultSetAnterior
oBrowserDeDados:SetAdo( oRecordSetConsulta, .t., .t.) // ADO object
oResultSetAnterior := nil
endif
DEFINE MSGITEM oMsgRecNo OF oMsgBar ;
PROMPT "Reg.Atual: " + ;
AllTrim( Str( If( oRecordSetConsulta:AbsolutePosition == -3, oRecordSetConsulta:RecordCount() + 1,;
oRecordSetConsulta:AbsolutePosition ) ) ) + " / " + ;
AllTrim( Str( oRecordSetConsulta:RecordCount() ) ) ;
SIZE 150
DEFINE MSGITEM oMsgTagName OF oMsgBar ;
PROMPT FWString( "Ordered by" ) + ": " + If( Empty( oRecordSetConsulta:Sort ),;
FWString( "natural order" ), oRecordSetConsulta:Sort ) ;
SIZE 150
oMsgBar:settext("Tempo da Ultima Consulta: "+ ElapTime(hini,time()) )
oMsgBar:Refresh()
oBrowserDeDados:CreateFromCode()
oJanelaPrincipal:oClient := oBrowserDeDados
oBrowserDeDados:Refresh()
oJanelaPrincipal:Resize()
oJanelaPrincipal:Refresh()
Sysrefresh()
endif
endif
endif
return uRet