knjrbfw 0.0.97 → 0.0.98

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.97
1
+ 0.0.98
data/knjrbfw.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "knjrbfw"
8
- s.version = "0.0.97"
8
+ s.version = "0.0.98"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Kasper Johansen"]
12
- s.date = "2012-09-13"
12
+ s.date = "2012-09-18"
13
13
  s.description = "Including stuff for HTTP, SSH and much more."
14
14
  s.email = "k@spernj.org"
15
15
  s.extra_rdoc_files = [
data/lib/knj/knj.rb CHANGED
@@ -46,7 +46,9 @@ module Knj
46
46
  end
47
47
 
48
48
  #Loads a gem by a given name. First tries to load the gem from a custom parent directory to enable loading of development-gems.
49
- def self.gem_require(gem_const, gem_name)
49
+ def self.gem_require(gem_const, gem_name = nil)
50
+ gem_name = gem_const.to_s.downcase.strip if !gem_name
51
+
50
52
  #Return false if the constant is already loaded.
51
53
  return false if ::Kernel.const_defined?(gem_const)
52
54
 
@@ -47,63 +47,65 @@ class KnjDB_mysql
47
47
 
48
48
  #Respawns the connection to the MySQL-database.
49
49
  def reconnect
50
- case @subtype
51
- when "mysql"
52
- @conn = Mysql.real_connect(@knjdb.opts[:host], @knjdb.opts[:user], @knjdb.opts[:pass], @knjdb.opts[:db], @port)
53
- when "mysql2"
54
- require "rubygems"
55
- require "mysql2"
56
-
57
- args = {
58
- :host => @knjdb.opts[:host],
59
- :username => @knjdb.opts[:user],
60
- :password => @knjdb.opts[:pass],
61
- :database => @knjdb.opts[:db],
62
- :port => @port,
63
- :symbolize_keys => true,
64
- :cache_rows => false
65
- }
66
-
67
- #Symbolize keys should also be given here, else table-data wont be symbolized for some reason - knj.
68
- @query_args = {:symbolize_keys => true}
69
- @query_args.merge!(@knjdb.opts[:query_args]) if @knjdb.opts[:query_args]
70
-
71
- pos_args = [:as, :async, :cast_booleans, :database_timezone, :application_timezone, :cache_rows, :connect_flags, :cast]
72
- pos_args.each do |key|
73
- args[key] = @knjdb.opts[key] if @knjdb.opts.key?(key)
74
- end
75
-
76
- args[:as] = :array if @opts[:result] == "array"
77
-
78
- tries = 0
79
- begin
80
- tries += 1
81
- @conn = Mysql2::Client.new(args)
82
- rescue => e
83
- if tries <= 3
84
- if e.message == "Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (111)"
85
- sleep 1
86
- retry
50
+ @mutex.synchronize do
51
+ case @subtype
52
+ when "mysql"
53
+ @conn = Mysql.real_connect(@knjdb.opts[:host], @knjdb.opts[:user], @knjdb.opts[:pass], @knjdb.opts[:db], @port)
54
+ when "mysql2"
55
+ require "rubygems"
56
+ require "mysql2"
57
+
58
+ args = {
59
+ :host => @knjdb.opts[:host],
60
+ :username => @knjdb.opts[:user],
61
+ :password => @knjdb.opts[:pass],
62
+ :database => @knjdb.opts[:db],
63
+ :port => @port,
64
+ :symbolize_keys => true,
65
+ :cache_rows => false
66
+ }
67
+
68
+ #Symbolize keys should also be given here, else table-data wont be symbolized for some reason - knj.
69
+ @query_args = {:symbolize_keys => true}
70
+ @query_args.merge!(@knjdb.opts[:query_args]) if @knjdb.opts[:query_args]
71
+
72
+ pos_args = [:as, :async, :cast_booleans, :database_timezone, :application_timezone, :cache_rows, :connect_flags, :cast]
73
+ pos_args.each do |key|
74
+ args[key] = @knjdb.opts[key] if @knjdb.opts.key?(key)
75
+ end
76
+
77
+ args[:as] = :array if @opts[:result] == "array"
78
+
79
+ tries = 0
80
+ begin
81
+ tries += 1
82
+ @conn = Mysql2::Client.new(args)
83
+ rescue => e
84
+ if tries <= 3
85
+ if e.message == "Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (111)"
86
+ sleep 1
87
+ retry
88
+ end
87
89
  end
90
+
91
+ raise e
92
+ end
93
+ when "java"
94
+ if !@jdbc_loaded
95
+ require "java"
96
+ require "/usr/share/java/mysql-connector-java.jar" if File.exists?("/usr/share/java/mysql-connector-java.jar")
97
+ import "com.mysql.jdbc.Driver"
98
+ @jdbc_loaded = true
88
99
  end
89
100
 
90
- raise e
91
- end
92
- when "java"
93
- if !@jdbc_loaded
94
- require "java"
95
- require "/usr/share/java/mysql-connector-java.jar" if File.exists?("/usr/share/java/mysql-connector-java.jar")
96
- import "com.mysql.jdbc.Driver"
97
- @jdbc_loaded = true
98
- end
99
-
100
- @conn = java.sql::DriverManager.getConnection("jdbc:mysql://#{@knjdb.opts[:host]}:#{@port}/#{@knjdb.opts[:db]}?user=#{@knjdb.opts[:user]}&password=#{@knjdb.opts[:pass]}&populateInsertRowWithDefaultValues=true&zeroDateTimeBehavior=round&characterEncoding=#{@encoding}&holdResultsOpenOverStatementClose=true")
101
- self.query("SET SQL_MODE = ''")
102
- else
103
- raise "Unknown subtype: #{@subtype}"
101
+ @conn = java.sql::DriverManager.getConnection("jdbc:mysql://#{@knjdb.opts[:host]}:#{@port}/#{@knjdb.opts[:db]}?user=#{@knjdb.opts[:user]}&password=#{@knjdb.opts[:pass]}&populateInsertRowWithDefaultValues=true&zeroDateTimeBehavior=round&characterEncoding=#{@encoding}&holdResultsOpenOverStatementClose=true")
102
+ self.query("SET SQL_MODE = ''")
103
+ else
104
+ raise "Unknown subtype: #{@subtype}"
105
+ end
106
+
107
+ self.query("SET NAMES '#{self.esc(@encoding)}'") if @encoding
104
108
  end
105
-
106
- self.query("SET NAMES '#{self.esc(@encoding)}'") if @encoding
107
109
  end
108
110
 
109
111
  #Executes a query and returns the result.
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: knjrbfw
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.97
5
+ version: 0.0.98
6
6
  platform: ruby
7
7
  authors:
8
8
  - Kasper Johansen
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2012-09-13 00:00:00 Z
13
+ date: 2012-09-18 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: wref
@@ -390,7 +390,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
390
390
  requirements:
391
391
  - - ">="
392
392
  - !ruby/object:Gem::Version
393
- hash: -3777771227131467790
393
+ hash: 73923719738851392
394
394
  segments:
395
395
  - 0
396
396
  version: "0"