Skip to content

Commit

Permalink
fix uuid overflow in prepared statement id generation.
Browse files Browse the repository at this point in the history
  • Loading branch information
deepfryed committed Mar 22, 2015
1 parent 0d4df81 commit d1e68ec
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 120 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
@@ -0,0 +1,3 @@
[submodule "vendor/swift-db-datetime"]
path = vendor/swift-db-datetime
url = https://github.com/deepfryed/swift-db-datetime.git
4 changes: 4 additions & 0 deletions CHANGELOG
@@ -1,3 +1,7 @@
== 0.3.1 (2015-03-22)

* prepared statement uuid overflow fix.

== 0.3.0 (2013-02-19)

* supports encoding option while connecting.
Expand Down
12 changes: 12 additions & 0 deletions README.md
Expand Up @@ -10,6 +10,18 @@ MRI adapter for PostgreSQL
* Asynchronous support using PQsendQuery family of functions
* Nested transactions

## Requirements

* postgresql client deveopment libraries (libpq-dev)
* uuid development libraries (uuid-dev)

## Building

```
git submodule update --init
rake
```

## API

```
Expand Down
2 changes: 1 addition & 1 deletion Rakefile
Expand Up @@ -7,7 +7,7 @@ require 'rake/testtask'
$rootdir = Pathname.new(__FILE__).dirname
$gemspec = Gem::Specification.new do |s|
s.name = 'swift-db-postgres'
s.version = '0.3.0'
s.version = '0.3.1'
s.date = Date.today
s.authors = ['Bharanee Rathna']
s.email = ['deepfryed@gmail.com']
Expand Down
7 changes: 4 additions & 3 deletions ext/swift/db/postgres/common.c
Expand Up @@ -12,11 +12,12 @@ VALUE rb_uuid_string() {
char uuid_hex[sizeof(uuid_t) * 2 + 1];

uuid_generate(uuid);

memset(uuid_hex, 0, sizeof(uuid_hex));
for (n = 0; n < sizeof(uuid_t); n++)
sprintf(uuid_hex + n * 2 + 1, "%02x", uuid[n]);
sprintf(uuid_hex + n * 2, "%02x", uuid[n]);

uuid_hex[0] = 'u';
return rb_str_new(uuid_hex, sizeof(uuid_t) * 2 + 1);
return rb_str_new(uuid_hex, sizeof(uuid_t) * 2);
}

/* NOTE: very naive, no regex etc. */
Expand Down
99 changes: 0 additions & 99 deletions ext/swift/db/postgres/datetime.c

This file was deleted.

1 change: 1 addition & 0 deletions ext/swift/db/postgres/datetime.c
8 changes: 0 additions & 8 deletions ext/swift/db/postgres/datetime.h

This file was deleted.

1 change: 1 addition & 0 deletions ext/swift/db/postgres/datetime.h
Binary file modified swift-db-postgres.gemspec
Binary file not shown.
19 changes: 10 additions & 9 deletions test/test_async.rb
Expand Up @@ -2,33 +2,34 @@

describe 'async operations' do
it 'can query async and call block with result when ready' do
rows = []
pool = 3.times.map {Swift::DB::Postgres.new(db: 'swift_test')}
rows = []
threads = []
pool = 3.times.map {Swift::DB::Postgres.new(db: 'swift_test')}

3.times do |n|
Thread.new do
threads << Thread.new do
pool[n].query("select pg_sleep(#{(3 - n) / 10.0}), #{n + 1} as query_id") {|row| rows << row[:query_id]}
end
end

Thread.list.reject {|thread| Thread.current == thread}.each(&:join)
threads.each(&:join)
assert_equal [3, 2, 1], rows
end

it 'returns and allows IO poll on connection file descriptor' do

rows = []
pool = 3.times.map {Swift::DB::Postgres.new(db: 'swift_test')}
rows = []
threads = []
pool = 3.times.map {Swift::DB::Postgres.new(db: 'swift_test')}

3.times do |n|
Thread.new do
threads << Thread.new do
pool[n].query("select pg_sleep(#{(3 - n) / 10.0}), #{n + 1} as query_id")
IO.select([IO.for_fd(pool[n].fileno)], [], [])
rows << pool[n].result.first[:query_id]
end
end

Thread.list.reject {|thread| Thread.current == thread}.each(&:join)
threads.each(&:join)
assert_equal [3, 2, 1], rows
end
end
1 change: 1 addition & 0 deletions vendor/swift-db-datetime
Submodule swift-db-datetime added at c72595

0 comments on commit d1e68ec

Please sign in to comment.