File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2525#include " Attachment.h"
2626#include " Client.h"
2727#include " Exception.h"
28+ #include " Statement.h"
29+ #include " Transaction.h"
2830
2931using namespace fbcpp ;
3032using namespace fbcpp ::impl;
@@ -93,3 +95,14 @@ void Attachment::dropDatabase()
9395{
9496 disconnectOrDrop (true );
9597}
98+
99+ bool Attachment::execute (Transaction& transaction, std::string_view sql)
100+ {
101+ return execute (transaction, sql, StatementOptions{});
102+ }
103+
104+ bool Attachment::execute (Transaction& transaction, std::string_view sql, const StatementOptions& options)
105+ {
106+ Statement statement{*this , transaction, sql, options};
107+ return statement.execute (transaction);
108+ }
Original file line number Diff line number Diff line change 3131#include < memory>
3232#include < optional>
3333#include < string>
34+ #include < string_view>
3435#include < vector>
3536#include < cstddef>
3637
4142namespace fbcpp
4243{
4344 class Client ;
45+ class StatementOptions ;
46+ class Transaction ;
4447
4548 // /
4649 // / Represents options used when creating an Attachment object.
@@ -301,6 +304,16 @@ namespace fbcpp
301304 // /
302305 void dropDatabase ();
303306
307+ // /
308+ // / Prepares and executes an SQL statement using the supplied transaction.
309+ // /
310+ bool execute (Transaction& transaction, std::string_view sql);
311+
312+ // /
313+ // / Prepares and executes an SQL statement using the supplied transaction and statement options.
314+ // /
315+ bool execute (Transaction& transaction, std::string_view sql, const StatementOptions& options);
316+
304317 private:
305318 void disconnectOrDrop (bool drop);
306319
Original file line number Diff line number Diff line change @@ -92,6 +92,23 @@ BOOST_AUTO_TEST_CASE(createDatabaseWithForcedWritesOff)
9292 transaction.commit ();
9393}
9494
95+ BOOST_AUTO_TEST_CASE (executePreparesAndExecutesStatement)
96+ {
97+ const auto database = getTempFile (" Attachment-executePreparesAndExecutesStatement.fdb" );
98+ Attachment attachment{CLIENT , database, AttachmentOptions ().setCreateDatabase (true ).setForcedWrites (false )};
99+ FbDropDatabase attachmentDrop{attachment};
100+
101+ Transaction transaction{attachment};
102+ BOOST_CHECK (attachment.execute (transaction, " create table t (id integer not null primary key)" ));
103+ transaction.commitRetaining ();
104+
105+ BOOST_CHECK (attachment.execute (transaction, " insert into t (id) values (1)" ));
106+ BOOST_CHECK (attachment.execute (transaction, " select id from t" ));
107+ BOOST_CHECK (!attachment.execute (transaction, " select id from t where id = 2" ));
108+
109+ transaction.commit ();
110+ }
111+
95112BOOST_AUTO_TEST_CASE (isNotValidAfterMove)
96113{
97114 const auto database = getTempFile (" Attachment-isNotValidAfterMove.fdb" );
You can’t perform that action at this time.
0 commit comments