MYSQLSafe 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -32,17 +32,22 @@ MYSQLSafe allows you to optionally set
32
32
  + password
33
33
  + encoding
34
34
 
35
+
35
36
  safe_sql_connect = MYSQLSafe::Base.new()
36
37
  safe_sql_connect.user = 'username'
37
38
  safe_sql_connect.host = 'myhost'
38
39
  safe_sql_connect.password = ENV['MYSQLPASSWORD']
39
40
  safe_sql_connect.database = 'databasename'
40
- safe_sql_connect.encoding = 'iso-8859-1' # otherwise defaults to utf-8
41
+ safe_sql_connect.encoding = 'iso-8859-1' # otherwise defaults to 'utf-8'
41
42
 
42
43
  MYSQLSafe has one other public function which allows you to pass a MYSQL query
43
44
 
44
45
  safe_sql_connect.connect_safe("SELECT * FROM tablename LIMIT 1;")
45
46
 
47
+ And it returns an Array
48
+
49
+ #=> [["1", "Sam", "Areas Of My Expertise"], ["2", "Caz", "1Q84"], ["3", "Kyle", "How I Became A Famous Novelist"]]
50
+
46
51
  ## Contributing
47
52
 
48
53
  1. Fork it
@@ -69,7 +69,7 @@ module MYSQLSafe
69
69
  column_names_results_sql = @cxtn.query(column_names_sql)
70
70
 
71
71
  column_names_results_sql.each do |name|
72
- column_names.push(name)
72
+ column_names.push(name[0])
73
73
  end
74
74
  end
75
75
 
@@ -1,3 +1,3 @@
1
1
  module MYSQLSafe
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -1,6 +1,8 @@
1
1
  require_relative '../../test_helper.rb'
2
2
 
3
3
  describe MYSQLSafe::Base do
4
+
5
+ help = TestHelpers.new()
4
6
 
5
7
  before do
6
8
  @obj = MYSQLSafe::Base.new
@@ -34,18 +36,14 @@ describe MYSQLSafe::Base do
34
36
  end
35
37
 
36
38
  it "should allow connections to be made, and return an array" do
37
- encoding_name = 'utf-8'
38
- @obj.encoding = encoding_name
39
- username = 'sam'
40
- @obj.user = username
41
- hostname = 'localhost'
42
- @obj.host = hostname
43
- database_name = 'test'
44
- @obj.database = database_name
45
- password_key = ENV['MYSQLPASSWORD'] || "password"
46
- @obj.password = password_key
47
-
39
+ @obj = help.set_variables(@obj)
48
40
  success = @obj.connect_safe("SELECT * FROM performance_test LIMIT 1")
49
41
  success.must_be_instance_of Array
50
42
  end
43
+
44
+ it "should allow table=value syntax" do
45
+ @obj = help.set_variables(@obj)
46
+ success = @obj.connect_safe("SELECT * FROM performance_test WHERE test_int=1 LIMIT 1")
47
+ success.must_be_instance_of Array
48
+ end
51
49
  end
data/test/test_helper.rb CHANGED
@@ -1,3 +1,42 @@
1
1
  require 'minitest/autorun'
2
2
  require 'minitest/pride'
3
3
  require File.expand_path('../../lib/MYSQLSafe.rb', __FILE__)
4
+
5
+ class TestHelpers
6
+ attr_accessor :encoding_name, :hostname_name, :user_name, :database_name, :password_name
7
+ def set_encoding(obj)
8
+ @encoding_name = 'utf-8'
9
+ obj.encoding = @encoding_name
10
+ return obj
11
+ end
12
+ def set_user(obj)
13
+ @user_name = 'sam'
14
+ obj.user = @user_name
15
+ return obj
16
+ end
17
+ def set_hostname(obj)
18
+ @hostname_name = 'localhost'
19
+ obj.host = @hostname_name
20
+ return obj
21
+ end
22
+ def set_database(obj)
23
+ @database_name = 'test'
24
+ obj.database = @database_name
25
+ return obj
26
+ end
27
+ def set_password(obj)
28
+ @password_name = ENV['MYSQLPASSWORD'] || "password"
29
+ obj.password = @password_name
30
+ return obj
31
+ end
32
+
33
+ def set_variables(obj)
34
+ obj = set_encoding(obj)
35
+ obj = set_user(obj)
36
+ obj = set_hostname(obj)
37
+ obj = set_database(obj)
38
+ obj = set_password(obj)
39
+
40
+ return obj
41
+ end
42
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: MYSQLSafe
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-09-03 00:00:00.000000000 Z
12
+ date: 2013-09-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler