Contents Index Using bit fields DBTools functions

ASA Programming Guide
  The Database Tools Interface
    Using the database tools interface

A DBTools example


You can find this sample and instructions for compiling it in the Samples\ASA\DBTools subdirectory of your SQL Anywhere directory. The sample program itself is Samples\ASA\DBTools\main.c. The sample illustrates how to use the DBTools library to carry out a backup of a database.

# define WINNT

#include <stdio.h>
#include "windows.h"
#include "string.h"
#include "dbtools.h"
extern short _callback ConfirmCallBack(char far * str){
   if( MessageBox( NULL, str, "Backup",
       MB_YESNO|MB_ICONQUESTION ) == IDYES ) {
      return 1;
   }
   return 0;
}
extern short _callback MessageCallBack( char far * str){
   if( str != NULL ) {
      fprintf( stdout, "%s", str );
      fprintf( stdout, "\n" );
      fflush( stdout );
   }
   return 0;
}
extern short _callback StatusCallBack( char far * str ){
   if( str != NULL ) {
      fprintf( stdout, "%s", str );
      fprintf( stdout, "\n" );
      fflush( stdout );
   }
   return 0;
}
extern short _callback ErrorCallBack( char far * str ){
   if( str != NULL ) {
      fprintf( stdout, "%s", str );
      fprintf( stdout, "\n" );
      fflush( stdout );
   }
   return 0;
}
// Main entry point into the program.
int main( int argc, char * argv[] ){
   a_backup_db      backup_info;
   a_dbtools_info   dbtinfo;
   char         dir_name[ _MAX_PATH + 1];
   char         connect[ 256 ];
   HINSTANCE      hinst;
   FARPROC         dbbackup;
   FARPROC         dbtoolsinit;
   FARPROC         dbtoolsfini;
   // Always initialize to 0 so new versions
   //of the structure will be compatible.
   memset( &backup_info, 0, sizeof( a_backup_db ) );
   backup_info.version = DB_TOOLS_VERSION_9_0_00;
   backup_info.quiet = 0;
   backup_info.no_confirm = 0;
   backup_info.confirmrtn =
                        (MSG_CALLBACK)ConfirmCallBack;
   backup_info.errorrtn = (MSG_CALLBACK)ErrorCallBack;
   backup_info.msgrtn = (MSG_CALLBACK)MessageCallBack;
   backup_info.statusrtn = (MSG_CALLBACK)StatusCallBack;
   if( argc > 1 ) {
      strncpy( dir_name, argv[1], _MAX_PATH );
   } else {
      // DBTools does not expect (or like) the
      // trailing slash
      strcpy( dir_name, "c:\\temp" );
   }
   backup_info.output_dir = dir_name;
   if( argc > 2 ) {
      strncpy( connect, argv[2], 255 );
   } else {
      // Assume that the engine is already running.
      strcpy( connect, "DSN=ASA 9.0 Sample" );
   }
   backup_info.connectparms = connect;
   backup_info.startline = "";
   backup_info.quiet = 0;
   backup_info.no_confirm = 0;
   backup_info.backup_database = 1;
   backup_info.backup_logfile = 1;
   backup_info.backup_writefile = 1;
   backup_info.rename_log = 0;
   backup_info.truncate_log = 0;
   hinst = LoadLibrary( "dbtool9.dll" );
   if( hinst == NULL ) {
      // Failed
      return 0;
   }
 dbtinfo.errorrtn = (MSG_CALLBACK)ErrorCallBack;
   dbbackup = GetProcAddress( (HMODULE)hinst,
      "_DBBackup@4" );
   dbtoolsinit = GetProcAddress( (HMODULE)hinst,
      "_DBToolsInit@4" );
   dbtoolsfini = GetProcAddress( (HMODULE)hinst,
      "_DBToolsFini@4" );
   (*dbtoolsinit)( &dbtinfo );
   (*dbbackup)( &backup_info );
   (*dbtoolsfini)( &dbtinfo );
   FreeLibrary( hinst );
   return 0;
}

Contents Index Using bit fields DBTools functions