MCPcopy Create free account
hub / github.com/FirebirdSQL/firebird / main

Function main

examples/interfaces/01.create.cpp:46–140  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

44static IMaster* master = fb_get_master_interface();
45
46int main()
47{
48 int rc = 0;
49
50 // Declare pointers to required interfaces
51 // IStatus is used to return wide error description to user
52 // IProvider is needed to start to work with database (or service)
53 // Status vector, main dispatcher and utility interfaces are returned by IMaster functions
54 // No error return may happen - these functions always succeed
55 IStatus* st = master->getStatus();
56 IProvider* prov = master->getDispatcher();
57 IUtil* utl = master->getUtilInterface();
58
59 // IAttachment and ITransaction contain methods to work with database attachment
60 // and transactions
61 IAttachment* att = NULL;
62 ITransaction* tra = NULL;
63
64 // IXpbBuilder is used to access various parameters blocks used in API
65 IXpbBuilder* dpb = NULL;
66
67 try
68 {
69 // Status wrapper - will be used later in all calls where status interface is needed
70 // With ThrowStatusWrapper passed as status interface FbException will be thrown on error
71 ThrowStatusWrapper status(st);
72
73 // create DPB - use non-default page size 4Kb
74 dpb = utl->getXpbBuilder(&status, IXpbBuilder::DPB, NULL, 0);
75 dpb->insertInt(&status, isc_dpb_page_size, 4 * 1024);
76 dpb->insertString(&status, isc_dpb_user_name, "sysdba");
77 dpb->insertString(&status, isc_dpb_password, "masterkey");
78
79 // create empty database
80 att = prov->createDatabase(&status, "fbtests.fdb", dpb->getBufferLength(&status),
81 dpb->getBuffer(&status));
82 printf("Database fbtests.fdb created\n");
83
84 // detach from database
85 att->detach(&status);
86 att = NULL;
87
88 // attach it once again
89 att = prov->attachDatabase(&status, "fbtests.fdb",
90 dpb->getBufferLength(&status), dpb->getBuffer(&status));
91 printf("Re-attached database fbtests.fdb\n");
92
93 // start transaction
94 tra = att->startTransaction(&status, 0, NULL);
95
96 // create table
97 att->execute(&status, tra, 0, "create table dates_table (d1 date)", SAMPLES_DIALECT,
98 NULL, NULL, NULL, NULL); // Input parameters and output data not used
99
100 // commit transaction retaining
101 tra->commitRetaining(&status);
102 printf("Table dates_table created\n");
103

Callers

nothing calls this directly

Calls 15

getStatusMethod · 0.45
getDispatcherMethod · 0.45
getUtilInterfaceMethod · 0.45
getXpbBuilderMethod · 0.45
insertIntMethod · 0.45
insertStringMethod · 0.45
createDatabaseMethod · 0.45
getBufferLengthMethod · 0.45
getBufferMethod · 0.45
detachMethod · 0.45
attachDatabaseMethod · 0.45
startTransactionMethod · 0.45

Tested by

no test coverage detected