oracle_query 0.1.1 → 0.1.2
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/lib/oracle_query.rb +79 -25
- metadata +2 -2
data/lib/oracle_query.rb
CHANGED
@@ -1,26 +1,80 @@
|
|
1
|
-
require 'oci8'
|
2
|
-
|
3
|
-
class Oracle
|
4
|
-
def initialize (username, password, db_connection)
|
5
|
-
@oci = OCI8.new(username, password, db_connection)
|
6
|
-
end
|
7
|
-
|
8
|
-
def select (query, var)
|
9
|
-
variable = var
|
10
|
-
@variable = []
|
11
|
-
@oci.exec(query) do |result|
|
12
|
-
@variable.push(result)
|
13
|
-
end
|
14
|
-
eval("$#{variable} = @variable")
|
15
|
-
end
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
@oci.
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
1
|
+
require 'oci8'
|
2
|
+
|
3
|
+
class Oracle
|
4
|
+
def initialize (username, password, db_connection)
|
5
|
+
@oci = OCI8.new(username, password, db_connection)
|
6
|
+
end
|
7
|
+
|
8
|
+
def select (query, var)
|
9
|
+
variable = var
|
10
|
+
@variable = []
|
11
|
+
@oci.exec(query) do |result|
|
12
|
+
@variable.push(result)
|
13
|
+
end
|
14
|
+
eval("$#{variable} = @variable")
|
15
|
+
end
|
16
|
+
|
17
|
+
#Set table name and values ["name = 'John', employee_id = 39994"]
|
18
|
+
def insert (table, values)
|
19
|
+
@oci.exec("INSERT INTO #{table} VALUES(#{values[0]})")
|
20
|
+
@oci.commit
|
21
|
+
end
|
22
|
+
|
23
|
+
#Set table name and values ["name = 'John', employee_id = 39994"]
|
24
|
+
def append (table, values)
|
25
|
+
@oci.exec("INSERT /*+ append */ INTO #{table} VALUES(#{values[0]})")
|
26
|
+
@oci.commit
|
27
|
+
end
|
28
|
+
|
29
|
+
#set Table name to truncate
|
30
|
+
def truncate (table)
|
31
|
+
@oci.exec("TRUNCATE TABLE #{table}")
|
32
|
+
@oci.commit
|
33
|
+
end
|
34
|
+
|
35
|
+
#set Table name, Values to update ["name = 'John', id = 30"], where columns = values
|
36
|
+
def update (table, values, where)
|
37
|
+
@oci.exec("UPDATE #{table} SET #{values[0]} WHERE #{where}")
|
38
|
+
@oci.commit
|
39
|
+
end
|
40
|
+
|
41
|
+
#Set table to name of table you wish to delete
|
42
|
+
#Set values for where column = values
|
43
|
+
#Set type to all if you want to remove all otherewise pass nil
|
44
|
+
def delete (table, values = '', type = '')
|
45
|
+
if type == "all"
|
46
|
+
@oci.exec("DELETE FROM #{table}")
|
47
|
+
@oci.commit
|
48
|
+
else
|
49
|
+
@oci.exec("DELETE FROM #{table} WHERE #{values}")
|
50
|
+
@oci.commit
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
#Set Object to either a table or database
|
55
|
+
#Set the value based on if its a table your droping or database
|
56
|
+
def drop (object, type)
|
57
|
+
if type == 'table'
|
58
|
+
@oci.exec("DROP #{object}")
|
59
|
+
@oci.commit
|
60
|
+
end
|
61
|
+
if type == 'database'
|
62
|
+
@oci.exec("DROP DATABASE #{object}")
|
63
|
+
@oci.commit
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
#Set table = TABLE_NAME;
|
68
|
+
#Set Values as an array [['column_name1', 'data_type'], ['column_name2', 'data_type'], ['column_name3', 'data_type']]
|
69
|
+
def create(table, values)
|
70
|
+
data_set = []
|
71
|
+
values.each{ |data|
|
72
|
+
data = data.join(" ")
|
73
|
+
data_set.push(data)
|
74
|
+
}
|
75
|
+
data_set = data_set.join(", ")
|
76
|
+
@oci.exec("CREATE TABLE #{table} (#{data_set})")
|
77
|
+
@oci.commit
|
78
|
+
end
|
79
|
+
|
26
80
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oracle_query
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -54,7 +54,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
54
54
|
version: '0'
|
55
55
|
requirements: []
|
56
56
|
rubyforge_project:
|
57
|
-
rubygems_version: 1.8.
|
57
|
+
rubygems_version: 1.8.25
|
58
58
|
signing_key:
|
59
59
|
specification_version: 3
|
60
60
|
summary: Oracle Query!
|