Permalink
Browse files

db, feat: add result to DbConnection.trans.

  • Loading branch information...
xicilion committed May 13, 2018
1 parent 428064a commit c6973ba11086f333cac6ae37d3056bbbdde03783
View
@@ -30,7 +30,7 @@ class SQLite : public SQLite_base {
virtual result_t begin(AsyncEvent* ac);
virtual result_t commit(AsyncEvent* ac);
virtual result_t rollback(AsyncEvent* ac);
virtual result_t trans(v8::Local<v8::Function> func);
virtual result_t trans(v8::Local<v8::Function> func, bool& retVal);
virtual result_t execute(exlib::string sql, OptArgs args, obj_ptr<NArray>& retVal, AsyncEvent* ac);
virtual result_t format(exlib::string sql, OptArgs args, exlib::string& retVal);
@@ -26,7 +26,7 @@ class DbConnection_base : public object_base {
virtual result_t begin(AsyncEvent* ac) = 0;
virtual result_t commit(AsyncEvent* ac) = 0;
virtual result_t rollback(AsyncEvent* ac) = 0;
virtual result_t trans(v8::Local<v8::Function> func) = 0;
virtual result_t trans(v8::Local<v8::Function> func, bool& retVal) = 0;
virtual result_t execute(exlib::string sql, OptArgs args, obj_ptr<NArray>& retVal, AsyncEvent* ac) = 0;
virtual result_t format(exlib::string sql, OptArgs args, exlib::string& retVal) = 0;
@@ -175,6 +175,8 @@ inline void DbConnection_base::s_rollback(const v8::FunctionCallbackInfo<v8::Val
inline void DbConnection_base::s_trans(const v8::FunctionCallbackInfo<v8::Value>& args)
{
bool vr;
METHOD_NAME("DbConnection.trans");
METHOD_INSTANCE(DbConnection_base);
METHOD_ENTER();
@@ -183,9 +185,9 @@ inline void DbConnection_base::s_trans(const v8::FunctionCallbackInfo<v8::Value>
ARG(v8::Local<v8::Function>, 0);
hr = pInst->trans(v0);
hr = pInst->trans(v0, vr);
METHOD_VOID();
METHOD_RETURN();
}
inline void DbConnection_base::s_execute(const v8::FunctionCallbackInfo<v8::Value>& args)
View
@@ -32,7 +32,7 @@ class mssql : public MSSQL_base {
virtual result_t begin(AsyncEvent* ac);
virtual result_t commit(AsyncEvent* ac);
virtual result_t rollback(AsyncEvent* ac);
virtual result_t trans(v8::Local<v8::Function> func);
virtual result_t trans(v8::Local<v8::Function> func, bool& retVal);
virtual result_t execute(exlib::string sql, OptArgs args, obj_ptr<NArray>& retVal, AsyncEvent* ac);
virtual result_t format(exlib::string sql, OptArgs args, exlib::string& retVal);
View
@@ -31,7 +31,7 @@ class mysql : public MySQL_base {
virtual result_t begin(AsyncEvent* ac);
virtual result_t commit(AsyncEvent* ac);
virtual result_t rollback(AsyncEvent* ac);
virtual result_t trans(v8::Local<v8::Function> func);
virtual result_t trans(v8::Local<v8::Function> func, bool& retVal);
virtual result_t execute(exlib::string sql, OptArgs args, obj_ptr<NArray>& retVal, AsyncEvent* ac);
virtual result_t format(exlib::string sql, OptArgs args, exlib::string& retVal);
@@ -195,9 +195,9 @@ result_t SQLite::rollback(AsyncEvent* ac)
return execute("ROLLBACK", 8, retVal);
}
result_t SQLite::trans(v8::Local<v8::Function> func)
result_t SQLite::trans(v8::Local<v8::Function> func, bool& retVal)
{
return _trans(this, func);
return _trans(this, func, retVal);
}
inline int32_t _busy(int32_t ms, int32_t count)
@@ -187,9 +187,9 @@ result_t mssql::rollback(AsyncEvent* ac)
return 0;
}
result_t mssql::trans(v8::Local<v8::Function> func)
result_t mssql::trans(v8::Local<v8::Function> func, bool& retVal)
{
return _trans(this, func);
return _trans(this, func, retVal);
}
result_t mssql::execute(const char* sql, int32_t sLen,
@@ -290,9 +290,9 @@ result_t mysql::rollback(AsyncEvent* ac)
return execute("ROLLBACK", 8, retVal);
}
result_t mysql::trans(v8::Local<v8::Function> func)
result_t mysql::trans(v8::Local<v8::Function> func, bool& retVal)
{
return _trans(this, func);
return _trans(this, func, retVal);
}
result_t mysql::execute(const char* sql, int32_t sLen,
View
@@ -2,9 +2,10 @@
namespace fibjs {
inline result_t _trans(DbConnection_base* db, v8::Local<v8::Function> func)
inline result_t _trans(DbConnection_base* db, v8::Local<v8::Function> func, bool& retVal)
{
result_t hr = 0;
retVal = false;
hr = db->ac_begin();
if (hr < 0)
@@ -21,7 +22,9 @@ inline result_t _trans(DbConnection_base* db, v8::Local<v8::Function> func)
if (result->IsFalse())
return db->ac_rollback();
else
else {
retVal = true;
return db->ac_commit();
}
}
}
@@ -23,8 +23,9 @@ interface DbConnection : object
* 函数运行错误,事务自动回滚
@param func 以事务方式执行的函数
@return 返回事务是否提交,正常 commit 时返回 true, rollback 时返回 false,如果事务出错则抛出错误
*/
trans(Function func);
Boolean trans(Function func);
/*! @brief 执行一个 sql 命令,并返回执行结果,可根据参数格式化字符串

0 comments on commit c6973ba

Please sign in to comment.