Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
activerecord-monetdb-adapter
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
simcaq
activerecord-monetdb-adapter
Commits
1d7f2673
Commit
1d7f2673
authored
Jul 31, 2012
by
Pavel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
MonetDB adapter fixes
parent
8f9c53f6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
58 additions
and
28 deletions
+58
-28
adapter/lib/active_record/connection_adapters/monetdb_adapter.rb
.../lib/active_record/connection_adapters/monetdb_adapter.rb
+50
-25
lib/MonetDBData.rb
lib/MonetDBData.rb
+8
-3
No files found.
adapter/lib/active_record/connection_adapters/monetdb_adapter.rb
View file @
1d7f2673
...
...
@@ -24,6 +24,7 @@
# Refreshed by Martin Samson (2011)
require
'active_record/connection_adapters/abstract_adapter'
$LOAD_PATH
.
unshift
(
'/home/bunyan/Programming/MonetDB/or_adapter/monetdb-client-ruby-activerecord/lib/'
)
require
'MonetDB'
module
ActiveRecord
...
...
@@ -64,8 +65,9 @@ module ActiveRecord
def
type_cast
(
value
)
if
(
value
.
nil?
)
return
nil
elsif
(
type
==
:integer
&&
value
=~
/next value for "sys"."seq_(\d)*"/
)
r
e
turn
value
elsif
(
type
==
:integer
&&
value
=~
/next value for/
)
#r
e
turn
value
return
nil
else
super
end
...
...
@@ -117,8 +119,13 @@ module ActiveRecord
end
class
MonetDBAdapter
<
AbstractAdapter
class
BindSubstitution
<
Arel
::
Visitors
::
MySQL
include
Arel
::
Visitors
::
BindVisitor
end
def
initialize
(
connection
,
logger
,
connection_options
,
config
)
super
(
connection
,
logger
)
@visitor
=
BindSubstitution
.
new
self
@connection_options
,
@config
=
connection_options
,
config
connect
end
...
...
@@ -331,6 +338,10 @@ module ActiveRecord
return
result
end
def
primary_key
(
table
)
'id'
end
# Adds a new column to the named table.
# See TableDefinition#column for details of the options you can use.
...
...
@@ -346,7 +357,7 @@ module ActiveRecord
# Return an array with all non-system table names of the current
# database schema
def
tables
(
name
=
nil
)
cur_schema
=
select_value
(
"select current_schema"
,
name
)
cur_schema
=
select_value
(
"select current_schema"
,
name
)
select_values
(
" SELECT t.name FROM sys._tables t, sys.schemas s
WHERE s.name = '
#{
cur_schema
}
'
AND t.schema_id = s.id
...
...
@@ -423,13 +434,21 @@ module ActiveRecord
end
def
execute
(
sql
,
name
=
nil
)
# This substitution is needed.
#puts "execute: #{sql}"
# This substitution is needed.
sql
=
sql
.
gsub
(
'!='
,
'<>'
)
sql
+=
';'
#log(sql, name) do
hdl
=
@connection
.
query
(
sql
)
#end
end
@connection
.
query
(
sql
)
end
def
exec_query
(
sql
,
name
=
nil
,
binds
=
[])
#puts "exec_query: #{sql}"
@connection
.
query
(
sql
)
end
def
last_inserted_id
(
result
)
result
.
last_insert_id
end
# Begins the transaction.
def
begin_db_transaction
...
...
@@ -483,29 +502,35 @@ module ActiveRecord
protected
# Returns an array of record hashes with the column names as keys and
# column values as values.
def
select
(
sql
,
name
=
nil
)
hdl
=
execute
(
sql
,
name
)
fields
=
[]
# restructure result returned by execute
def
process_hdl
(
hdl
)
result
=
[]
if
(
(
num_rows
=
hdl
.
num_rows
)
>
0
)
if
(
num_rows
=
hdl
.
num_rows
)
>
0
fields
=
hdl
.
name_fields
# Must do a successful mapi_fetch_row first
row_hash
=
{}
fields
.
each_with_index
do
|
f
,
i
|
row_hash
[
f
]
=
hdl
.
fetch_column_name
(
f
)
num_rows
.
times
do
result
<<
{}
end
fields
.
each
do
|
f
|
cols
=
hdl
.
fetch_column_name
(
f
)
cols
.
each_with_index
do
|
val
,
i
|
result
[
i
][
f
]
=
val
end
result
<<
row_hash
end
end
result
end
# Returns an array of record hashes with the column names as keys and
# column values as values.
def
select
(
sql
,
name
=
nil
,
binds
=
[])
hdl
=
execute
(
sql
,
name
)
process_hdl
(
hdl
)
end
# Executes the update statement and returns the number of rows affected.
def
update_sql
(
sql
,
name
=
nil
)
...
...
lib/MonetDBData.rb
View file @
1d7f2673
...
...
@@ -26,7 +26,8 @@ require 'MonetDBConnection'
require
'logger'
class
MonetDBData
@@DEBUG
=
false
@@DEBUG
=
false
attr_accessor
:last_insert_id
,
:affected_rows
def
initialize
(
connection
)
@connection
=
connection
...
...
@@ -39,7 +40,6 @@ class MonetDBData
@record_set
=
[]
@index
=
0
# Position of the last returned record
@row_count
=
0
@row_offset
=
10
@row_index
=
Integer
(
REPLY_SIZE
)
...
...
@@ -133,7 +133,7 @@ class MonetDBData
col
=
Array
.
new
# Scan the record set by row
@record_set
.
each
do
|
row
|
col
<<
parse_tuple
(
row
[
position
])
col
<<
parse_tuple
(
row
)[
position
]
end
return
col
...
...
@@ -205,6 +205,11 @@ class MonetDBData
@action
=
Q_TRANSACTION
elsif
row
[
1
].
chr
==
Q_CREATE
@action
=
Q_CREATE
elsif
row
[
1
].
chr
==
Q_UPDATE
@action
=
Q_UPDATE
result
=
row
.
split
(
' '
)
@affected_rows
=
result
[
1
].
to_i
@last_insert_id
=
result
[
2
].
to_i
end
elsif
row
[
0
].
chr
==
MSG_INFO
raise
MonetDBQueryError
,
row
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment