Files
harbour-core/harbour/contrib/hbmysql/mysql.c
Viktor Szakats 23dd5b134d 2010-06-19 09:52 UTC+0200 Viktor Szakats (harbour.01 syenar.hu)
* src/vm/runner.c
    ! Minor to prev.

  * include/hbapi.h
  * src/vm/extend.c
    + Added hb_parnsize(), hb_retnsize(), hb_stornsize() functions.
    ; NOTE: These should be used in place of hb_parnl(), hb_retnl(),
            hb_stornl() when passing HB_SIZE types.
    ; TODO: Use them all accross Harbour if they are correct and
            after being finalized.

  * src/vm/itemapi.c
    + Added hb_itemGetNSize(), hb_itemPutNSize() functions.
    * DATETIME stuff in hb_itemGetNL() marked as HB_LEGACY_LEVEL3.
    ; QUESTION: It's marked as to be deleted in the TODO, so maybe we should
                rather delete it.

  * include/hbapiitm.h
  * src/rtl/filesys.c
    + hb_fsReadAt(), hb_fsWriteAt(): Added support for Win64 HB_SIZE.
    ; QUESTION: I assume these functions have the purpose of being
                atomic seek + read without moving the file pointer,
                which means current modification isn't safe. How
                can this be solved given Windows doesn't seem to have
                64-bit read/write API calls?
    ! Fixed old copy-paste typos in Windows OVERLAPPED initialization,
      where the lines were ended with command instead of semicolon,
      they didn't cause any harm though in their former location.
    % Reverted a minor change from prev commit to make it
      possibly a little bit faster, like it was before.

  * src/rtl/hbzlib.c
    + Added casts (at external interface calls) and other fixes to
      make it build for Win64 without warnings.

  * src/rdd/dbfntx/dbfntx1.c
  * src/rdd/dbfnsx/dbfnsx1.c
  * src/rdd/dbfcdx/dbfcdx1.c
  * src/rdd/dbffpt/dbffpt1.c
  * contrib/rddbmcdx/bmdbfcdx.c
    * HB_ULONG -> HB_SIZE where appropriate to avoid Win64 errors
      and some warnings. I'm still not comfortable to touch this
      code, but it could certainly need a type cleanup.

  * include/hbdefs.h
    + Added HB_PFS macro which holds the printf() format string
      for HB_SIZE value.
    ; TODO: Use it all accross Harbour.

  * contrib/hbmysql/mysql.c
  * contrib/sddmy/sddmy.c
  * contrib/hbmzip/hbmzip.c
  * contrib/hbcurl/hbcurl.c
  * contrib/hbhpdf/harupdf.c
  * contrib/hbpgsql/postgres.c
  * contrib/rddads/adsfunc.c
  * contrib/rddads/ads1.c
  * contrib/hbfimage/fi_wrp.c
  * contrib/sddodbc/sddodbc.c
  * contrib/hbgd/gdwrp.c
  * contrib/hbwin/wapi_wingdi.c
  * contrib/hbwin/wapi_winbase.c
  * contrib/hbwin/wapi_winuser.c
  * contrib/hbwin/win_bmp.c
  * contrib/hbwin/win_prn1.c
  * contrib/hbwin/win_regc.c
  * contrib/hbssl/evpciph.c
  * contrib/hbssl/ssl.c
  * contrib/hbssl/bio.c
  * contrib/hbssl/sslctx.c
  * contrib/hbssl/evpenc.c
  * contrib/hbssl/pem.c
  * contrib/hbssl/rand.c
  * contrib/hbssl/evp.c
    + Added necessary casts at external component boundaries to
      make Win64 builds warning-free.

  * contrib/hbct/ctstrfil.c
    + HB_ISIZ -> HB_FOFFSET, hb_fsSeek() usage, other type cleanup
      to handle file offsets correctly.

  * contrib/xhb/hbnxs.h
  * contrib/xhb/hbcrypt.c
    ! Fixed warnings for Win64.

  * contrib/hbwin/win_prn3.c
  * contrib/xhb/dbf2txt.c
  * contrib/xhb/fparse.c
    * int -> HB_ISIZ for Win64.

  * contrib/xhb/freadlin.c
    * hb_fsSeek() -> hb_fsSeekLarge().

  * contrib/sddfb/sddfb.c
    * Minor type cleanup to make Win64 warning-free.

  * contrib/hbsqlit3/hbsqlit3.c
    + Added necessary casts at external interface calls.
    % Deleted one dummy operation from SQLITE3_FILE_TO_BUFF().

  * contrib/rddsql/sqlmix.c
  * contrib/rddads/adsx.c
    * HB_ULONG -> HB_SIZE.

  * contrib/gtwvg/gtwvg.c
  * contrib/gtwvg/wvggui.c
  * contrib/gtwvg/wvgcuig.c
  * contrib/gtwvg/wvgwin.c
  * contrib/gtwvg/wvgutils.c
  * contrib/gtwvg/wvgcore.c
    ! int -> HB_ISIZ/HB_SIZE
    + Added necessary casts at external component boundaries to
      make Win64 warning-free.

  * contrib/rddads/ads1.c
    * HB_ULONG -> HB_SIZE

  * contrib/hbtip/utils.c
    * int -> HB_ISIZ
    ! Fixed to use HB_FOFFSET type to save/restore file position.

  * ChangeLog
    + Added missing item to previous log entry:
      ! Fixed hb_fsCurDirBuff() for Win64.

  ; It's quite large commit, nevertheless I'd highly appreciate
    peer review, and certainly there will be places which need
    better or different solution for Win64.
