do_postgres 0.9.2 → 0.9.3

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt ADDED
@@ -0,0 +1 @@
1
+
data/Manifest.txt ADDED
@@ -0,0 +1,19 @@
1
+ History.txt
2
+ LICENSE
3
+ Manifest.txt
4
+ README.txt
5
+ Rakefile
6
+ TODO
7
+ ext/do_postgres_ext.c
8
+ ext/extconf.rb
9
+ ext/type-oids.h
10
+ lib/do_postgres.rb
11
+ lib/do_postgres/transaction.rb
12
+ lib/do_postgres/version.rb
13
+ spec/integration/do_postgres_spec.rb
14
+ spec/integration/logging_spec.rb
15
+ spec/integration/quoting_spec.rb
16
+ spec/integration/timezone_spec.rb
17
+ spec/spec.opts
18
+ spec/spec_helper.rb
19
+ spec/unit/transaction_spec.rb
@@ -1,4 +1,3 @@
1
- do_postgres
2
- ===========
1
+ = do_postgres
3
2
 
4
3
  A PostgreSQL driver for DataObjects
data/Rakefile CHANGED
@@ -1,14 +1,10 @@
1
1
  require 'rubygems'
2
- require 'rake/clean'
3
- require 'rake/gempackagetask'
4
2
  require 'spec/rake/spectask'
5
3
  require 'pathname'
6
- require Pathname(__FILE__).dirname.expand_path.parent + 'tasks/ext_helper'
7
4
 
8
- # House-keeping
9
- CLEAN.include '**/*.o', '**/*.so', '**/*.bundle', '**/*.a',
10
- '**/*.log', '{ext,lib}/*.{bundle,so,obj,pdb,lib,def,exp}',
11
- 'ext/Makefile'
5
+ ROOT = Pathname(__FILE__).dirname.expand_path
6
+
7
+ require "lib/do_postgres/version"
12
8
 
13
9
  JRUBY = (RUBY_PLATFORM =~ /java/) rescue nil
14
10
  WINDOWS = (RUBY_PLATFORM =~ /mswin|mingw|cygwin/) rescue nil
@@ -16,38 +12,31 @@ WINDOWS = (RUBY_PLATFORM =~ /mswin|mingw|cygwin/) rescue nil
16
12
  # is not entirely correct.
17
13
  SUDO = (WINDOWS || JRUBY) ? '' : ('sudo' unless ENV['SUDOLESS'])
18
14
 
19
- spec = Gem::Specification.new do |s|
20
- s.name = 'do_postgres'
21
- s.version = '0.9.2'
22
- s.platform = Gem::Platform::RUBY
23
- s.has_rdoc = true
24
- s.extra_rdoc_files = %w[ README LICENSE TODO ]
25
- s.summary = 'A DataObject.rb driver for PostgreSQL'
26
- s.description = s.summary
27
- s.author = 'Yehuda Katz'
28
- s.email = 'wycats@gmail.com'
29
- s.homepage = 'http://rubyforge.org/projects/dorb'
30
- s.rubyforge_project = 'dorb'
31
- s.require_path = 'lib'
32
- s.extensions = %w[ ext/extconf.rb ]
33
- s.files = FileList[ '{ext,lib,spec}/**/*.{c,h,rb}', 'Rakefile', *s.extra_rdoc_files ]
34
- s.add_dependency('data_objects', "=#{s.version}")
35
- end
15
+ AUTHOR = "Bernerd Schaefer"
16
+ EMAIL = "bj.schaefer@gmail.com"
17
+ GEM_NAME = "do_postgres"
18
+ GEM_VERSION = DataObjects::Postgres::VERSION
19
+ GEM_DEPENDENCIES = [["data_objects", GEM_VERSION]]
20
+ GEM_CLEAN = ['**/*.{o,so,bundle,log,a,gem,dSYM,obj,pdb,lib,def,exp,DS_Store}', 'ext/Makefile']
21
+ GEM_EXTRAS = { :extensions => %w[ ext/extconf.rb ], :has_rdoc => false }
36
22
 
37
- Rake::GemPackageTask.new(spec) do |pkg|
38
- pkg.gem_spec = spec
39
- end
23
+ PROJECT_NAME = "dorb"
24
+ PROJECT_URL = "http://rubyforge.org/projects/dorb"
25
+ PROJECT_DESCRIPTION = PROJECT_SUMMARY = "A DataObject.rb driver for MySQL"
26
+
27
+ DRIVER = true
28
+
29
+ require ROOT.parent + 'tasks/hoe'
40
30
 
