add affected_rows method (mysql_affected_rows)
This commit is contained in:
parent
e20df5c140
commit
8f93f830c1
@ -254,11 +254,16 @@ static VALUE rb_mysql_client_async_result(VALUE self) {
|
|||||||
|
|
||||||
static VALUE rb_mysql_client_last_id(VALUE self) {
|
static VALUE rb_mysql_client_last_id(VALUE self) {
|
||||||
MYSQL * client;
|
MYSQL * client;
|
||||||
my_ulonglong id;
|
|
||||||
GetMysql2Client(self, client);
|
GetMysql2Client(self, client);
|
||||||
|
|
||||||
id = mysql_insert_id(client);
|
return ULL2NUM(mysql_insert_id(client));
|
||||||
return ULL2NUM(id);
|
}
|
||||||
|
|
||||||
|
static VALUE rb_mysql_client_affected_rows(VALUE self) {
|
||||||
|
MYSQL * client;
|
||||||
|
GetMysql2Client(self, client);
|
||||||
|
|
||||||
|
return ULL2NUM(mysql_affected_rows(client));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Mysql2::Result */
|
/* Mysql2::Result */
|
||||||
@ -459,6 +464,7 @@ void Init_mysql2_ext() {
|
|||||||
rb_define_method(cMysql2Client, "socket", rb_mysql_client_socket, 0);
|
rb_define_method(cMysql2Client, "socket", rb_mysql_client_socket, 0);
|
||||||
rb_define_method(cMysql2Client, "async_result", rb_mysql_client_async_result, 0);
|
rb_define_method(cMysql2Client, "async_result", rb_mysql_client_async_result, 0);
|
||||||
rb_define_method(cMysql2Client, "last_id", rb_mysql_client_last_id, 0);
|
rb_define_method(cMysql2Client, "last_id", rb_mysql_client_last_id, 0);
|
||||||
|
rb_define_method(cMysql2Client, "affected_rows", rb_mysql_client_affected_rows, 0);
|
||||||
|
|
||||||
cMysql2Error = rb_define_class_under(mMysql2, "Error", rb_eStandardError);
|
cMysql2Error = rb_define_class_under(mMysql2, "Error", rb_eStandardError);
|
||||||
|
|
||||||
|
@ -39,6 +39,7 @@ static VALUE rb_mysql_client_server_info(VALUE self);
|
|||||||
static VALUE rb_mysql_client_socket(VALUE self);
|
static VALUE rb_mysql_client_socket(VALUE self);
|
||||||
static VALUE rb_mysql_client_async_result(VALUE self);
|
static VALUE rb_mysql_client_async_result(VALUE self);
|
||||||
static VALUE rb_mysql_client_last_id(VALUE self);
|
static VALUE rb_mysql_client_last_id(VALUE self);
|
||||||
|
static VALUE rb_mysql_client_affected_rows(VALUE self);
|
||||||
void rb_mysql_client_free(void * client);
|
void rb_mysql_client_free(void * client);
|
||||||
|
|
||||||
/* Mysql2::Result */
|
/* Mysql2::Result */
|
||||||
|
@ -117,18 +117,35 @@ describe Mysql2::Client do
|
|||||||
result.class.should eql(Mysql2::Result)
|
result.class.should eql(Mysql2::Result)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should respond to #last_id" do
|
context 'write operations api' do
|
||||||
@client.should respond_to(:last_id)
|
before(:each) do
|
||||||
end
|
@client.query "USE test"
|
||||||
|
@client.query "CREATE TABLE lastIdTest (`id` int(11) NOT NULL AUTO_INCREMENT, blah INT(11), PRIMARY KEY (`id`))"
|
||||||
|
end
|
||||||
|
|
||||||
it "#last_id should return a Fixnum, the from the last INSERT/UPDATE" do
|
after(:each) do
|
||||||
@client.last_id.should eql(0)
|
@client.query "DROP TABLE lastIdTest"
|
||||||
@client.query "USE test"
|
end
|
||||||
@client.query "CREATE TABLE lastIdTest (`id` int(11) NOT NULL AUTO_INCREMENT, blah INT(11), PRIMARY KEY (`id`))"
|
|
||||||
@client.last_id.should eql(0)
|
it "should respond to #last_id" do
|
||||||
@client.query "INSERT INTO lastIdTest (blah) VALUES (1234)"
|
@client.should respond_to(:last_id)
|
||||||
@client.last_id.should eql(1)
|
end
|
||||||
@client.query "DROP TABLE lastIdTest"
|
|
||||||
@client.last_id.should eql(0)
|
it "#last_id should return a Fixnum, the from the last INSERT/UPDATE" do
|
||||||
|
@client.last_id.should eql(0)
|
||||||
|
@client.query "INSERT INTO lastIdTest (blah) VALUES (1234)"
|
||||||
|
@client.last_id.should eql(1)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should respond to #last_id" do
|
||||||
|
@client.should respond_to(:last_id)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "#last_id should return a Fixnum, the from the last INSERT/UPDATE" do
|
||||||
|
@client.query "INSERT INTO lastIdTest (blah) VALUES (1234)"
|
||||||
|
@client.affected_rows.should eql(1)
|
||||||
|
@client.query "UPDATE lastIdTest SET blah=4321 WHERE id=1"
|
||||||
|
@client.affected_rows.should eql(1)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
Loading…
Reference in New Issue
Block a user