another error in class DataRow

another error in class DataRow

Postby lucasdebeltran » Sun Jun 09, 2013 10:08 am

Hello,

I am trying to add a new record:

Code: Select all  Expand view
#include "fivewin.ch"
#include "dbinfo.ch"
#include "adodef.ch"
#include "xbrowse.ch"
#include "Set.ch"


REQUEST HB_Lang_ES
REQUEST HB_CODEPAGE_ESWIN




FUNCTION MAIN()

   local cStr, oCn, oRs
   local oData


   // Idioma español
   HB_LangSelect("ES") // Para mensajes, fechas, etc..
   HB_CDPSELECT("ESWIN") // Para ordenación, requiere CodePage.lib

   // Driver CDX----------------------------------------------------------------
   REQUEST DBFCDX, DBFFPT

   RDDSETDEFAULT( "DBFCDX")

   SET DATE TO ITALIAN
   SET EPOCH TO 1990


   cStr  := "Driver={MySQL ODBC 3.51 Driver};Server=db4free.net;" + ;
            "Database=pruebasado;User=pruebasado;Password=123456;Option=3;"

   oCn   := FW_OpenAdoConnection( cStr )




   oRs   := FW_OpenRecordSet( oCn, "select * from clientes" )

   if oRs = nil
      msgstop("error opening recordset")
      oCn:Close()
      RETURN NIL
   endif


   xbrowser oRs


oData := TDataRow():New( oRs, nil, .T. )
oData:registro := 1
oData:nombre   := "Cliente añadido por Lucas3"
oData:email    := "mi email"

MsgInfo(oData:Modified(), "IsModified")

oData:Save()


xbrowser oRs


 oCn:Close()
 QUIT


RETURN NIL
//----------------------------------------------------------------------------//
 





This is the error:

Application
===========
Path and name: C:\ADO\DATAROW.exe (32 bits)
Size: 2,876,928 bytes
Compiler version: Harbour 3.2.0dev (Rev. 18881)
FiveWin Version: FWH 13.05
Windows version: 6.1, Build 7601 Service Pack 1

Time from start: 0 hours 0 mins 5 secs
Error occurred at: 09-06-13, 12:05:44
Error description: Error BASE/1004 Message not found: TDATAROW:ADDNEW

Stack Calls
===========
Called from: .\source\function\HARBOUR.PRG => _CLSSETERROR( 234 )
Called from: .\source\classes\DATAROW.PRG => TDATAROW:ADDNEW( 543 )
Called from: .\source\classes\DATAROW.PRG => TDATAROW:SAVEADO( 355 )
Called from: .\source\classes\DATAROW.PRG => TDATAROW:SAVE( 279 )
Called from: datarow.prg => MAIN( 79 )


Thank you.

What is the problem?.
Last edited by lucasdebeltran on Mon Jun 10, 2013 4:32 pm, edited 1 time in total.
Muchas gracias. Many thanks.

Un saludo, Best regards,

Harbour 3.2.0dev, Borland C++ 5.82 y FWH 13.06 [producción]

Implementando MSVC 2010, FWH64 y ADO.

Abandonando uso xHarbour y SQLRDD.
User avatar
lucasdebeltran
 
Posts: 1303
Joined: Tue Jul 21, 2009 8:12 am

Re: error in class DataRow

Postby lucasdebeltran » Sun Jun 09, 2013 12:35 pm

Hello,

Also, you have to control when modifying the table -oRs:Update()- that the record has not been deleted or modified in the meantime by another user in the network?.

How can be controlled that?.

Thank you.

Best regards
Muchas gracias. Many thanks.

Un saludo, Best regards,

Harbour 3.2.0dev, Borland C++ 5.82 y FWH 13.06 [producción]

Implementando MSVC 2010, FWH64 y ADO.

Abandonando uso xHarbour y SQLRDD.
User avatar
lucasdebeltran
 
Posts: 1303
Joined: Tue Jul 21, 2009 8:12 am

Re: error in class DataRow

Postby nageswaragunupudi » Sun Jun 09, 2013 5:21 pm

About the runtime error:
This is a bug in datarow.prg. Thanks for testing and finding it out.
In line 355, please change
::AddNew()
as
oRs:AddNew()

Next question about multiiuser issues:
1. If recordset is opened with adLockOptimistic:
If other user modified the same record we get a runtime error when we call oRs:Update. So catch the error in TRY/CATCH block and dealwith it.
2. If the recordset is opened in Batch Optimistic mode and if the provider is OLEDB
In most cases ReSync() works
First call oRs:ReSync( adAffectCurrent, adResyncUnderlyingValues ) // ( 1, 1 )
RecordSet reads current values into underlyingvalues

