Sybase Technical Library - Product Manuals Home
[Search Forms] [Previous Section with Hits] [Next Section with Hits] [Clear Search] Expand Search

Using bit fields [Table of Contents] DBTools functions

[-] Chapter 3: The Database Tools Interface
[-] Using the database tools interface
[-] A DBTools example


A DBTools example

The following program illustrates the use of the DBTools library in the context of a backup program:

#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, str );
  fprintf( stdout, "\n" );
  fflush( stdout );
 }
 return 0;
}


extern short _callback StatusCallBack( char far * str )
{
 if( str != NULL ) {
  fprintf( stdout, str );
  fprintf( stdout, "\n" );
  fflush( stdout );
 }
 return 0;
}


extern short _callback ErrorCallBack( char far * str )
{
 if( str != NULL ) {
  fprintf( stdout, 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;
 char  dir_name[ _MAX_PATH + 1];
 char  connect[ 256 ];
 short  ret;
 HINSTANCE  hinst;
 FARPROC  proc_addr;


 // 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_NUMBER;
 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, "UID=dba;PWD=sql;DBN=asademo" );
 }
 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( "dbtl50t.dll" );
 if( hinst == NULL ) {
  // Failed
  return 0;
 }


 proc_addr = GetProcAddress( (HMODULE)hinst,
  "_DBBackup@4" );


 (*proc_addr)( &backup_info );
 FreeLibrary( hinst );
 return 0;
}


Using bit fields [Table of Contents] DBTools functions