Using ADOCE

Re: Using ADOCE

Postby anserkk » Thu Feb 19, 2009 4:47 am

Dear Mr.Antonio and Mr.Sergio,

Thankyou very much for the info and the sample :D . I was looking for a solution on how a FWPPC application can access a MYSQL Database installed on a server and MySQL support on Windows Mobile devices. I understand that MySQLMobile is a commercial software. I hope that we can create FWPPC compatible lib as demonstarated by you, once we purchase a Full version of MySqlMobile.

Regards

Anser
User avatar
anserkk
 
Posts: 1333
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India

Re: Using ADOCE

Postby Antonio Linares » Thu Feb 19, 2009 6:39 am

Sergio,

> The Test return 0 (é normal)

Yes, it is ok! :-)

It means connected! :-)

>
Podemos tentar Ligar
MyExeQuery ? - Executar uma query
MySelectDb ? - Abrir Base de Dados
MyDesconec ? - Desconectar
>

Yes, lets do it :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42117
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Using ADOCE

Postby Antonio Linares » Thu Feb 19, 2009 6:50 am

A new test.prg with mysql errors support:

test.prg
Code: Select all  Expand view  RUN
#include "FWCE.ch"

function Main()

   local nRet := MySQL_Connect( "192.168.0.30", 3306, "username", "password" )
   
   if nRet == 0
      MsgInfo( "successful connection" )
   else
      MsgInfo( MySQL_Get_Last_Error( nRet ) )
   endif    
   
return nil  

#pragma BEGINDUMP

int  mysql_connect( char * host, int iPort, char * pszUsername, char * pszPassword );
void mysql_get_last_error( int nErrorCode, char * pszError );

#include <hbapi.h>

HB_FUNC( MYSQL_CONNECT )
{
   hb_retnl( mysql_connect( hb_parc( 1 ), hb_parnl( 2 ), hb_parc( 3 ), hb_parc( 4 ) ) );
}

HB_FUNC( MYSQL_GET_LAST_ERROR )
{
   char error[ 255 ];
   
   mysql_get_last_error( hb_parnl( 1 ), error );
   
   hb_retc( error );
}      

#pragma ENDDUMP
 

Image
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42117
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Using ADOCE

Postby Antonio Linares » Thu Feb 19, 2009 6:57 am

A new version with disconnect support:

test.prg
Code: Select all  Expand view  RUN
#include "FWCE.ch"

function Main()

   local nRet := MySQL_Connect( "192.168.0.30", 3306, "username", "password" )
   
   if nRet == 0
      MsgInfo( "successful connection" )
   else
      MsgInfo( MySQL_Get_Last_Error( nRet ) )
   endif    
   
   MySQL_Disconnect()
   
return nil  

#pragma BEGINDUMP

int  mysql_connect( char * host, int iPort, char * pszUsername, char * pszPassword );
void mysql_get_last_error( int nErrorCode, char * pszError );
int  mysql_disconnect( void );

#include <hbapi.h>

HB_FUNC( MYSQL_CONNECT )
{
   hb_retnl( mysql_connect( hb_parc( 1 ), hb_parnl( 2 ), hb_parc( 3 ), hb_parc( 4 ) ) );
}

HB_FUNC( MYSQL_GET_LAST_ERROR )
{
   char error[ 255 ];
   
   mysql_get_last_error( hb_parnl( 1 ), error );
   
   hb_retc( error );
}      

HB_FUNC( MYSQL_DISCONNECT )
{
   mysql_disconnect();
}  

#pragma ENDDUMP
 
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42117
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Using ADOCE

Postby Antonio Linares » Thu Feb 19, 2009 7:02 am

Selecting the database to work with:

test.prg
Code: Select all  Expand view  RUN
#include "FWCE.ch"

function Main()

   local nRet := MySQL_Connect( "192.168.0.30", 3306, "username", "password" )
   
   if nRet == 0
      MsgInfo( "successful connection" )
      nRet = MySQL_Select_DB( "test" )
      if nRet == 0
         MsgInfo( "database properly selected" )
      else  
         MsgInfo( MySQL_Get_Last_Error( nRet ) )
      endif  
   else
      MsgInfo( MySQL_Get_Last_Error( nRet ) )
   endif    
   
   MySQL_Disconnect()
   
return nil  

#pragma BEGINDUMP

int  mysql_connect( char * host, int iPort, char * pszUsername, char * pszPassword );
void mysql_get_last_error( int nErrorCode, char * pszError );
int  mysql_disconnect( void );
int  mysql_select_db( char * pszDatabaseName );

#include <hbapi.h>

HB_FUNC( MYSQL_CONNECT )
{
   hb_retnl( mysql_connect( hb_parc( 1 ), hb_parnl( 2 ), hb_parc( 3 ), hb_parc( 4 ) ) );
}

HB_FUNC( MYSQL_GET_LAST_ERROR )
{
   char error[ 255 ];
   
   mysql_get_last_error( hb_parnl( 1 ), error );
   
   hb_retc( error );
}      

HB_FUNC( MYSQL_DISCONNECT )
{
   mysql_disconnect();
}  

HB_FUNC( MYSQL_SELECT_DB )
{
   hb_retnl( mysql_select_db( hb_parc( 1 ) ) );
}  

#pragma ENDDUMP
 
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42117
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Using ADOCE

Postby Antonio Linares » Thu Feb 19, 2009 7:10 am

Doing a SQL query:

test.prg
Code: Select all  Expand view  RUN
#include "FWCE.ch"

#define MYSQL_PORT  3306

function Main()

   local nRet := MySQL_Connect( "192.168.0.30", MYSQL_PORT, "username", "password" )
   
   if nRet == 0
      MsgInfo( "successful connection" )
      nRet = MySQL_Select_DB( "test" )
      if nRet == 0
         MsgInfo( "database properly selected" )
      else  
         MsgInfo( MySQL_Get_Last_Error( nRet ) )
      endif  
      nRet = MySQL_Execute_Query( "SELECT * FROM Customers LIMIT 100" )
      if nRet != 0
         MsgInfo( MySQL_Get_Last_Error( nRet ) )
      endif  
   else
      MsgInfo( MySQL_Get_Last_Error( nRet ) )
   endif    
   
   MySQL_Disconnect()
   
return nil  

#pragma BEGINDUMP

int  mysql_connect( char * host, int iPort, char * pszUsername, char * pszPassword );
void mysql_get_last_error( int nErrorCode, char * pszError );
int  mysql_disconnect( void );
int  mysql_select_db( char * pszDatabaseName );
int  mysql_execute_query( char * pszQueryString );

#include <hbapi.h>

HB_FUNC( MYSQL_CONNECT )
{
   hb_retnl( mysql_connect( hb_parc( 1 ), hb_parnl( 2 ), hb_parc( 3 ), hb_parc( 4 ) ) );
}

HB_FUNC( MYSQL_GET_LAST_ERROR )
{
   char error[ 255 ];
   
   mysql_get_last_error( hb_parnl( 1 ), error );
   
   hb_retc( error );
}      

HB_FUNC( MYSQL_DISCONNECT )
{
   mysql_disconnect();
}  

HB_FUNC( MYSQL_SELECT_DB )
{
   hb_retnl( mysql_select_db( hb_parc( 1 ) ) );
}  

HB_FUNC( MYSQL_EXECUTE_QUERY )
{
   hb_retnl( mysql_execute_query( hb_parc( 1 ) ) );
}  

#pragma ENDDUMP
 
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42117
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Using ADOCE

Postby Antonio Linares » Thu Feb 19, 2009 8:31 am

A live test against http://www.FreeMySQL.net:

test.prg
Code: Select all  Expand view  RUN
#include "FWCE.ch"

#define MYSQL_PORT  3306

function Main()

   local nRet := MySQL_Connect( "SQL06.FREEMYSQL.NET", MYSQL_PORT, "fivetech", "fivewin" ) // username, password
   
   if nRet == 0
      MsgInfo( "successful connection" )
      nRet = MySQL_Select_DB( "fwppc" )
      if nRet == 0
         MsgInfo( "database properly selected" )
      else  
         MsgInfo( MySQL_Get_Last_Error( nRet ) )
      endif  
      nRet = MySQL_Execute_Query( "SELECT * FROM customers LIMIT 100" )
      if nRet != 0
         MsgInfo( MySQL_Get_Last_Error( nRet ) )
      else
         MsgInfo( "Number of fields: " + Str( MySQL_Get_FieldCount() ) )  
      endif
   else
      MsgInfo( MySQL_Get_Last_Error( nRet ) )
   endif    
   
   MySQL_Disconnect()
   
return nil  

#pragma BEGINDUMP

int  mysql_connect( char * host, int iPort, char * pszUsername, char * pszPassword );
void mysql_get_last_error( int nErrorCode, char * pszError );
int  mysql_disconnect( void );
int  mysql_select_db( char * pszDatabaseName );
int  mysql_execute_query( char * pszQueryString );
int  mysql_get_fieldcount( void );

#include <hbapi.h>

