Fixed persistency layer.

Now we have ODBC .. that accepts various connection string (including SQLite, MySQL,...)
  And EiffelStore+MySQL.
Updated sql scripts to work with MySQL, and SQLite.
Added a sql_statement (s: STRING): STRING that converts ROC sql statement to fit the underlying database engine.
 mostly to adapt incompatibilities such as AUTO_INCREMENT for MySQL and AUTOINCREMENT for SQLite
 by default SQL script should be written following MySQL SQL syntax.
Warning: to use ODBC persistence driver, it has to be installed on the target machine.
This commit is contained in:
2015-06-18 13:55:05 +02:00
parent e37dbb0a62
commit f619727997
45 changed files with 1235 additions and 662 deletions

View File

@@ -109,4 +109,12 @@ feature -- Access
Result:= sql_storage.sql_item (a_index)
end
feature -- Conversion
sql_statement (a_statement: STRING): STRING
-- <Precursor>
do
Result := sql_storage.sql_statement (a_statement)
end
end

View File

@@ -150,22 +150,42 @@ feature -- Helper
sql_execute_script (a_sql_script: STRING)
-- Execute SQL script.
-- i.e: multiple SQL statements.
local
i: INTEGER
err: BOOLEAN
do
reset_error
-- sql_begin_transaction
sql_change (a_sql_script, Void)
-- sql_commit_transaction
sql_begin_transaction
-- Issue on MySQL with multiple statements
-- sql_change (a_sql_script, Void)
from
i := 1
until
i > a_sql_script.count or err
loop
if attached next_sql_statement (a_sql_script, i) as s then
if not s.is_whitespace then
sql_change (sql_statement (s), Void)
err := err or has_error
reset_error
end
i := i + s.count
else
i := a_sql_script.count + 1
end
end
if err then
sql_rollback_transaction
else
sql_commit_transaction
end
end
sql_table_exists (a_table_name: READABLE_STRING_8): BOOLEAN
-- Does table `a_table_name' exists?
local
l_params: STRING_TABLE [detachable ANY]
do
reset_error
create l_params.make (1)
l_params.force (a_table_name, "tbname")
sql_query ("SELECT count(*) FROM :tbname ;", l_params)
sql_query ("SELECT count(*) FROM " + a_table_name + " ;", Void)
Result := not has_error
-- FIXME: find better solution
reset_error
@@ -173,13 +193,9 @@ feature -- Helper
sql_table_items_count (a_table_name: READABLE_STRING_8): INTEGER_64
-- Number of items in table `a_table_name'?
local
l_params: STRING_TABLE [detachable ANY]
do
reset_error
create l_params.make (1)
l_params.force (a_table_name, "tbname")
sql_query ("SELECT count(*) FROM :tbname ;", l_params)
sql_query ("SELECT count(*) FROM " + a_table_name + " ;", Void)
if not has_error then
Result := sql_read_integer_64 (1)
end
@@ -325,4 +341,57 @@ feature -- Access
end
end
feature -- Conversion
sql_statement (a_statement: STRING): STRING
-- Statement normalized for underlying SQL database.
deferred
end
feature {NONE} -- Implementation
next_sql_statement (a_script: STRING; a_start_index: INTEGER): detachable STRING
local
i,j,n: INTEGER
c: CHARACTER
l_end: INTEGER
do
from
i := a_start_index
n := a_script.count
until
i > n or a_script[i] = ';'
loop
c := a_script[i]
inspect c
when '`', '"', '%'' then
from
j := i
l_end := 0
until
l_end > 0 or j > n
loop
j := a_script.index_of (c, i + 1)
if j > i then
if a_script [j - 1] /= '\' then
l_end := j
end
end
end
if l_end > 0 then
i := l_end
else
i := j
end
else
end
i := i + 1
end
i := a_script.index_of (';', a_start_index)
if i > a_start_index then
Result := a_script.substring (a_start_index, i)
end
end
end