"PRO_CAN BIT NOT NULL COMMENT 'Canceled ?'," +;
aCol[ 6] := oBrw:AddCol()
aCol[ 6]:AddResource("SI")
aCol[ 6]:AddResource("NO")
aCol[ 6]:cHeader := "Can"
aCol[ 6]:bBmpData := { || IF(oRsPro:BOF() .AND. oRsPro:EOF(),2,IIF(oRsPro:Fields("PRO_CAN"):Value,1,2)) }
/*
* test connection with ADODB
*/
#include "FiveWin.Ch"
#include "XBrowse.Ch"
#include "ado.Ch"
//----------------------------------------------------------------------------//
function main()
execConnection()
return( 0 )
FUNCTION execConnection
LOCAL oCon, oRs, oError
oCon := MySQLConnect()
MakeTabla(oCon)
oRs := MySQLRecordSet( oCon )
IF oRs:recordCount() > 0
oRs:moveFirst()
ENDIF
TxBrowseShow( oRs )
oRs:close()
oCon:close()
RETURN( .T. )
/*
* --------------------------------------------------------------------------*
* --------------------------------------------------------------------------*
*/
FUNCTION MySQLConnect
LOCAL oError, oCon, cConnectionString
TRY
oCon := TOleAuto():new( "ADODB.Connection" )
CATCH oError
msgStop( "No se pudo crear la conexion" )
RETURN( .F. )
END
cConnectionString := "Driver={MySQL ODBC 5.1 Driver}" + ;
";Server=mcfox.dyndns.org" + ;
";DefaultDatabase=prueba01" + ;
";Database=prueba01" + ;
";Port=3306" + ;
";User=prueba" + ;
";Password=12345" + ;
";Option=3;"
oCon:connectionString := cConnectionString
TRY
oCon:open()
? "Connection ok!"
CATCH oError
msgInfo( "No se pudo crear la conexion" )
showError( oError )
RETURN( .F. )
END
RETURN( oCon )
/*
* --------------------------------------------------------------------------*
* --------------------------------------------------------------------------*
*/
FUNCTION MySQLRecordSet( oCon )
LOCAL oRs, oError, cQuerySql
TRY
oRs := TOleAuto():new( "ADODB.RecordSet" )
CATCH oError
msgStop( "No hay RS" )
showError( oError )
oRs := NIL
RETURN( .F. )
END
&& -- Realizando uma query no cadastro de empresas
cQuerySql := "SELECT * FROM test"
oRs:cursorLocation := adUseClient // 3
oRs:lockType := adLockOptimistic // 3
oRs:cursorType := adOpenDynamic // 2
oRs:source := cQuerySql
oRs:activeConnection( oCon )
TRY
oRs:open()
? oRs:source,,, "oRs:recordCount()", oRs:recordCount()
CATCH oError
msgStop( "No Query '" + cQuerySql + "'" )
showError( oError )
RETURN( .F. )
END
RETURN( oRs )
/*
* --------------------------------------------------------------------------*
* --------------------------------------------------------------------------*
*/
PROCEDURE showError( oError )
LOCAL cMensagemRetorno := ""
cMensagemRetorno := "[Subsystem]" + CRLF + oError:SubSystem + CRLF + CRLF + ;
"[SubCode]" + CRLF + alltrim( str( oError:SubCode ) ) + CRLF + CRLF + ;
"[Operacion]" + CRLF + oError:Operation + CRLF + CRLF + ;
"[Descripcion]" + CRLF + oError:Description + CRLF + CRLF + ;
"[Argumentos]" + CRLF + valToPrg( oError:Args )
RETURN( msgStop( cMensagemRetorno ) )
/*
* --------------------------------------------------------------------------*
* --------------------------------------------------------------------------*
*/
FUNCTION TxBrowseShow( oRs )
local oWnd, oBrw, oCol
DEFINE WINDOW ownd OF WndMain() TITLE "Test"
@ 0,0 XBROWSE oBrw OF oWnd RECSET oRs AUTOCOLS AUTOSORT FOOTERS FASTEDIT ;
LINES CELL
oBrw:createFromCode()
oWnd:oClient := oBrw
ACTIVATE WINDOW oWnd ON INIT oBrw:setFocus()
return nil
function MakeTabla( oCon )
local cCmdSql := "CREATE TABLE IF NOT EXISTS TEST ("+;
"ROW_ID INTEGER NOT NULL AUTO_INCREMENT COMMENT 'LLAVE',"+;
"CODIGO CHAR(5) NOT NULL COMMENT 'CODIGO CLIENTE',"+;
"NOMBRE CHAR(30) NOT NULL COMMENT 'NOMBRE CLIENTE',"+;
"ACTIVO BIT NOT NULL COMMENT 'ACTIVO',"+;
"PRIMARY KEY(ROW_ID))"+;
"ENGINE = InnoDB COMMENT 'Test';"
oCon:Execute( cCmdSql )
cCmdSql := "INSERT INTO TEST (CODIGO,NOMBRE,ACTIVO) VALUES('001','NOMBRE01',0);"
oCon:Execute( cCmdSql )
cCmdSql := "INSERT INTO TEST (CODIGO,NOMBRE,ACTIVO) VALUES('002','NOMBRE02',1);"
oCon:Execute( cCmdSql )
cCmdSql := "INSERT INTO TEST (CODIGO,NOMBRE,ACTIVO) VALUES('003','NOMBRE03',0);"
oCon:Execute( cCmdSql )
cCmdSql := "INSERT INTO TEST (CODIGO,NOMBRE,ACTIVO) VALUES('004','NOMBRE04',1);"
oCon:Execute( cCmdSql )
return nil
cCmdSql := "INSERT INTO TEST (CODIGO,NOMBRE,ACTIVO) VALUES('004','NOMBRE04','1');"
Application
===========
Path and name: C:\prg\Julio\ADODB.exe (32 bits)
Size: 1,806,848 bytes
Time from start: 0 hours 0 mins 5 secs
Error occurred at: 03/13/09, 15:19:56
Error description: Error ADODB.Connection/0 S_OK: EXECUTE
Args:
[ 1] = C INSERT INTO TEST (CODIGO,NOMBRE,ACTIVO) VALUES('001','NOMBRE01','0');
Stack Calls
===========
Called from: source\rtl\win32ole.prg => TOLEAUTO:EXECUTE(0)
Called from: C:\prg\Julio\ADODB.prg => MAKETABLA(182)
Called from: C:\prg\Julio\ADODB.prg => EXECCONNECTION(25)
Called from: C:\prg\Julio\ADODB.prg => MAIN(14)
System
======
CPU type: Intel(R) Core(TM)2 CPU 6600 @ 2.40GHz 2400 Mhz
Hardware memory: 2045 megs
Free System resources: 90 %
GDI resources: 90 %
User resources: 90 %
Compiler version: xHarbour build 1.1.0 Intl. (SimpLex) (Rev. 6195)
Windows version: 6.1, Build 7000
Windows total applications running: 0
Variables in use
================
Procedure Type Value
==========================
TOLEAUTO:EXECUTE
Param 1: C "INSERT INTO TEST (CODIGO,NOMBRE,ACTIVO) VALUES('001','NOMBRE01','0');"
Local 1: U
Local 2: N 0
MAKETABLA
Param 1: O Class: TOLEAUTO
Local 1: C "INSERT INTO TEST (CODIGO,NOMBRE,ACTIVO) VALUES('001','NOMBRE01','0');"
EXECCONNECTION
Local 1: O Class: TOLEAUTO
Local 2: U
Local 3: U
MAIN
Armando wrote:Daniel:
Aún no hago la prueba perooooooo, por aquí veo algo diferente:
Prueba cambiando los 0 y 1 cuando insertas los registros por '0' y '1' (tipo caracter)
- Code: Select all Expand view
cCmdSql := "INSERT INTO TEST (CODIGO,NOMBRE,ACTIVO) VALUES('004','NOMBRE04','1');"
Me comentas por favor
Saludos
cCmdSql: = "INSERT INTO TEST (CODIGO, NOMBRE, ACTIVO) VALUES ('001 ',' NOMBRE01 ', 0);"
Return to FiveWin para Harbour/xHarbour
Users browsing this forum: Google [Bot] and 31 guests