HB_FUNC( MYSQL_CONNECT )
{
   hb_retnl( mysql_connect( hb_parc( 1 ), hb_parnl( 2 ), hb_parc( 3 ), hb_parc( 4 ) ) );
}

HB_FUNC( MYSQL_GET_LAST_ERROR )
{
   char error[ 255 ];
   
   mysql_get_last_error( hb_parnl( 1 ), error );
   
   hb_retc( error );
}      

HB_FUNC( MYSQL_DISCONNECT )
{
   mysql_disconnect();
}  

HB_FUNC( MYSQL_SELECT_DB )
{
   hb_retnl( mysql_select_db( hb_parc( 1 ) ) );
}  

HB_FUNC( MYSQL_EXECUTE_QUERY )
{
   hb_retnl( mysql_execute_query( hb_parc( 1 ) ) );
}  

HB_FUNC( MYSQL_GET_FIELDCOUNT )
{
   hb_retnl( mysql_get_fieldcount() );
}

#pragma ENDDUMP
 

Image
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42117
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Using ADOCE

Postby Antonio Linares » Thu Feb 19, 2009 8:47 am

Getting the fieldnames:

test.prg
Code: Select all  Expand view  RUN
#include "FWCE.ch"

#define MYSQL_PORT  3306

function Main()

   local nRet := MySQL_Connect( "SQL06.FREEMYSQL.NET", MYSQL_PORT, "fivetech", "fivewin" ) // username, password
   local nFields, cFieldName
   
   if nRet == 0
      MsgInfo( "successful connection" )
     
      nRet = MySQL_Select_DB( "fwppc" )
      if nRet == 0
         MsgInfo( "database properly selected" )
      else  
         MsgInfo( MySQL_Get_Last_Error( nRet ) )
      endif  
     
      nRet = MySQL_Execute_Query( "SELECT * FROM customers LIMIT 100" )
      if nRet != 0
         MsgInfo( MySQL_Get_Last_Error( nRet ) )
      else
         MsgInfo( "Number of fields: " + Str( nFields := MySQL_Get_FieldCount() ) )  
         for n = 1 to nFields
             MySQL_Get_Field( n, @cFieldName )
             MsgInfo( AllTrim( Str( n ) ) + ": " + cFieldName )
         next    
      endif
     
   else
      MsgInfo( MySQL_Get_Last_Error( nRet ) )
   endif    
   
   MySQL_Disconnect()
   
   MsgInfo( "done!" )
   
return nil  

#pragma BEGINDUMP

// field parameters for mysql_get_field_param() function
#define FIELD_PARAM_CATALOG              1
#define FIELD_PARAM_DB                   2
#define FIELD_PARAM_TABLE                3
#define FIELD_PARAM_ORIGTABLE            4
#define FIELD_PARAM_FIELD                5
#define FIELD_PARAM_ORIGFIELD            6
#define FIELD_PARAM_LENGTH               7
#define FIELD_PARAM_TYPE                 8
#define FIELD_PARAM_FLAGS                9
#define FIELD_PARAM_DECIMALS            10

int  mysql_connect( char * host, int iPort, char * pszUsername, char * pszPassword );
void mysql_get_last_error( int nErrorCode, char * pszError );
int  mysql_disconnect( void );
int  mysql_select_db( char * pszDatabaseName );
int  mysql_execute_query( char * pszQueryString );
int  mysql_get_fieldcount( void );
int  mysql_get_field( char * char_val, int * int_val, int nParam, int nIndex );

#include <hbapi.h>

HB_FUNC( MYSQL_CONNECT ) // cHost, nPort, cUserName, cPassword
{
   hb_retnl( mysql_connect( hb_parc( 1 ), hb_parnl( 2 ), hb_parc( 3 ), hb_parc( 4 ) ) );
}

HB_FUNC( MYSQL_GET_LAST_ERROR ) // nCode --> cError
{
   char error[ 255 ];
   
   mysql_get_last_error( hb_parnl( 1 ), error );
   
   hb_retc( error );
}      

HB_FUNC( MYSQL_DISCONNECT )
{
   mysql_disconnect();
}  

HB_FUNC( MYSQL_SELECT_DB ) // cDataBaseName --> nRet
{
   hb_retnl( mysql_select_db( hb_parc( 1 ) ) );
}  

HB_FUNC( MYSQL_EXECUTE_QUERY ) // cSQLQuery --> nRet
{
   hb_retnl( mysql_execute_query( hb_parc( 1 ) ) );
}  

HB_FUNC( MYSQL_GET_FIELDCOUNT ) // --> nFields
{
   hb_retnl( mysql_get_fieldcount() );
}

