mirror of
https://github.com/FirebirdSQL/firebird.git
synced 2025-01-22 15:23:03 +01:00
Updated samples, added sample 6
This commit is contained in:
parent
43fc0e3f10
commit
1c548a533c
@ -95,7 +95,7 @@ int main()
|
||||
tra = att->startTransaction(&status, 0, NULL);
|
||||
|
||||
// create table
|
||||
att->execute(&status, tra, 0, "create table dates_table (d1 date)", 3,
|
||||
att->execute(&status, tra, 0, "create table dates_table (d1 date)", SAMPLES_DIALECT,
|
||||
NULL, NULL, NULL, NULL); // Input parameters and output data not used
|
||||
|
||||
// commit transaction retaining
|
||||
@ -103,7 +103,7 @@ int main()
|
||||
printf("Table dates_table created\n");
|
||||
|
||||
// insert a record into dates_table
|
||||
att->execute(&status, tra, 0, "insert into dates_table values (CURRENT_DATE)", 3,
|
||||
att->execute(&status, tra, 0, "insert into dates_table values (CURRENT_DATE)", SAMPLES_DIALECT,
|
||||
NULL, NULL, NULL, NULL); // Input parameters and output data not used
|
||||
|
||||
// commit transaction (will close interface)
|
||||
|
@ -84,7 +84,7 @@ int main()
|
||||
tra = att->startTransaction(&status, 0, NULL);
|
||||
|
||||
// prepare statement
|
||||
stmt = att->prepare(&status, tra, 0, updstr, 3, 0);
|
||||
stmt = att->prepare(&status, tra, 0, updstr, SAMPLES_DIALECT, 0);
|
||||
|
||||
// build metadata
|
||||
// IMaster creates empty new metadata in builder
|
||||
|
@ -70,7 +70,7 @@ int main()
|
||||
// prepare statement
|
||||
stmt = att->prepare(&status, tra, 0, "select last_name, first_name, phone_ext from phone_list "
|
||||
"where location = 'Monterey' order by last_name, first_name",
|
||||
3, IStatement::PREPARE_PREFETCH_METADATA);
|
||||
SAMPLES_DIALECT, IStatement::PREPARE_PREFETCH_METADATA);
|
||||
|
||||
// get list of columns
|
||||
meta = stmt->getOutputMetadata(&status);
|
||||
|
@ -78,7 +78,7 @@ int main()
|
||||
"or RDB$VIEW_SOURCE is not null";
|
||||
|
||||
// Do not use IStatement - just ask attachment to open cursor
|
||||
curs = att->openCursor(&status, tra, 0, sql, 3, NULL, NULL, NULL, NULL, 0);
|
||||
curs = att->openCursor(&status, tra, 0, sql, SAMPLES_DIALECT, NULL, NULL, NULL, NULL, 0);
|
||||
meta = curs->getMetadata(&status);
|
||||
unsigned cols = meta->getCount(&status);
|
||||
|
||||
|
@ -222,7 +222,8 @@ int main()
|
||||
tra = att->startTransaction(&status, 0, NULL);
|
||||
|
||||
// open cursor
|
||||
curs = att->openCursor(&status, tra, 0, "select current_user from rdb$database", 3, NULL, NULL, meta, NULL, 0);
|
||||
curs = att->openCursor(&status, tra, 0, "select current_user from rdb$database",
|
||||
SAMPLES_DIALECT, NULL, NULL, meta, NULL, 0);
|
||||
|
||||
// fetch record from cursor and print it
|
||||
curs->fetchNext(&status, buffer);
|
||||
|
128
examples/interfaces/06.fb_message.cpp
Normal file
128
examples/interfaces/06.fb_message.cpp
Normal file
@ -0,0 +1,128 @@
|
||||
/*
|
||||
* PROGRAM: Object oriented API samples.
|
||||
* MODULE: 06.fb_message.cpp
|
||||
* DESCRIPTION: A sample of using static messages.
|
||||
* Prints user-defined tables with comments.
|
||||
*
|
||||
* Example for the following macro:
|
||||
*
|
||||
* FB_MESSAGE - defines static messages
|
||||
* C++ specific sample!
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Adriano dos Santos Fernandes.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2011 the Initial Developer.
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Alexander Peshkov
|
||||
*
|
||||
*/
|
||||
|
||||
#include "ifaceExamples.h"
|
||||
#include <firebird/Message.h>
|
||||
|
||||
static IMaster* master = fb_get_master_interface();
|
||||
|
||||
int main()
|
||||
{
|
||||
int rc = 0;
|
||||
|
||||
setenv("ISC_USER", "sysdba", 0);
|
||||
setenv("ISC_PASSWORD", "masterkey", 0);
|
||||
|
||||
ThrowStatusWrapper status(master->getStatus());
|
||||
IProvider* prov = master->getDispatcher();
|
||||
|
||||
IAttachment* att = NULL;
|
||||
ITransaction* tra = NULL;
|
||||
IResultSet* rs = NULL;
|
||||
|
||||
const char* dbName = "employee";
|
||||
|
||||
try
|
||||
{
|
||||
att = prov->attachDatabase(&status, dbName, 0, NULL);
|
||||
tra = att->startTransaction(&status, 0, NULL);
|
||||
|
||||
// Comment some tables
|
||||
att->execute(&status, tra, 0, "comment on table employee is 'Employees'",
|
||||
SAMPLES_DIALECT, NULL, NULL, NULL, NULL);
|
||||
att->execute(&status, tra, 0, "comment on table customer is 'Customers'",
|
||||
SAMPLES_DIALECT, NULL, NULL, NULL, NULL);
|
||||
att->execute(&status, tra, 0, "comment on table country is 'Countries and national currencies'",
|
||||
SAMPLES_DIALECT, NULL, NULL, NULL, NULL);
|
||||
tra->commitRetaining(&status);
|
||||
|
||||
// Print tables list
|
||||
FB_MESSAGE(Input, ThrowStatusWrapper,
|
||||
(FB_INTEGER, systemFlag)
|
||||
) input(&status, master);
|
||||
|
||||
FB_MESSAGE(Output, ThrowStatusWrapper,
|
||||
(FB_SMALLINT, relationId)
|
||||
(FB_VARCHAR(31), relationName)
|
||||
(FB_VARCHAR(100), description)
|
||||
) output(&status, master);
|
||||
|
||||
input.clear();
|
||||
input->systemFlag = 0;
|
||||
|
||||
rs = att->openCursor(&status, tra, 0,
|
||||
"select rdb$relation_id, rdb$relation_name, rdb$description"
|
||||
" from rdb$relations"
|
||||
" where rdb$system_flag = ?"
|
||||
" order by rdb$relation_id",
|
||||
SAMPLES_DIALECT, input.getMetadata(), input.getData(), output.getMetadata(), NULL, 0);
|
||||
|
||||
printf(" ID Name/comment\n");
|
||||
while (rs->fetchNext(&status, output.getData()) == IStatus::RESULT_OK)
|
||||
{
|
||||
unsigned lRelName = output->relationNameNull ? 0 : output->relationName.length;
|
||||
unsigned lDesc = output->descriptionNull ? 0 : output->description.length;
|
||||
printf("%4d %*.*s%c%*.*s\n", output->relationId,
|
||||
lRelName, lRelName, output->relationName.str,
|
||||
lDesc ? '/' : ' ',
|
||||
lDesc, lDesc, output->description.str);
|
||||
}
|
||||
|
||||
rs->close(&status);
|
||||
rs = NULL;
|
||||
|
||||
tra->commit(&status);
|
||||
tra = NULL;
|
||||
|
||||
att->detach(&status);
|
||||
att = NULL;
|
||||
}
|
||||
catch (const FbException& error)
|
||||
{
|
||||
// handle error
|
||||
rc = 1;
|
||||
|
||||
char buf[256];
|
||||
master->getUtilInterface()->formatStatus(buf, sizeof(buf), error.getStatus());
|
||||
fprintf(stderr, "%s\n", buf);
|
||||
}
|
||||
|
||||
// release interfaces after error caught
|
||||
if (rs)
|
||||
rs->release();
|
||||
if (tra)
|
||||
tra->release();
|
||||
if (att)
|
||||
att->release();
|
||||
|
||||
// generic cleanup
|
||||
prov->release();
|
||||
status.dispose();
|
||||
}
|
@ -47,3 +47,5 @@ typedef int FbSampleAtomic;
|
||||
#endif
|
||||
|
||||
using namespace Firebird;
|
||||
|
||||
#define SAMPLES_DIALECT SQL_DIALECT_V6
|
||||
|
Loading…
Reference in New Issue
Block a user