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

Function main

examples/interfaces/04.print_table.cpp:48–174  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

46};
47
48int main()
49{
50 int rc = 0;
51 char s[100];
52
53 setenv("ISC_USER", "sysdba", 0);
54 setenv("ISC_PASSWORD", "masterkey", 0);
55
56 ThrowStatusWrapper status(master->getStatus());
57 IProvider* prov = master->getDispatcher();
58
59 IAttachment* att = NULL;
60 ITransaction* tra = NULL;
61 IResultSet* curs = NULL;
62 IMessageMetadata* meta = NULL;
63
64 try
65 {
66 att = prov->attachDatabase(&status, "employee", 0, NULL);
67 tra = att->startTransaction(&status, 0, NULL);
68
69 // If we are not going to run same SELECT query many times we may do not prepare it,
70 // opening cursor instead with single API call.
71 // If statement has input parameters and we know them, appropriate IMetadata may be
72 // constructed and passed to openCursor() together with data buffer.
73 // We also may provide out format info and coerce data passing appropriate metadata
74 // into API call.
75 // In this sample we have no input parameters and do not coerce anything - just
76 // print what we get from SQL query.
77 const char* sql = "select * from rdb$relations where RDB$RELATION_ID < 3 "
78 "or RDB$VIEW_SOURCE is not null";
79
80 // Do not use IStatement - just ask attachment to open cursor
81 curs = att->openCursor(&status, tra, 0, sql, SAMPLES_DIALECT, NULL, NULL, NULL, NULL, 0);
82 meta = curs->getMetadata(&status);
83 unsigned cols = meta->getCount(&status);
84
85 MyField* fields = new MyField[cols];
86 memset(fields, 0, sizeof(MyField) * cols);
87
88 unsigned f = 0;
89 for (unsigned j = 0; j < cols; ++j)
90 {
91 unsigned t = meta->getType(&status, j) & ~1;
92 unsigned sub = meta->getSubType(&status, j);
93
94 switch (t)
95 {
96 case SQL_BLOB:
97 if (sub != 1)
98 continue;
99 break;
100
101 case SQL_TEXT:
102 case SQL_VARYING:
103 case SQL_SHORT:
104 case SQL_DOUBLE:
105 break;

Callers

nothing calls this directly

Calls 15

setenvFunction · 0.85
fflushFunction · 0.85
getStatusMethod · 0.45
getDispatcherMethod · 0.45
attachDatabaseMethod · 0.45
startTransactionMethod · 0.45
openCursorMethod · 0.45
getMetadataMethod · 0.45
getCountMethod · 0.45
getTypeMethod · 0.45
getSubTypeMethod · 0.45
getFieldMethod · 0.45

Tested by

no test coverage detected