| 46 | }; |
| 47 | |
| 48 | int 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; |
nothing calls this directly
no test coverage detected