Skip to content

Commit

Permalink
Add MysqlSyncConn::SetCharset() method with tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Sannis committed Mar 22, 2010
1 parent de1fd37 commit cd2873e
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/api_node_mysql_sync.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ Connection, options, errors and information
Boolean close();
Boolean ping();
Boolean selectDb (dbname);
Boolean setCharset (charset);


### Options ###
Expand Down
27 changes: 27 additions & 0 deletions mysql_sync_bindings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Local<External> VAR = Local<External>::Cast(args[I]);
// static Persistent<String> ping_symbol;
// static Persistent<String> query_symbol;
// static Persistent<String> selectDb_symbol;
// static Persistent<String> setCharset_symbol;
// static Persistent<String> warningCount_symbol;

// For MysqlSyncRes
Expand Down Expand Up @@ -82,6 +83,7 @@ class MysqlSyncConn : public node::EventEmitter {
// ping_symbol = NODE_PSYMBOL("ping");
// query_symbol = NODE_PSYMBOL("query");
// selectDb_symbol = NODE_PSYMBOL("selectDb");
// setCharset_symbol = NODE_PSYMBOL("setCharset");
// warningCount_symbol = NODE_PSYMBOL("warningCount");

NODE_SET_PROTOTYPE_METHOD(t, "affectedRows", AffectedRows);
Expand All @@ -98,6 +100,7 @@ class MysqlSyncConn : public node::EventEmitter {
NODE_SET_PROTOTYPE_METHOD(t, "ping", Ping);
NODE_SET_PROTOTYPE_METHOD(t, "query", Query);
NODE_SET_PROTOTYPE_METHOD(t, "selectDb", SelectDb);
NODE_SET_PROTOTYPE_METHOD(t, "setCharset", SetCharset);
NODE_SET_PROTOTYPE_METHOD(t, "warningCount", WarningCount);

target->Set(String::NewSymbol("MysqlSyncConn"), t->GetFunction());
Expand Down Expand Up @@ -510,6 +513,30 @@ class MysqlSyncConn : public node::EventEmitter {
return scope.Close(True());
}

static Handle<Value> SetCharset(const Arguments& args) {
HandleScope scope;

MysqlSyncConn *conn = OBJUNWRAP<MysqlSyncConn>(args.This());

if (!conn->_conn) {
return THREXC("Not connected");
}

if (args.Length() == 0 || !args[0]->IsString()) {
return THREXC("Must give charset name as argument");
}

String::Utf8Value charset(args[0]);

bool r = mysql_set_character_set(conn->_conn, *charset);

if (r) {
return scope.Close(False());
}

return scope.Close(True());
}

static Handle<Value> WarningCount(const Arguments& args) {
HandleScope scope;

Expand Down
9 changes: 9 additions & 0 deletions tests/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ var host = "localhost",
database = "test",
database_denied = "mysql",
test_table = "test_table",
charset = "utf8",

// Operations count for continuous tests
reconnect_count = 10000,
Expand Down Expand Up @@ -85,6 +86,14 @@ unittest.test('conn.selectDb() for denied database', function () {
conn.close();
});

unittest.test('conn.setCharset()', function () {
var conn = mysql_sync.createConnection(host, user, password);

unittest.assert(conn.setCharset(charset));

conn.close();
});

unittest.test('conn.connectErrno()', function () {
var conn = mysql_sync.createConnection(host, user, password, database);

Expand Down

0 comments on commit cd2873e

Please sign in to comment.