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

Function main

examples/interfaces/02.update.cpp:50–192  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

48int Input_ptr = 0;
49
50int main()
51{
52 int rc = 0;
53
54 // set default password if none specified in environment
55 setenv("ISC_USER", "sysdba", 0);
56 setenv("ISC_PASSWORD", "masterkey", 0);
57
58 // status vector and main dispatcher
59 ThrowStatusWrapper status(master->getStatus());
60 IProvider* prov = master->getDispatcher();
61
62 // declare pointers to required interfaces
63 IAttachment* att = NULL;
64 ITransaction* tra = NULL;
65
66 // Interface executes prepared SQL statement
67 IStatement* stmt = NULL;
68
69 // Interfaces provides access to format of data in messages
70 IMessageMetadata* meta = NULL;
71
72 // Interface makes it possible to change format of data or define it yourself
73 IMetadataBuilder* builder = NULL;
74
75 const char* updstr =
76 "UPDATE department SET budget = ? * budget + budget WHERE dept_no = ?";
77
78 try
79 {
80 // attach employee db
81 att = prov->attachDatabase(&status, "employee", 0, NULL);
82
83 // start transaction
84 tra = att->startTransaction(&status, 0, NULL);
85
86 // prepare statement
87 stmt = att->prepare(&status, tra, 0, updstr, SAMPLES_DIALECT, 0);
88
89 // build metadata
90 // IMaster creates empty new metadata in builder
91 builder = master->getMetadataBuilder(&status, 2);
92 // set required info on fields
93 builder->setType(&status, 0, SQL_DOUBLE + 1);
94 builder->setType(&status, 1, SQL_TEXT + 1);
95 builder->setLength(&status, 1, 3);
96 // IMetadata should be ready
97 meta = builder->getMetadata(&status);
98 // no need in builder any more
99 builder->release();
100 builder = NULL;
101
102 // allocate buffer on stack
103 char buffer[256];
104 unsigned len = meta->getMessageLength(&status);
105 if (len > sizeof(buffer))
106 {
107 throw "Input message length too big - can't continue";

Callers

nothing calls this directly

Calls 15

setenvFunction · 0.85
get_inputFunction · 0.70
getStatusMethod · 0.45
getDispatcherMethod · 0.45
attachDatabaseMethod · 0.45
startTransactionMethod · 0.45
prepareMethod · 0.45
getMetadataBuilderMethod · 0.45
setTypeMethod · 0.45
setLengthMethod · 0.45
getMetadataMethod · 0.45
releaseMethod · 0.45

Tested by

no test coverage detected