Each field has 3 values
:Value ( as modified by us )
:OriginalValue ( at the time recordset was read )
:UnderlyingValue ( After above resync, this is the present value on the Server)

If :Value <> :OriginalValue -> we modified the value after reading the recset
If :OriginalValue <> :UnderlyingValue --> Other user modified the value after we read the recordset.

Now in the program you decide if you want to overwrite or cancel edit and re-read new values from the server.

I do not think you can do with MySql ( I did not test ) because it is not full OLEDB provider but only ODBC driver.
We can use such features for mssql,oracle,etc
Regards

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

Re: error in class DataRow

Postby lucasdebeltran » Mon Jun 10, 2013 3:56 pm

Mr. Nages,

Thank you very much. Now I get:

Application
===========
Path and name: C:\tests\enrico.exe (32 bits)
Size: 2,878,464 bytes
Compiler version: Harbour 3.2.0dev (Rev. 18881)
FiveWin Version: FWH 13.05
Windows version: 6.1, Build 7601 Service Pack 1

Time from start: 0 hours 0 mins 2 secs
Error occurred at: 10-06-13, 17:55:01
Error description: Error BASE/1066 Error de argumento: conditional
Args:
[ 1] = U

Stack Calls
===========
Called from: enrico.prg => TDATAROW:SAVEADO( 556 )
Called from: enrico.prg => TDATAROW:SAVE( 467 )
Called from: enrico.prg => MAIN( 108 )





This is a working sample:

Code: Select all  Expand view
#include "fivewin.ch"
#include "dbinfo.ch"
#include "adodef.ch"
#include "xbrowse.ch"
#include "Set.ch"
#include "dbstruct.ch"


REQUEST HB_Lang_ES
REQUEST HB_CODEPAGE_ESWIN


#define STRIM( cStr, nChr ) Left( cStr, Len( cStr ) - nChr )
#define NTRIM( nNumber ) LTrim( Str( nNumber ) )





STATIC cCadena



//----------------------------------------------------------------------------------------
FUNCTION MAIN()

   local cStr, oCn, oRs
   local oData

   local lCreaTabla := .f.

   LOCAL aEstructura := { { "CODIGO"    , "N", 04, 0 }, ;
                          { "NOMBRE"    , "C", 70, 0 } }



   // Idioma español
   HB_LangSelect("ES") // Para mensajes, fechas, etc..
   HB_CDPSELECT("ESWIN") // Para ordenación, requiere CodePage.lib

   // Driver CDX----------------------------------------------------------------
   REQUEST DBFCDX, DBFFPT

   RDDSETDEFAULT( "DBFCDX")

   SET DATE TO ITALIAN
   SET EPOCH TO 1990





   cCadena := 'Provider='+"Microsoft.Jet.OLEDB.4.0"+';Data Source='+HB_DIRBASE()+"ACCESS.MDB"


   IF !FILE("ACCESS.MDB")
      MSGALERT( FW_CreateMDB( "ACCESS.MDB" ), "CREATED ACCESS.MDB")
      lCreaTabla := .T.
   ENDIF





   oCn   := FW_OpenAdoConnection( HB_DIRBASE()+"ACCESS.MDB" )




   IF lCreaTabla
      ADDTABLE( "JET", "CLIENTES", aEstructura )
   ENDIF






   oRs   := FW_OpenRecordSet( oCn, "select * from CLIENTES" )

   if oRs = nil
      FW_ShowAdoError( oCn )
      oCn:Close()
      RETURN NIL
   endif




xbrowser oRs



/*
 oData := TDataRow():New( oRs )
?oData:nombre
?len(oData:nombre)
*/



oData := TDataRow():New( oRs, nil, .T. )
oData:CODIGO   := NRANDOM(2)
oData:NOMBRE   := "Cliente añadido por Lucas3 "+cValToChar(time())
//oData:email    := "mi email "+cValToChar(Time())

MsgInfo(oData:Modified(), "IsModified")

oData:Save()




xbrowser oRs




 oRs:Close()
 oCn:Close()
 QUIT


RETURN NIL
//----------------------------------------------------------------------------//







