全て クラス 名前空間 関数 変数 型定義 列挙型 列挙値 ページ
レコードの削除

標準APIを使ったサンプル

#include <stdio.h>
#include <bzs/db/protocol/tdap/client/database.h>
#include <bzs/db/protocol/tdap/client/table.h>
#include <bzs/db/protocol/tdap/client/dbDef.h>
using namespace bzs::db::protocol::tdap::client;
using namespace bzs::db::protocol::tdap;
/**
@brief read and delete example
This program deletes one record of a "user" table.
Please execute "create database" , "change schema" and "insert records" example
before execute this example.
*/
static const short fieldnum_id = 0;
static const short fieldnum_name = 1;
static const short fieldnum_group = 2;
static const short fieldnum_tel = 3;
static const char_td keynum_id = 0;
/** show database operation error
*/
void showError(const _TCHAR* caption, const _TCHAR* tableName, short statusCode)
{
_TCHAR tmp[1024] = { 0x00 };
nstable::tdapErr(0x00, statusCode, tableName, tmp);
_tprintf(_T("[ERROR] %s No.%ld %s\n"), caption, statusCode, tmp);
}
bool deleteUser(table* tb)
{
tb->clearBuffer();
tb->setKeyNum(keynum_id); // use id key
tb->setFV(fieldnum_id, 3); // id=3 satoshi
tb->seek();
if (tb->stat() == 0)
tb->del();
if (tb->stat() != 0)
showError(_T("update user"), tb->tableDef()->tableName(), tb->stat());
return (tb->stat() == 0);
}
/** Open database
*/
bool openDatabase(database* db, const _TCHAR* uri)
{
/******************************************************
!!! Important !!!
When using a multi-threaded,
please request a new connection for each database.
*******************************************************/
// When using a multi-threaded, set to true.
bool newConnection = false;
if (!db->connect(uri, newConnection))
{
showError(_T("connect daatabase"), NULL, db->stat());
return false;
}
db->open(uri, TYPE_SCHEMA_BDF);
if (db->stat() != 0)
{
showError(_T("open daatabase"), NULL, db->stat());
return false;
}
return true;
}
#pragma argsused
int _tmain(int argc, _TCHAR* argv[])
{
int result = 0;
static const _TCHAR* uri = _T("tdap://localhost/test?dbfile=test.bdf");
if (openDatabase(db, uri))
{
table* tbu = db->openTable(_T("user"));
if (db->stat() != 0)
showError(_T("open user table"), NULL, db->stat());
else
{
if (deleteUser(tbu))
_tprintf(_T("Delete records success. \n"));
tbu->release();
}
db->close();
}
return result;
}

コンビニエンスAPIを使ったサンプル

#include <bzs/db/protocol/tdap/client/trdboostapi.h>
#include <iostream>
using namespace bzs::db::protocol::tdap::client;
using namespace bzs::db::protocol::tdap;
/**
@brief read and delete example
This program deletes one record of a "user" table.
Please execute "create database" , "change schema" and "insert records" example
before execute this example.
*/
static const short fieldnum_id = 0;
static const char_td keynum_id = 0;
void deleteUser(table_ptr tb)
{
// Seek record that user id = 3 "satoshi"
indexIterator it = readIndex_v(tb, eSeekEqual, keynum_id, 3);
if (!it.isEnd())
deleteRecord(it); // delete id = 3
else
THROW_BZS_ERROR_WITH_MSG(_T("User id = 3 was not found"));
}
#pragma argsused
int _tmain(int argc, _TCHAR* argv[])
{
try
{
connectParams param(_T("tdap"), _T("localhost"), _T("test"),
_T("test"));
/******************************************************
!!! Important !!!
When using a multi-threaded,
please request a new connection for each database.
*******************************************************/
// When using a multi-threaded, set to true.
bool newConnection = false;
connectOpen(db, param, newConnection);
table_ptr tb = openTable(db, _T("user"));
deleteUser(tb);
std::cout << "Delete records success." << std::endl;
return 0;
}
catch (bzs::rtl::exception& e)
{
std::tcout << _T("[ERROR] ") << *bzs::rtl::getMsg(e) << std::endl;
}
return 1;
}

Transactd SDK 2018年07月31日(火) 19時40分25秒 doxygen