Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TIMOB-15194] Implemented Ti.Database.getRowsAffected() #172

Merged
merged 1 commit into from
Sep 16, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/tibb/NativeDBObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#pragma GCC diagnostic ignored "-Wunused-parameter"

NativeDBObject::NativeDBObject(TiObject* tiObject)
: NativeProxyObject(tiObject) {
: NativeProxyObject(tiObject), rowsAffected(0) {
}

NativeDBObject::~NativeDBObject() {
Expand Down Expand Up @@ -75,6 +75,7 @@ int NativeDBObject::execute(NativeResultSetObject* resultSet, string command, ve
if (stepResult == SQLITE_DONE) {
sqlite3_finalize(statement);
resultSet->effectedRows = effectedRows;
rowsAffected = resultSet->effectedRows + 1;
resultSet->statement = statement;
return NATIVE_ERROR_OK;
}
Expand All @@ -95,6 +96,7 @@ int NativeDBObject::execute(NativeResultSetObject* resultSet, string command, ve
}

resultSet->effectedRows = effectedRows;
rowsAffected = resultSet->effectedRows;
sqlite3_reset(statement);
resultSet->stepResult = sqlite3_step(statement);
resultSet->statement = statement;
Expand All @@ -105,6 +107,10 @@ int NativeDBObject::execute(NativeResultSetObject* resultSet, string command, ve
return NATIVE_ERROR_OK;
}

int NativeDBObject::affectedRows()
{
return rowsAffected;
}
int NativeDBObject::close() {

sqlite3_close(_db);
Expand Down
4 changes: 2 additions & 2 deletions src/tibb/NativeDBObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class NativeDBObject : public NativeProxyObject
// DB methods
int execute(NativeResultSetObject* resultSet, string command, vector<string> bindings);
int close();

int affectedRows();
protected:
virtual ~NativeDBObject();

Expand All @@ -49,7 +49,7 @@ class NativeDBObject : public NativeProxyObject

friend class TiDBObject;
int _open(string name);

int rowsAffected;
sqlite3* _db;
};

Expand Down
10 changes: 10 additions & 0 deletions src/tibb/TiDBObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "TiResultSetObject.h"
#include "TiConstants.h"
#include "TiGenericFunctionObject.h"
#include "TiPropertyGetObject.h"
#include "NativeException.h"
#include "TiMessageStrings.h"
#include <vector>
Expand Down Expand Up @@ -54,6 +55,7 @@ void TiDBObject::onCreateStaticMembers() {
TiProxy::onCreateStaticMembers();
TiGenericFunctionObject::addGenericFunctionToParent(this, "execute", this, _execute);
TiGenericFunctionObject::addGenericFunctionToParent(this, "close", this, _close);
TiPropertyGetObject::createGetProperty(this, "rowsAffected", this, _rowsAffected);
}

Handle<Value> TiDBObject::_execute(void* userContext, TiObject*, const Arguments& args)
Expand Down Expand Up @@ -106,6 +108,14 @@ Handle<Value> TiDBObject::_execute(void* userContext, TiObject*, const Arguments
return Undefined();
}

Handle<Value> TiDBObject::_rowsAffected(void* userContext)
{
TiDBObject* obj = (TiDBObject*) userContext;
NativeDBObject* ndb = (NativeDBObject*) obj->getNativeObject();
HandleScope scope;
return scope.Close(Number::New(ndb->affectedRows()));
}

Handle<Value> TiDBObject::_close(void* userContext, TiObject*, const Arguments& args)
{
TiDBObject* obj = (TiDBObject*) userContext;
Expand Down
1 change: 1 addition & 0 deletions src/tibb/TiDBObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class TiDBObject : public TiProxy

static Handle<Value> _execute(void* userContext, TiObject* caller, const Arguments& args);
static Handle<Value> _close(void* userContext, TiObject* caller, const Arguments& args);
static Handle<Value> _rowsAffected(void* userContext);

private:
TiDBObject();
Expand Down