STATIC FUNCTION ADDTABLE( cMot, cTab, aFld )

    LOCAL cQuery := "CREATE TABLE " + cTab + " ( "

    LOCAL cType

    LOCAL i

    DEFAULT cMot := "JET"



    IF cMot == "JET"
        cQuery += "Id COUNTER PRIMARY KEY, "
    ELSEIF cMot == "MSSQL"
        cQuery += "Id INT IDENTITY PRIMARY KEY, "
    ELSEIF cMot == "MYSQL"
        cQuery += "Id SERIAL, "
    ENDIF

    FOR i = 1 TO LEN( aFld )
        cType = aFld[ i, DBS_TYPE ]

        DO CASE
            CASE cType = "C"
                cQuery += aFld[ i, DBS_NAME ] + " VARCHAR ( " + NTRIM( aFld[ i, DBS_LEN ] ) + " ), "
            CASE cType = "N"
                cQuery += aFld[ i, DBS_NAME ] + " NUMERIC ( " + NTRIM( aFld[ i, DBS_LEN ] ) + ", " + NTRIM( aFld[ i, DBS_DEC ] ) + " ), "
            CASE cType = "D"
                cQuery += aFld[ i, DBS_NAME ] + " DATETIME, "
            CASE cType = "L"
                cQuery += aFld[ i, DBS_NAME ] + " INT, "
            CASE cType = "M"
                IF cMot == "JET"
                    cQuery += "[" + aFld[ i, DBS_NAME ] + "]" + " MEMO, "
                ELSEIF cMot == "MSSQL"
                    cQuery += "[" + aFld[ i, DBS_NAME ] + "]" + " TEXT, "
                ELSEIF cMot == "MYSQL"
                    cQuery += aFld[ i, DBS_NAME ] + " TEXT, "
                ENDIF
        ENDCASE
    NEXT

    cQuery = STRIM( cQuery, 2 ) + " )"

    SQLEXEC( cQuery )

RETURN NIL





FUNCTION SQLEXEC( cQuery )

    LOCAL cCns := cCadena //"Your connectionstring here"

    LOCAL oCn2 := CREATEOBJECT( "ADODB.Connection" )

    oCn2:CursorLocation = adUseClient

    oCn2:Open( cCns )

    oCn2:Execute( cQuery )

    oCn2:Close()

 RETURN NIL







//----------------------------------------------------------------------------//
 




Thank you.

Best regards
Last edited by lucasdebeltran on Mon Jun 10, 2013 8:42 pm, edited 1 time in total.
Muchas gracias. Many thanks.

Un saludo, Best regards,

Harbour 3.2.0dev, Borland C++ 5.82 y FWH 13.06 [producción]

Implementando MSVC 2010, FWH64 y ADO.

Abandonando uso xHarbour y SQLRDD.
User avatar
lucasdebeltran
 
Posts: 1303
Joined: Tue Jul 21, 2009 8:12 am

Re: another error in class DataRow

Postby nageswaragunupudi » Mon Jun 10, 2013 8:31 pm

Mr Lucas

Probably, your error is in this line:
Code: Select all  Expand view
     if aPair[ 3 ] .and. ! ( oField:Value == uVal )
 

Please change it as
Code: Select all  Expand view
     if IfNil(aPair[ 3 ], .t. ) .and. ! ( oField:Value == uVal )
 


Is it appropriate to publish entire new classes of FWH here?
Regards

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

Re: another error in class DataRow

Postby lucasdebeltran » Mon Jun 10, 2013 8:44 pm

Dear Mr. Nages,

Thank you very much. It is working OK now.

I remove the class, but it is useless as some new functions at olefuncs.prg and xbrowse.prg are needed.

Also, I published it because I need to fix the class according to your instructions at oRs:AddNew().

I very much like the concept and design of that class.
Muchas gracias. Many thanks.

Un saludo, Best regards,

Harbour 3.2.0dev, Borland C++ 5.82 y FWH 13.06 [producción]

Implementando MSVC 2010, FWH64 y ADO.

Abandonando uso xHarbour y SQLRDD.
User avatar
lucasdebeltran
 
Posts: 1303
Joined: Tue Jul 21, 2009 8:12 am

Re: another error in class DataRow

Postby nageswaragunupudi » Tue Jun 11, 2013 5:52 am

Mr Lucas

Thanks for pointing out the two bugs.
Wish you test with DBF, Ado and oBrw. ( Only edits for oBrw )
Now it works for TDatabase also. In the next version we extend it to all kinds of classes.

Advantage of this class is that once the programmer specifies the datasource, he can work independent of the datasource and is not worried about reading and saving. This enables common code to work with different datasources.

At present the default edit dialog is simple. We plan to include handling of images, memos, Rtf, etc without any programming effort.
Any suggestions/criticism welcome.
Regards

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


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot], jmartial and 119 guests