2010-06-19 08:05:24 +00:00

611 lines
16 KiB
C

/*
* $Id$
*/
/*
* Harbour Project source code:
* MySQL DBMS low level (client api) interface code.
*
* Copyright 2010 Viktor Szakats (harbour.01 syenar.hu) (GC support)
* Copyright 2000 Maurilio Longo <maurilio.longo@libero.it>
* www - http://harbour-project.org
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this software; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/).
*
* As a special exception, the Harbour Project gives permission for
* additional uses of the text contained in its release of Harbour.
*
* The exception is that, if you link the Harbour libraries with other
* files to produce an executable, this does not by itself cause the
* resulting executable to be covered by the GNU General Public License.
* Your use of that executable is in no way restricted on account of
* linking the Harbour library code into it.
*
* This exception does not however invalidate any other reasons why
* the executable file might be covered by the GNU General Public License.
*
* This exception applies only to the code released by the Harbour
* Project under the name Harbour. If you copy code from other
* Harbour Project or Free Software Foundation releases into a copy of
* Harbour, as the General Public License permits, the exception does
* not apply to the code that you add in this way. To avoid misleading
* anyone as to the status of such modified files, you must delete
* this exception notice from them.
*
* If you write modifications of your own for Harbour, it is your choice
* whether to permit this exception to apply to your modifications.
* If you do not wish that, delete this exception notice.
*
*/
/*
* The following parts are Copyright of the individual authors.
* www - http://harbour-project.org
*
* Copyright 2001 Luiz Rafael Culik <culik@sl.conex.net>
* DATATOSQL(), FILETOSQLBINARY()
*
* See COPYING for licensing terms.
*
*/
#include "hbapi.h"
#include "hbapierr.h"
#include "hbapiitm.h"
#include "hbapifs.h"
#if defined( HB_OS_WIN )
/* NOTE: To satisfy MySQL headers. */
#include <winsock2.h>
#endif
#include "mysql.h"
/* NOTE: OS/2 EMX port of MySQL needs libmysqlclient.a from 3.21.33b build which has st and mt
versions of client library. I'm using ST version since harbour is single threaded.
You need also .h files from same distribution. */
/* GC object handlers */
static HB_GARBAGE_FUNC( MYSQL_release )
{
void ** ph = ( void ** ) Cargo;
/* Check if pointer is not NULL to avoid multiple freeing */
if( ph && * ph )
{
/* Destroy the object */
mysql_close( ( MYSQL * ) * ph );
/* set pointer to NULL to avoid multiple freeing */
* ph = NULL;
}
}
static const HB_GC_FUNCS s_gcMYSQLFuncs =
{
MYSQL_release,
hb_gcDummyMark
};
static void hb_MYSQL_ret( MYSQL * p )
{
if( p )
{
void ** ph = ( void ** ) hb_gcAllocate( sizeof( MYSQL * ), &s_gcMYSQLFuncs );
* ph = p;
hb_retptrGC( ph );
}
else
hb_retptr( NULL );
}
static MYSQL * hb_MYSQL_par( int iParam )
{
void ** ph = ( void ** ) hb_parptrGC( &s_gcMYSQLFuncs, iParam );
return ph ? ( MYSQL * ) * ph : NULL;
}
static HB_GARBAGE_FUNC( MYSQL_RES_release )
{
void ** ph = ( void ** ) Cargo;
/* Check if pointer is not NULL to avoid multiple freeing */
if( ph && * ph )
{
/* Destroy the object */
mysql_free_result( ( MYSQL_RES * ) * ph );
/* set pointer to NULL to avoid multiple freeing */
* ph = NULL;
}
}
static const HB_GC_FUNCS s_gcMYSQL_RESFuncs =
{
MYSQL_RES_release,
hb_gcDummyMark
};
static void hb_MYSQL_RES_ret( MYSQL_RES * p )
{
if( p )
{
void ** ph = ( void ** ) hb_gcAllocate( sizeof( MYSQL_RES * ), &s_gcMYSQL_RESFuncs );
* ph = p;
hb_retptrGC( ph );
}
else
hb_retptr( NULL );
}
static MYSQL_RES * hb_MYSQL_RES_par( int iParam )
{
void ** ph = ( void ** ) hb_parptrGC( &s_gcMYSQL_RESFuncs, iParam );
return ph ? ( MYSQL_RES * ) * ph : NULL;
}
/* API wrappers */
HB_FUNC( MYSQL_REAL_CONNECT ) /* MYSQL * mysql_real_connect( MYSQL *, char * host, char * user, char * password, char * db, uint port, char *, uint flags ) */
{
const char * szHost = hb_parc( 1 );
const char * szUser = hb_parc( 2 );
const char * szPass = hb_parc( 3 );
#if MYSQL_VERSION_ID > 32200
MYSQL * mysql;
unsigned int port = ( unsigned int ) hb_parnidef( 4, MYSQL_PORT );
unsigned int flags = ( unsigned int ) hb_parnidef( 5, 0 );
if( ( mysql = mysql_init( ( MYSQL * ) NULL ) ) != NULL )
{
/* from 3.22.x of MySQL there is a new parameter in mysql_real_connect() call, that is char * db
which is not used here */
if( mysql_real_connect( mysql, szHost, szUser, szPass, 0, port, NULL, flags ) )
hb_MYSQL_ret( mysql );
else
{
mysql_close( mysql );
hb_retptr( NULL );
}
}
else
hb_retptr( NULL );
#else
hb_MYSQL_ret( mysql_real_connect( NULL, szHost, szUser, szPass, 0, NULL, 0 ) );
#endif
}
#if defined( HB_LEGACY_LEVEL3 )
/* NOTE: Deprecated */
HB_FUNC( MYSQL_CLOSE ) /* void mysql_close( MYSQL * mysql ) */
{
void ** ph = ( void ** ) hb_parptrGC( &s_gcMYSQLFuncs, 1 );
/* Check if pointer is not NULL to avoid multiple freeing */
if( ph && * ph )
{
/* Destroy the object */
mysql_close( ( MYSQL * ) * ph );
/* set pointer to NULL to avoid multiple freeing */
* ph = NULL;
}
}
#endif
HB_FUNC( MYSQL_GET_SERVER_VERSION ) /* long mysql_get_server_version( MYSQL * ) */
{
MYSQL * mysql = hb_MYSQL_par( 1 );
if( mysql )
{
#if MYSQL_VERSION_ID >= 40100
hb_retnl( ( long ) mysql_get_server_version( mysql ) );
#else
const char * szVer = mysql_get_server_info( mysql );
long lVer = 0;
while( *szVer )
{
if( *szVer >= '0' && *szVer <= '9' )
lVer = lVer * 10 + *szVer;
++szVer;
}
hb_retnl( lVer );
#endif
}
else
hb_errRT_BASE( EG_ARG, 2020, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( MYSQL_COMMIT ) /* bool mysql_commit( MYSQL * mysql ) */
{
MYSQL * mysql = hb_MYSQL_par( 1 );
if( mysql )
{
#if MYSQL_VERSION_ID >= 40100
hb_retnl( ( long ) mysql_commit( mysql ) );
#else
hb_retnl( ( long ) mysql_query( mysql, "COMMIT" ) );
#endif
}
else
hb_errRT_BASE( EG_ARG, 2020, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( MYSQL_ROLLBACK ) /* bool mysql_rollback( MYSQL * mysql ) */
{
MYSQL * mysql = hb_MYSQL_par( 1 );
if( mysql )
{
#if MYSQL_VERSION_ID >= 40100
hb_retnl( ( long ) mysql_rollback( mysql ) );
#else
hb_retnl( ( long ) mysql_query( mysql, "ROLLBACK" ) );
#endif
}
else
hb_errRT_BASE( EG_ARG, 2020, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( MYSQL_SELECT_DB ) /* int mysql_select_db( MYSQL *, char * ) */
{
MYSQL * mysql = hb_MYSQL_par( 1 );
if( mysql )
hb_retnl( ( long ) mysql_select_db( mysql, ( const char * ) hb_parc( 2 ) ) );
else
hb_errRT_BASE( EG_ARG, 2020, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( MYSQL_QUERY ) /* int mysql_query( MYSQL *, char * ) */
{
MYSQL * mysql = hb_MYSQL_par( 1 );
if( mysql )
hb_retnl( ( long ) mysql_query( mysql, hb_parc( 2 ) ) );
else
hb_errRT_BASE( EG_ARG, 2020, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( MYSQL_STORE_RESULT ) /* MYSQL_RES * mysql_store_result( MYSQL * ) */
{
MYSQL * mysql = hb_MYSQL_par( 1 );
if( mysql )
hb_MYSQL_RES_ret( mysql_store_result( mysql ) );
else
hb_errRT_BASE( EG_ARG, 2020, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( MYSQL_USE_RESULT ) /* MYSQL_RES * mysql_use_result( MYSQL * ) */
{
MYSQL * mysql = hb_MYSQL_par( 1 );
if( mysql )
hb_MYSQL_RES_ret( mysql_use_result( mysql ) );
else
hb_errRT_BASE( EG_ARG, 2020, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
#if defined( HB_LEGACY_LEVEL3 )
/* NOTE: Deprecated */
HB_FUNC( MYSQL_FREE_RESULT ) /* void mysql_free_result( MYSQL_RES * ) */
{
void ** ph = ( void ** ) hb_parptrGC( &s_gcMYSQL_RESFuncs, 1 );
/* Check if pointer is not NULL to avoid multiple freeing */
if( ph && * ph )
{
/* Destroy the object */
mysql_free_result( ( MYSQL_RES * ) * ph );
/* set pointer to NULL to avoid multiple freeing */
* ph = NULL;
}
}
#endif
HB_FUNC( MYSQL_FETCH_ROW ) /* MYSQL_ROW * mysql_fetch_row( MYSQL_RES * ) */
{
MYSQL_RES * mresult = hb_MYSQL_RES_par( 1 );
if( mresult )
{
unsigned int num_fields = mysql_num_fields( mresult );
PHB_ITEM aRow = hb_itemArrayNew( num_fields );
MYSQL_ROW mrow = mysql_fetch_row( mresult );
if( mrow )
{
unsigned long * lengths = mysql_fetch_lengths( mresult );
unsigned int i;
for( i = 0; i < num_fields; ++i )
hb_arraySetCL( aRow, i + 1, mrow[ i ], lengths[ i ] );
}
hb_itemReturnRelease( aRow );
}
}
HB_FUNC( MYSQL_DATA_SEEK ) /* void mysql_data_seek( MYSQL_RES *, unsigned int ) */
{
MYSQL_RES * mresult = hb_MYSQL_RES_par( 1 );
if( mresult )
mysql_data_seek( mresult, ( unsigned int ) hb_parni( 2 ) );
else
hb_errRT_BASE( EG_ARG, 2020, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( MYSQL_NUM_ROWS ) /* my_ulongulong mysql_num_rows( MYSQL_RES * ) */
{
MYSQL_RES * mresult = hb_MYSQL_RES_par( 1 );
if( mresult )
hb_retnint( mysql_num_rows( ( mresult ) ) );
else
hb_errRT_BASE( EG_ARG, 2020, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( MYSQL_FETCH_FIELD ) /* MYSQL_FIELD * mysql_fetch_field( MYSQL_RES * ) */
{
MYSQL_RES * mresult = hb_MYSQL_RES_par( 1 );
if( mresult )
{
/* NOTE: field structure of MySQL has 8 members as of MySQL 3.22.x */
PHB_ITEM aField = hb_itemArrayNew( 8 );
MYSQL_FIELD * mfield = mysql_fetch_field( mresult );
if( mfield )
{
hb_arraySetC( aField, 1, mfield->name );
hb_arraySetC( aField, 2, mfield->table );
hb_arraySetC( aField, 3, mfield->def );
hb_arraySetNL( aField, 4, ( long ) mfield->type );
hb_arraySetNL( aField, 5, mfield->length );
hb_arraySetNL( aField, 6, mfield->max_length );
hb_arraySetNL( aField, 7, mfield->flags );
hb_arraySetNL( aField, 8, mfield->decimals );
}
hb_itemReturnRelease( aField );
}
else
hb_errRT_BASE( EG_ARG, 2020, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( MYSQL_FIELD_SEEK ) /* MYSQL_FIELD_OFFSET mysql_field_seek( MYSQL_RES *, MYSQL_FIELD_OFFSET ) */
{
MYSQL_RES * mresult = hb_MYSQL_RES_par( 1 );
if( mresult )
mysql_field_seek( mresult, ( MYSQL_FIELD_OFFSET ) hb_parni( 2 ) );
else
hb_errRT_BASE( EG_ARG, 2020, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( MYSQL_NUM_FIELDS ) /* unsigned int mysql_num_fields( MYSQL_RES * ) */
{
MYSQL_RES * mresult = hb_MYSQL_RES_par( 1 );
if( mresult )
hb_retnl( mysql_num_fields( ( mresult ) ) );
else
hb_errRT_BASE( EG_ARG, 2020, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( MYSQL_FIELD_COUNT ) /* unsigned int mysql_field_count( MYSQL * ) */
{
MYSQL * mysql = hb_MYSQL_par( 1 );
if( mysql )
{
#if MYSQL_VERSION_ID > 32200
hb_retnl( mysql_field_count( ( mysql ) ) );
#else
hb_retnl( 0 );
#endif
}
else
hb_errRT_BASE( EG_ARG, 2020, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( MYSQL_LIST_FIELDS ) /* MYSQL_RES * mysql_list_fields( MYSQL *, char * ); */
{
MYSQL * mysql = hb_MYSQL_par( 1 );
if( mysql )
hb_MYSQL_RES_ret( mysql_list_fields( mysql, hb_parc( 2 ), NULL ) );
else
hb_errRT_BASE( EG_ARG, 2020, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( MYSQL_ERROR ) /* char * mysql_error( MYSQL * ); */
{
MYSQL * mysql = hb_MYSQL_par( 1 );
if( mysql )
hb_retc( mysql_error( mysql ) );
else
hb_errRT_BASE( EG_ARG, 2020, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( MYSQL_LIST_DBS ) /* MYSQL_RES * mysql_list_dbs( MYSQL *, char * wild ); */
{
MYSQL * mysql = hb_MYSQL_par( 1 );
if( mysql )
{
MYSQL_RES * mresult = mysql_list_dbs( mysql, NULL );
HB_SIZE nr = ( HB_SIZE ) mysql_num_rows( mresult );
PHB_ITEM aDBs = hb_itemArrayNew( nr );
HB_SIZE i;
for( i = 0; i < nr; ++i )
{
MYSQL_ROW mrow = mysql_fetch_row( mresult );
hb_arraySetC( aDBs, i + 1, mrow[ 0 ] );
}
mysql_free_result( mresult );
hb_itemReturnRelease( aDBs );
}
else
hb_errRT_BASE( EG_ARG, 2020, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( MYSQL_LIST_TABLES ) /* MYSQL_RES * mysql_list_tables( MYSQL *, char * wild ); */
{
MYSQL * mysql = hb_MYSQL_par( 1 );
if( mysql )
{
const char * cWild = hb_parc( 2 );
MYSQL_RES * mresult = mysql_list_tables( mysql, cWild );
long nr = ( long ) mysql_num_rows( mresult );
PHB_ITEM aTables = hb_itemArrayNew( nr );
long i;
for( i = 0; i < nr; ++i )
{
MYSQL_ROW mrow = mysql_fetch_row( mresult );
hb_arraySetC( aTables, i + 1, mrow[ 0 ] );
}
mysql_free_result( mresult );
hb_itemReturnRelease( aTables );
}
else
hb_errRT_BASE( EG_ARG, 2020, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( MYSQL_AFFECTED_ROWS )
{
MYSQL * mysql = hb_MYSQL_par( 1 );
if( mysql )
hb_retnl( ( long ) mysql_affected_rows( mysql ) );
else
hb_errRT_BASE( EG_ARG, 2020, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( MYSQL_GET_HOST_INFO )
{
MYSQL * mysql = hb_MYSQL_par( 1 );
if( mysql )
hb_retc( mysql_get_host_info( mysql ) );
else
hb_errRT_BASE( EG_ARG, 2020, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( MYSQL_GET_SERVER_INFO )
{
MYSQL * mysql = hb_MYSQL_par( 1 );
if( mysql )
hb_retc( mysql_get_server_info( mysql ) );
else
hb_errRT_BASE( EG_ARG, 2020, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( MYSQL_INSERT_ID )
{
MYSQL * mysql = hb_MYSQL_par( 1 );
if( mysql )
hb_retnint( mysql_insert_id( mysql ) );
else
hb_errRT_BASE( EG_ARG, 2020, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( MYSQL_REAL_ESCAPE_STRING ) /* unsigned long STDCALL mysql_real_escape_string( MYSQL * mysql, char * to, const char * from, unsigned long length ); */
{
MYSQL * mysql = hb_MYSQL_par( 1 );
if( mysql )
{
const char * from = hb_parcx( 1 );
unsigned long nSize = ( unsigned long ) hb_parclen( 1 );
char * buffer = ( char * ) hb_xgrab( nSize * 2 + 1 );
nSize = mysql_real_escape_string( mysql, buffer, from, nSize );
hb_retclen_buffer( ( char * ) buffer, nSize );
}
else
hb_errRT_BASE( EG_ARG, 2020, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
HB_FUNC( MYSQL_ESCAPE_STRING )
{
const char * from = hb_parcx( 1 );
unsigned long nSize = ( unsigned long ) hb_parclen( 1 );
char * buffer = ( char * ) hb_xgrab( nSize * 2 + 1 );
nSize = mysql_escape_string( buffer, from, nSize );
hb_retclen_buffer( ( char * ) buffer, nSize );
}
static char * filetoBuff( const char * fname, unsigned long * size )
{
char * buffer = NULL;
HB_FHANDLE handle = hb_fsOpen( fname, FO_READWRITE );
if( handle != FS_ERROR )
{
*size = hb_fsSeek( handle, 0, FS_END );
hb_fsSeek( handle, 0, FS_SET );
buffer = ( char * ) hb_xgrab( *size + 1 );
*size = ( unsigned long ) hb_fsReadLarge( handle, buffer, *size );
buffer[ *size ] = '\0';
hb_fsClose( handle );
}
else
*size = 0;
return buffer;
}
HB_FUNC( MYSQL_ESCAPE_STRING_FROM_FILE )
{
unsigned long nSize;
char * from = filetoBuff( hb_parc( 1 ), &nSize );
if( from )
{
char * buffer = ( char * ) hb_xgrab( nSize * 2 + 1 );
nSize = mysql_escape_string( buffer, from, nSize );
hb_retclen_buffer( buffer, nSize );
hb_xfree( from );
}
}