41
- # Use of ext_helper to properly setup compile tasks and native gem generation
42
- setup_extension "#{spec.name}_ext", spec
31
+ # Installation
43
32
 
44
33
  task :install => [ :package ] do
45
- sh %{#{SUDO} gem install --local pkg/#{spec.name}-#{spec.version} --no-update-sources}, :verbose => false
34
+ sh %{#{SUDO} gem install --local pkg/#{GEM_NAME}-#{GEM_VERSION} --no-update-sources}, :verbose => false
46
35
  end
47
36
 
48
- desc "Uninstall #{spec.name} #{spec.version} (default ruby)"
37
+ desc "Uninstall #{GEM_NAME} #{GEM_VERSION} (default ruby)"
49
38
  task :uninstall => [ :clobber ] do
50
- sh "#{SUDO} gem uninstall #{spec.name} -v#{spec.version} -I -x", :verbose => false
39
+ sh "#{SUDO} gem uninstall #{GEM_NAME} -v#{GEM_VERSION} -I -x", :verbose => false
51
40
  end
52
41
 
53
42
  desc 'Run specifications'
@@ -53,7 +53,7 @@ static VALUE ePostgresError;
53
53
  static void data_objects_debug(VALUE string) {
54
54
  VALUE logger = rb_funcall(mPostgres, ID_LOGGER, 0);
55
55
  int log_level = NUM2INT(rb_funcall(logger, ID_LEVEL, 0));
56
-
56
+
57
57
  if (0 == log_level) {
58
58
  rb_funcall(logger, ID_DEBUG, 1, string);
59
59
  }
@@ -87,23 +87,23 @@ static VALUE parse_date(const char *date) {
87
87
  int year, month, day;
88
88
  int jd, ajd;
89
89
  VALUE rational;
90
-
90
+
91
91
  sscanf(date, "%4d-%2d-%2d", &year, &month, &day);
92
-
92
+
93
93
  jd = jd_from_date(year, month, day);
94
-
94
+
95
95
  // Math from Date.jd_to_ajd
96
96
  ajd = jd * 2 - 1;
97
97
  rational = rb_funcall(rb_cRational, rb_intern("new!"), 2, INT2NUM(ajd), INT2NUM(2));
98
-
98
+
99
99
  return rb_funcall(rb_cDate, ID_NEW_DATE, 3, rational, INT2NUM(0), INT2NUM(2299161));
100
100
  }
101
101
 
102
102
  // Creates a Rational for use as a Timezone offset to be passed to DateTime.new!
103
103
  static VALUE seconds_to_offset(do_int64 num) {
104
- do_int64 den = 86400;
104
+ do_int64 den = 86400;
105
105
  reduce(&num, &den);
106
- return rb_funcall(rb_cRational, rb_intern("new!"), 2, rb_ll2inum(num), rb_ll2inum(den));
106
+ return rb_funcall(rb_cRational, rb_intern("new!"), 2, rb_ll2inum(num), rb_ll2inum(den));
107
107
  }
108
108
 
109
109
  static VALUE timezone_to_offset(int hour_offset, int minute_offset) {
@@ -121,15 +121,15 @@ static VALUE parse_date_time(const char *date) {
121
121
  int year, month, day, hour, min, sec, usec, hour_offset, minute_offset;
122
122
  int jd;
123
123
  do_int64 num, den;
124
-
124
+
125
125
  long int gmt_offset;
126
126
  int is_dst;
127
-
127
+
128
128
  time_t rawtime;
129
129
  struct tm * timeinfo;
130
130
 
131
131
  int tokens_read, max_tokens;
132
-
132
+
133
133
  if (0 != strchr(date, '.')) {
134
134
  // This is a datetime with sub-second precision
135
135
  tokens_read = sscanf(date, "%4d-%2d-%2d %2d:%2d:%2d.%d%3d:%2d", &year, &month, &day, &hour, &min, &sec, &usec, &hour_offset, &minute_offset);
@@ -139,7 +139,7 @@ static VALUE parse_date_time(const char *date) {
139
139
  tokens_read = sscanf(date, "%4d-%2d-%2d %2d:%2d:%2d%3d:%2d", &year, &month, &day, &hour, &min, &sec, &hour_offset, &minute_offset);
140
140
  max_tokens = 8;
141
141
  }
142
-
142
+
143
143
  if (max_tokens == tokens_read) {
144
144
  // We read the Date, Time, and Timezone info
145
145
  minute_offset *= hour_offset < 0 ? -1 : 1;
@@ -150,11 +150,11 @@ static VALUE parse_date_time(const char *date) {
150
150
  return parse_date(date);
151
151
  } else if (tokens_read >= (max_tokens - 3)) {
152
152
  // We read the Date and Time, default to the current locale's offset
153
-
153
+
154
154
  // Get localtime
155
155
  time(&rawtime);
156
156
  timeinfo = localtime(&rawtime);
157
-
157
+
158
158
  is_dst = timeinfo->tm_isdst * 3600;
159
159
 
160
160
  // Reset to GM Time
@@ -181,7 +181,7 @@ static VALUE parse_date_time(const char *date) {
181
181
 
182
182
  // Modify the numerator so when we apply the timezone everything works out
183
183
  num -= (hour_offset * 1440) + (minute_offset * 24);
184
-
184
+
185
185
  den = (24 * 1440);
186
186
  reduce(&num, &den);
187
187
 
@@ -199,7 +199,7 @@ static VALUE parse_date_time(const char *date) {
199
199
 
200
200
  ajd = rb_funcall(rb_cRational, rb_intern("new!"), 2, rb_ull2inum(num), rb_ull2inum(den));
201
201
  offset = timezone_to_offset(hour_offset, minute_offset);
202
-
202
+
203
203
  return rb_funcall(rb_cDateTime, ID_NEW_DATE, 3, ajd, offset, INT2NUM(2299161));
204
204
  }
205
205
 
@@ -260,7 +260,7 @@ static VALUE infer_ruby_type(Oid type) {
260
260
  }
261
261
 
262
262
  static VALUE typecast(char *value, char *type) {
263
-
263
+
264
264
  if ( strcmp(type, "Class") == 0) {
265
265
  return rb_funcall(mDO, rb_intern("find_const"), 1, TAINTED_STRING(value));
266
266
  } else if ( strcmp(type, "Integer") == 0 || strcmp(type, "Fixnum") == 0 || strcmp(type, "Bignum") == 0 ) {
@@ -324,12 +324,12 @@ static VALUE cConnection_initialize(VALUE self, VALUE uri) {
324
324
  }
325
325
 
326
326
  db = PQsetdbLogin(
327
- host,
328
- port,
329
- NULL,
330
- NULL,
331
- database,
332
- user,
327
+ host,
328
+ port,
329
+ NULL,
330
+ NULL,
331
+ database,
332
+ user,
333
333
  password
334
334
  );
335
335
 
@@ -375,7 +375,7 @@ static VALUE cCommand_quote_string(VALUE self, VALUE string) {
375
375
  char *escaped;
376
376
  int quoted_length = 0;
377
377
  VALUE result;
378
-
378
+
379
379
  length = strlen(source);
380
380
 
381
381
  // Allocate space for the escaped version of 'string'
@@ -397,17 +397,17 @@ static VALUE cCommand_execute_non_query(int argc, VALUE *argv[], VALUE self) {
397
397
  PGconn *db = DATA_PTR(rb_iv_get(rb_iv_get(self, "@connection"), "@connection"));
398
398
  PGresult *response;
399
399
  int status;
400
-
400
+
401
401
  int affected_rows;
402
402
  int insert_id;
403
-
403
+
404
404
  VALUE query = build_query_from_args(self, argc, argv);
405
405
  data_objects_debug(query);
406
-
406
+
407
407
  response = PQexec(db, StringValuePtr(query));
408
-
408
+
409
409
  status = PQresultStatus(response);
410
-
410
+
411
411
  if ( status == PGRES_TUPLES_OK ) {
412
412
  insert_id = atoi(PQgetvalue(response, 0, 0));
413
413
  affected_rows = 1;
@@ -421,9 +421,9 @@ static VALUE cCommand_execute_non_query(int argc, VALUE *argv[], VALUE self) {
421
421
  PQclear(response);
422
422
  rb_raise(ePostgresError, message);
423
423
  }
424
-
424
+
425
425
  PQclear(response);
426
-
426
+
427
427
  return rb_funcall(cResult, ID_NEW, 3, self, INT2NUM(affected_rows), INT2NUM(insert_id));
428
428
  }
429
429
 
@@ -521,14 +521,14 @@ static VALUE cReader_next(VALUE self) {
521
521
 
522
522
  for ( i = 0; i < field_count; i++ ) {
523
523
  ruby_type = RARRAY(field_types)->ptr[i];
524
-
524
+
525
525
  if ( TYPE(ruby_type) == T_STRING ) {
526
526
  type = RSTRING(ruby_type)->ptr;
527
527
  }
528
528
  else {
529
529
  type = rb_class2name(ruby_type);
530
530
  }
531
-
531
+
532
532
  // Always return nil if the value returned from Postgres is null
533
533
  if (!PQgetisnull(reader, position, i)) {
534
534
  value = typecast(PQgetvalue(reader, position, i), type);
@@ -546,10 +546,10 @@ static VALUE cReader_next(VALUE self) {
546
546
  }
547
547
 
548
548
  static VALUE cReader_values(VALUE self) {
549
-
549
+
550
550
  int position = rb_iv_get(self, "@position");
551
551
  int row_count = NUM2INT(rb_iv_get(self, "@row_count"));
552
-
552
+
553
553
  if ( position == Qnil || NUM2INT(position) > row_count ) {
554
554
  rb_raise(ePostgresError, "Reader not initialized");
555
555
  }
@@ -565,16 +565,16 @@ static VALUE cReader_fields(VALUE self) {
565
565
  void Init_do_postgres_ext() {
566
566
  rb_require("rubygems");
567
567
  rb_require("date");
568
-
569
- // Get references classes needed for Date/Time parsing
568
+
569
+ // Get references classes needed for Date/Time parsing
570
570
  rb_cDate = CONST_GET(rb_mKernel, "Date");
571
571
  rb_cDateTime = CONST_GET(rb_mKernel, "DateTime");
572
572
  rb_cTime = CONST_GET(rb_mKernel, "Time");
573
573
  rb_cRational = CONST_GET(rb_mKernel, "Rational");
574
574
  rb_cBigDecimal = CONST_GET(rb_mKernel, "BigDecimal");
575
-
575
+
576
576
  rb_funcall(rb_mKernel, rb_intern("require"), 1, rb_str_new2("data_objects"));
577
-
577
+
578
578
  ID_NEW_DATE = RUBY_VERSION_CODE < 186 ? rb_intern("new0") : rb_intern("new!");
579
579
  ID_LOGGER = rb_intern("logger");
580
580
  ID_DEBUG = rb_intern("debug");
@@ -587,28 +587,28 @@ void Init_do_postgres_ext() {
587
587
  cDO_Command = CONST_GET(mDO, "Command");
588
588
  cDO_Result = CONST_GET(mDO, "Result");
589
589
  cDO_Reader = CONST_GET(mDO, "Reader");
590
-
590
+
591
591
  mPostgres = rb_define_module_under(mDO, "Postgres");
592
592
  ePostgresError = rb_define_class("PostgresError", rb_eStandardError);
593
-
593
+
594
594
  cConnection = POSTGRES_CLASS("Connection", cDO_Connection);
595
595
  rb_define_method(cConnection, "initialize", cConnection_initialize, 1);
596
596
  rb_define_method(cConnection, "dispose", cConnection_dispose, 0);
597
-
597
+
598
598
  cCommand = POSTGRES_CLASS("Command", cDO_Command);
599
599
  rb_include_module(cCommand, cDO_Quoting);
600
600
  rb_define_method(cCommand, "set_types", cCommand_set_types, 1);
601
601
  rb_define_method(cCommand, "execute_non_query", cCommand_execute_non_query, -1);
602
602
  rb_define_method(cCommand, "execute_reader", cCommand_execute_reader, -1);
603
603
  rb_define_method(cCommand, "quote_string", cCommand_quote_string, 1);
604
-
604
+
605
605
  cResult = POSTGRES_CLASS("Result", cDO_Result);
606
-
606
+
607
607
  cReader = POSTGRES_CLASS("Reader", cDO_Reader);
608
608
  rb_define_method(cReader, "close", cReader_close, 0);
609
609
  rb_define_method(cReader, "next!", cReader_next, 0);
610
610
  rb_define_method(cReader, "values", cReader_values, 0);
611
611
  rb_define_method(cReader, "fields", cReader_fields, 0);
612
-
612
+
613
613
  }
614
614
 
@@ -0,0 +1,5 @@
1
+ module DataObjects
2
+ module Postgres
3
+ VERSION = "0.9.3"
4
+ end
5
+ end
@@ -21,6 +21,7 @@ describe "DataObjects::Postgres::Connection" do
21
21
 
22
22
  it "should connect to the db" do
23
23
  connection = DataObjects::Connection.new("postgres://localhost/do_test")
24
+ connection.close
24
25
  end
25
26
  end
26
27
 
@@ -31,6 +32,10 @@ describe "DataObjects::Postgres::Command" do
31
32
  @connection = ensure_users_table_and_return_connection
32
33
  end
33
34
 
35
+ after :all do
36
+ @connection.close
37
+ end
38
+
34
39
  it "should create a command" do
35
40
  @connection.create_command("CREATE TABLE users").should be_a_kind_of(DataObjects::Postgres::Command)
36
41
  end
@@ -62,6 +67,10 @@ describe "DataObjects::Postgres::Result" do
62
67
  @connection = ensure_users_table_and_return_connection
63
68
  end
64
69
 
70
+ after :all do
71
+ @connection.close
72
+ end
73
+
65
74
  it "should raise errors on bad queries" do
66
75
  command = @connection.create_command("INSER INTO users (name) VALUES ('Test')")
67
76
  lambda { command.execute_non_query }.should raise_error
@@ -4,7 +4,7 @@ require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
4
4
  describe DataObjects::Postgres::Command do
5
5
 
6
6
  before(:each) do
7
- @connection = DataObjects::Postgres::Connection.new("postgres://localhost/do_test")
7
+ @connection = DataObjects::Connection.new("postgres://localhost/do_test")
8
8
  end
9
9
 
10
10
  describe "Executing a Reader" do
data/spec/spec.opts ADDED
@@ -0,0 +1,2 @@
1
+ --format specdoc
2
+ --colour
metadata CHANGED
@@ -1,59 +1,77 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: do_postgres
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.2
4
+ version: 0.9.3
5
5
  platform: ruby
6
6
  authors:
7
- - Yehuda Katz
7
+ - Bernerd Schaefer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-06-25 00:00:00 -05:00
12
+ date: 2008-07-24 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: data_objects
17
+ type: :runtime
17
18
  version_requirement:
18
19
  version_requirements: !ruby/object:Gem::Requirement
19
20
  requirements:
20
21
  - - "="
21
22
  - !ruby/object:Gem::Version
22
- version: 0.9.2
23
+ version: 0.9.3
23
24
  version:
24
- description: A DataObject.rb driver for PostgreSQL
25
- email: wycats@gmail.com
25
+ - !ruby/object:Gem::Dependency
26
+ name: hoe
27
+ type: :development
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.7.0
34
+ version:
35
+ description: A DataObject.rb driver for MySQL
36
+ email:
37
+ - bj.schaefer@gmail.com
26
38
  executables: []
27
39
 
28
40
  extensions:
29
41
  - ext/extconf.rb
30
42
  extra_rdoc_files:
31
- - README
43
+ - History.txt
44
+ - Manifest.txt
45
+ - README.txt
46
+ files:
47
+ - History.txt
32
48
  - LICENSE
49
+ - Manifest.txt
50
+ - README.txt
51
+ - Rakefile
33
52
  - TODO
34
- files:
35
53
  - ext/do_postgres_ext.c
36
- - ext/type-oids.h
37
54
  - ext/extconf.rb
38
- - lib/do_postgres/transaction.rb
55
+ - ext/type-oids.h
39
56
  - lib/do_postgres.rb
57
+ - lib/do_postgres/transaction.rb
58
+ - lib/do_postgres/version.rb
40
59
  - spec/integration/do_postgres_spec.rb
41
60
  - spec/integration/logging_spec.rb
42
61
  - spec/integration/quoting_spec.rb
43
62
  - spec/integration/timezone_spec.rb
63
+ - spec/spec.opts
44
64
  - spec/spec_helper.rb
45
65
  - spec/unit/transaction_spec.rb
46
- - Rakefile
47
- - README
48
- - LICENSE
49
- - TODO
50
- has_rdoc: true
66
+ has_rdoc: false
51
67
  homepage: http://rubyforge.org/projects/dorb
52
68
  post_install_message:
53
- rdoc_options: []
54
-
69
+ rdoc_options:
70
+ - --main
71
+ - README.txt
55
72
  require_paths:
56
73
  - lib
74
+ - ext
57
75
  required_ruby_version: !ruby/object:Gem::Requirement
58
76
  requirements:
59
77
  - - ">="
@@ -69,9 +87,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
69
87
  requirements: []
70
88
 
71
89
  rubyforge_project: dorb
72
- rubygems_version: 1.0.1
90
+ rubygems_version: 1.2.0
73
91
  signing_key:
74
92
  specification_version: 2
75
- summary: A DataObject.rb driver for PostgreSQL
93
+ summary: A DataObject.rb driver for MySQL
76
94
  test_files: []
77
95