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:
82
library/persistence/store_odbc/src/cms_storage_store_odbc.e
Normal file
82
library/persistence/store_odbc/src/cms_storage_store_odbc.e
Normal file
@@ -0,0 +1,82 @@
|
||||
note
|
||||
description: "Summary description for {CMS_STORAGE_STORE_ODBC}."
|
||||
date: "$Date: 2015-02-09 22:29:56 +0100 (lun., 09 févr. 2015) $"
|
||||
revision: "$Revision: 96596 $"
|
||||
|
||||
class
|
||||
CMS_STORAGE_STORE_ODBC
|
||||
|
||||
inherit
|
||||
CMS_STORAGE_STORE_SQL
|
||||
redefine
|
||||
make
|
||||
end
|
||||
|
||||
CMS_CORE_STORAGE_SQL_I
|
||||
|
||||
CMS_USER_STORAGE_SQL_I
|
||||
|
||||
REFACTORING_HELPER
|
||||
|
||||
create
|
||||
make,
|
||||
make_with_driver
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make (a_connection: DATABASE_CONNECTION)
|
||||
-- <Precursor>
|
||||
do
|
||||
Precursor (a_connection)
|
||||
create odbc_driver.make_from_string_general ("odbc")
|
||||
end
|
||||
|
||||
make_with_driver (a_connection: DATABASE_CONNECTION; a_driver: detachable READABLE_STRING_GENERAL)
|
||||
require
|
||||
is_connected: a_connection.is_connected
|
||||
do
|
||||
make (a_connection)
|
||||
if a_driver /= Void then
|
||||
create odbc_driver.make_from_string_general (a_driver)
|
||||
end
|
||||
end
|
||||
|
||||
feature -- Status report
|
||||
|
||||
odbc_driver: IMMUTABLE_STRING_32
|
||||
-- Database's driver name.
|
||||
-- sqlite, mysql, ...
|
||||
|
||||
is_initialized: BOOLEAN
|
||||
-- Is storage initialized?
|
||||
do
|
||||
Result := has_user
|
||||
end
|
||||
|
||||
feature -- Conversion
|
||||
|
||||
sql_statement (a_statement: STRING): STRING
|
||||
-- <Precursor>.
|
||||
local
|
||||
i: INTEGER
|
||||
do
|
||||
Result := a_statement
|
||||
if odbc_driver.same_caseless_characters_general ("sqlite3", 1, 5, 1) then
|
||||
from
|
||||
i := 1
|
||||
until
|
||||
i = 0
|
||||
loop
|
||||
i := a_statement.substring_index ("AUTO_INCREMENT", i)
|
||||
if i > 0 then
|
||||
if Result = a_statement then
|
||||
create Result.make_from_string (a_statement)
|
||||
end
|
||||
Result.remove (i + 4)
|
||||
i := i + 14
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
@@ -0,0 +1,68 @@
|
||||
note
|
||||
description: "[
|
||||
Interface responsible to instantiate CMS_STORAGE_STORE_ODBC object.
|
||||
]"
|
||||
author: "$Author: jfiat $"
|
||||
date: "$Date: 2015-02-13 13:08:13 +0100 (ven., 13 févr. 2015) $"
|
||||
revision: "$Revision: 96616 $"
|
||||
|
||||
class
|
||||
CMS_STORAGE_STORE_ODBC_BUILDER
|
||||
|
||||
inherit
|
||||
CMS_STORAGE_STORE_SQL_BUILDER
|
||||
|
||||
GLOBAL_SETTINGS
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make
|
||||
-- Initialize `Current'.
|
||||
do
|
||||
end
|
||||
|
||||
feature -- Factory
|
||||
|
||||
storage (a_setup: CMS_SETUP): detachable CMS_STORAGE_STORE_ODBC
|
||||
local
|
||||
s: detachable STRING
|
||||
conn: detachable DATABASE_CONNECTION
|
||||
do
|
||||
if
|
||||
attached (create {APPLICATION_JSON_CONFIGURATION_HELPER}).new_database_configuration (a_setup.environment.application_config_path) as l_database_config
|
||||
then
|
||||
if l_database_config.driver.is_case_insensitive_equal ("odbc") then
|
||||
s := l_database_config.database_string
|
||||
if attached reuseable_connection.item as d then
|
||||
if s.same_string (d.name) then
|
||||
conn := d.connection
|
||||
end
|
||||
end
|
||||
if conn = Void or else not conn.is_connected then
|
||||
create {DATABASE_CONNECTION_ODBC} conn.login_with_connection_string (s)
|
||||
reuseable_connection.replace ([s, conn])
|
||||
end
|
||||
if conn.is_connected then
|
||||
create Result.make_with_driver (conn, l_database_config.item ("Driver"))
|
||||
set_map_zero_null_value (False) --| This way we map 0 to 0, instead of Null as default.
|
||||
if Result.is_available then
|
||||
if not Result.is_initialized then
|
||||
initialize (a_setup, Result)
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
-- Wrong mapping between storage name and storage builder!
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
reuseable_connection: CELL [detachable TUPLE [name: STRING; connection: DATABASE_CONNECTION]]
|
||||
once
|
||||
create Result.put (Void)
|
||||
end
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user