HB_FUNC( MYSQL_GET_FIELD ) // nField, @cName --> nRet
{
   char fieldname[ 255 ];
   int int_buffer, iRet;
   
   iRet = mysql_get_field( fieldname, &int_buffer, FIELD_PARAM_FIELD, hb_parnl( 1 ) - 1 );
   
   hb_storc( fieldname, 2 );
   hb_retnl( iRet );
}  

#pragma ENDDUMP
 
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42117
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Using ADOCE

Postby Antonio Linares » Thu Feb 19, 2009 9:05 am

Retrieving fields values! :-)

test.prg
Code: Select all  Expand view  RUN
#include "FWCE.ch"

#define MYSQL_PORT  3306

function Main()

   local nRet := MySQL_Connect( "SQL06.FREEMYSQL.NET", MYSQL_PORT, "fivetech", "fivewin" ) // username, password
   local nFields, cFieldName, n, nRow, nField, cFieldValue
   
   if nRet == 0
      MsgInfo( "successful connection" )
     
      nRet = MySQL_Select_DB( "fwppc" )
      if nRet == 0
         MsgInfo( "database properly selected" )
      else  
         MsgInfo( MySQL_Get_Last_Error( nRet ) )
      endif  
     
      nRet = MySQL_Execute_Query( "SELECT * FROM customers LIMIT 100" )
      if nRet != 0
         MsgInfo( MySQL_Get_Last_Error( nRet ) )
      else
         MsgInfo( "Number of fields: " + Str( nFields := MySQL_Get_FieldCount() ) )  
         for n = 1 to nFields
            MySQL_Get_Field( n, @cFieldName )
            MsgInfo( AllTrim( Str( n ) ) + ": " + cFieldName )
         next  
         for n = 1 to MySQL_Get_RowCount()
            for nField = 1 to MySQL_Get_FieldCount()
                MySQL_Get_Data( @cFieldValue, nRow, nField )              
                MsgInfo( cFieldValue )
            next
         next        
      endif
     
   else
      MsgInfo( MySQL_Get_Last_Error( nRet ) )
   endif    
   
   MySQL_Disconnect()
   
   MsgInfo( "done!" )
   
return nil  

#pragma BEGINDUMP

// field parameters for mysql_get_field_param() function
#define FIELD_PARAM_CATALOG              1
#define FIELD_PARAM_DB                   2
#define FIELD_PARAM_TABLE                3
#define FIELD_PARAM_ORIGTABLE            4
#define FIELD_PARAM_FIELD                5
#define FIELD_PARAM_ORIGFIELD            6
#define FIELD_PARAM_LENGTH               7
#define FIELD_PARAM_TYPE                 8
#define FIELD_PARAM_FLAGS                9
#define FIELD_PARAM_DECIMALS            10

int  mysql_connect( char * host, int iPort, char * pszUsername, char * pszPassword );
void mysql_get_last_error( int nErrorCode, char * pszError );
int  mysql_disconnect( void );
int  mysql_select_db( char * pszDatabaseName );
int  mysql_execute_query( char * pszQueryString );
int  mysql_get_fieldcount( void );
int  mysql_get_field( char * char_val, int * int_val, int nParam, int nIndex );
int  mysql_get_rowcount( void );
int  mysql_get_data( char * pszElem, int nRow, int nColumn );

#include <hbapi.h>

HB_FUNC( MYSQL_CONNECT ) // cHost, nPort, cUserName, cPassword
{
   hb_retnl( mysql_connect( hb_parc( 1 ), hb_parnl( 2 ), hb_parc( 3 ), hb_parc( 4 ) ) );
}

HB_FUNC( MYSQL_GET_LAST_ERROR ) // nCode --> cError
{
   char error[ 255 ];
   
   mysql_get_last_error( hb_parnl( 1 ), error );
   
   hb_retc( error );
}      

HB_FUNC( MYSQL_DISCONNECT )
{
   mysql_disconnect();
}  

HB_FUNC( MYSQL_SELECT_DB ) // cDataBaseName --> nRet
{
   hb_retnl( mysql_select_db( hb_parc( 1 ) ) );
}  

HB_FUNC( MYSQL_EXECUTE_QUERY ) // cSQLQuery --> nRet
{
   hb_retnl( mysql_execute_query( hb_parc( 1 ) ) );
}  

HB_FUNC( MYSQL_GET_FIELDCOUNT ) // --> nFields
{
   hb_retnl( mysql_get_fieldcount() );
}

