community.borland.com

Article #25440: Ability to create a database using the API call

Problem:
In the V3.3 version of InterBase, the ability to
create a database using an explicit API function call existed.
However, in the V4.0 version, it's recommended to pass a
string containing the statement "CREATE DATABASE "foo.gdb";" as
one of the parameters to the API call "isc_dsql_execute_immediate().

This would be good except for the fact, that this call
supposedly sets any existing database handles to NULL.  So, if you
are working with any existing databases and also trying to create
brand new ones in your API application, you might set the existing
database handles to NULL.      


Solution:
You could use the API call "isc_create_database()". This
is defined in the /usr/interbase/include/ibase.h file to take in
seven parameters. The last parameter can be ignored, or set to 0.  
Given below is a screen capture of a working example.
=================================================================

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
        CREATE1.C
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#include 
#include "/usr/interbase/include/ibase.h"


main()
{
long status[20], *DB = NULL, *Trans = NULL;
char *s;

isc_create_database(status, 0, "mydb", &DB, 0, 0,0);

errchk(status);

exit(0);
}

errchk(status)
long *status;
{
if (status[0] == 1 && status[1])
   {
   isc_print_status(status);
   }
}
====================================================================
bigbird{amakaram}39: cc -o create1 create1.c -lgdslib -lgdsflib
bigbird{amakaram}40: create1
bigbird{amakaram}41: ls -al | grep mydb
-rw-r--r--  1 amakaram   205824 May  7 14:01 mydb
bigbird{amakaram}42: isql mydb
Database:  mydb
SQL> show tables;
There are no tables in this database
SQL>
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 

Last Modified: 26-OCT-00