| 41 | static char *insert_date = "INSERT INTO dbinfo VALUES ('NOW')"; |
| 42 | |
| 43 | int main (int argc, char** argv) |
| 44 | { |
| 45 | isc_db_handle newdb = NULL; /* database handle */ |
| 46 | isc_tr_handle trans = NULL; /* transaction handle */ |
| 47 | ISC_STATUS_ARRAY status; /* status vector */ |
| 48 | long sqlcode; /* SQLCODE */ |
| 49 | char create_db[160]; /* 'create database' statement */ |
| 50 | char new_dbname[128]; |
| 51 | |
| 52 | if (argc > 1) |
| 53 | strcpy(new_dbname, argv[1]); |
| 54 | else |
| 55 | strcpy(new_dbname, "new.fdb"); |
| 56 | |
| 57 | /* |
| 58 | * Construct a 'create database' statement. |
| 59 | * The database name could have been passed as a parameter. |
| 60 | */ |
| 61 | sprintf(create_db, "CREATE DATABASE '%s'", new_dbname); |
| 62 | |
| 63 | /* |
| 64 | * Create a new database. |
| 65 | * The database handle is zero. |
| 66 | */ |
| 67 | |
| 68 | if (isc_dsql_execute_immediate(status, &newdb, &trans, 0, create_db, 1, |
| 69 | NULL)) |
| 70 | { |
| 71 | /* Extract SQLCODE from the status vector. */ |
| 72 | sqlcode = isc_sqlcode(status); |
| 73 | |
| 74 | /* Print a descriptive message based on the SQLCODE. */ |
| 75 | if (sqlcode == -902) |
| 76 | { |
| 77 | printf("\nDatabase already exists.\n"); |
| 78 | printf("Remove %s before running this program.\n\n", new_dbname); |
| 79 | } |
| 80 | |
| 81 | /* In addition, print a standard error message. */ |
| 82 | if (pr_error(status, "create database")) |
| 83 | return 1; |
| 84 | } |
| 85 | |
| 86 | isc_commit_transaction(status, &trans); |
| 87 | printf("Created database '%s'.\n\n", new_dbname); |
| 88 | |
| 89 | /* |
| 90 | * Connect to the new database and create a sample table. |
| 91 | */ |
| 92 | |
| 93 | /* newdb will be set to null on success */ |
| 94 | isc_detach_database(status, &newdb); |
| 95 | |
| 96 | if (isc_attach_database(status, 0, new_dbname, &newdb, 0, NULL)) |
| 97 | if (pr_error(status, "attach database")) |
| 98 | return 1; |
| 99 | |
| 100 |
nothing calls this directly
no test coverage detected