HB_FUNC( MYSQL_GET_FIELD ) // nField, @cName --> nRet
{
   char fieldname[ 255 ];
   int int_buffer;
   
   hb_retnl( mysql_get_field( fieldname, &int_buffer, FIELD_PARAM_FIELD, hb_parnl( 1 ) - 1 ) );
   hb_storc( fieldname, 2 );
}  

HB_FUNC( MYSQL_GET_ROWCOUNT ) // --> nRows
{
   hb_retnl( mysql_get_rowcount() );
}  

HB_FUNC( MYSQL_GET_DATA ) // @cFieldData, nRow, nField --> nRet
{
   char buffer[ 8192 ]; // max data size = 8K  
   
   hb_retnl( mysql_get_data( buffer, hb_parnl( 2 ) - 1, hb_parnl( 3 ) - 1 ) );
   hb_storc( buffer, 1 );
}
   
#pragma ENDDUMP
 
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42117
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Using ADOCE

Postby rasptty » Thu Feb 19, 2009 10:47 am

Excelent Linares :D

I testing with LAN - WIFI - it´s ok
I testing with NET - 3G - GPRS - it´s ok

FWPPC - In Progress

Regards, Saludos

Sergio
rasptty
 
Posts: 88
Joined: Sun May 25, 2008 5:46 pm

Re: Using ADOCE

Postby Antonio Linares » Thu Feb 19, 2009 11:18 am

Sergio,

Yes, it is working very nicely :-)

Thanks for your feedback,
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42117
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Using ADOCE

Postby rasptty » Fri Feb 20, 2009 12:23 am

Linares

Acabei por comprar o Mysqlmobile.dll - Versão 7 - full version
now i testing your test.prg

MySQL_Connect - Return OK
MySQL_Select_DB - Return OK

But after return the ERROR FIX GPFStack() in the your file test.prg

Regards

Sergio
rasptty
 
Posts: 88
Joined: Sun May 25, 2008 5:46 pm

Re: Using ADOCE

Postby Maurizio » Fri Feb 20, 2009 8:50 am

Hello Antonio

I add echo MySQLMobile.lib >> msvc.tmp into the buildce.bat

But I have this error

SQLNet.obj : error LNK2019: unresolved external symbol "void __cdecl mysql_get_l
ast_error(int,char *)" (?mysql_get_last_error@@YAXHPAD@Z) referenced in function
HB_FUN_MYSQL_GET_LAST_ERROR
SQLNet.obj : error LNK2019: unresolved external symbol "int __cdecl mysql_discon
nect(void)" (?mysql_disconnect@@YAHXZ) referenced in function HB_FUN_MYSQL_DISCO
NNECT
SQLNet.obj : error LNK2019: unresolved external symbol "int __cdecl mysql_select
_db(char *)" (?mysql_select_db@@YAHPAD@Z) referenced in function HB_FUN_MYSQL_SE
LECT_DB
SQLNet.obj : error LNK2019: unresolved external symbol "int __cdecl mysql_execut
e_query(char *)" (?mysql_execute_query@@YAHPAD@Z) referenced in function HB_FUN_
MYSQL_EXECUTE_QUERY
SQLNet.obj : error LNK2019: unresolved external symbol "int __cdecl mysql_get_fi
eldcount(void)" (?mysql_get_fieldcount@@YAHXZ) referenced in function HB_FUN_MYS
QL_GET_FIELDCOUNT
SQLNet.obj : error LNK2019: unresolved external symbol "int __cdecl mysql_get_fi
eld(char *,int *,int,int)" (?mysql_get_field@@YAHPADPAHHH@Z) referenced in funct
ion HB_FUN_MYSQL_GET_FIELD
SQLNet.exe : fatal error LNK1120: 7 unresolved externals

Regards MAurizio
User avatar
Maurizio
 
Posts: 825
Joined: Mon Oct 10, 2005 1:29 pm

Re: Using ADOCE

Postby Antonio Linares » Fri Feb 20, 2009 1:04 pm

Maurizio,

You are compiling, with the C compiler, using C++ mode.

Please remove the /Tp flag, thanks :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42117
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Using ADOCE

Postby rasptty » Fri Feb 20, 2009 5:10 pm

For user´s the DLL MySQLMobile Version 1.7

Modify respectiv MySQLMobile.LIB in ...\vce\lib\arm\

download file in
http://www.briweb.net/software/c/MySQLMobile.lib


in build.bat
.......\MySQLMobile.lib >> msvc.tmp


I´Testing and RUN OK


Best REGARDS

Sergio
rasptty
 
Posts: 88
Joined: Sun May 25, 2008 5:46 pm

PreviousNext

Return to FiveWin for Pocket PC

Who is online

Users browsing this forum: No registered users and 2 guests