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
@@ -0,0 +1,37 @@
note
description: "Summary description for {CMS_STORAGE_STORE_MYSQL}."
date: "$Date: 2015-02-09 22:29:56 +0100 (lun., 09 févr. 2015) $"
revision: "$Revision: 96596 $"
class
CMS_STORAGE_STORE_MYSQL
inherit
CMS_STORAGE_STORE_SQL
CMS_CORE_STORAGE_SQL_I
CMS_USER_STORAGE_SQL_I
REFACTORING_HELPER
create
make
feature -- Status report
is_initialized: BOOLEAN
-- Is storage initialized?
do
Result := has_user
end
feature -- Conversion
sql_statement (a_statement: STRING): STRING
-- <Precursor>
do
Result := a_statement
end
end
@@ -0,0 +1,48 @@
note
description: "[
Interface responsible to instantiate CMS_STORAGE_STORE_MYSQL object.
]"
author: "$Author: jfiat $"
date: "$Date: 2015-01-27 19:15:02 +0100 (mar., 27 janv. 2015) $"
revision: "$Revision: 96542 $"
class
CMS_STORAGE_STORE_MYSQL_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_MYSQL
local
conn: DATABASE_CONNECTION
do
if attached (create {APPLICATION_JSON_CONFIGURATION_HELPER}).new_database_configuration (a_setup.environment.application_config_path) as l_database_config then
create {DATABASE_CONNECTION_MYSQL} conn.login_with_connection_string (l_database_config.connection_string)
if conn.is_connected then
create Result.make (conn)
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
end
end
end
@@ -0,0 +1,115 @@
note
description: "Object that handle a database connection for ODBC"
date: "$Date: 2014-08-20 15:21:15 -0300 (mi., 20 ago. 2014) $"
revision: "$Revision: 95678 $"
class
DATABASE_CONNECTION_MYSQL
inherit
DATABASE_CONNECTION
redefine
db_application
end
create
login, login_with_default, login_with_database_name, login_with_connection_string, login_with_schema
feature -- Initialization
login_with_default
-- Create a database handler for MYSQL with common settings.
do
login_with_database_name (default_database_name)
end
login_with_database_name (a_database_name: STRING)
-- Create a database handler and
-- set database_name to `a_database_name'.
do
login (default_username, default_password, default_hostname, a_database_name, is_keep_connection)
end
login (a_username: STRING; a_password: STRING; a_hostname: STRING; a_database_name: STRING; connection: BOOLEAN)
-- Create a database handler for ODBC and set `username' to `a_username',
-- `password' to `a_password'
-- `database_name' to `a_database_name'
-- `connection' to `a_connection'
do
create database_error_handler.make
create db_application.login (a_username, a_password)
db_application.set_hostname (a_hostname)
db_application.set_data_source (a_database_name)
db_application.set_base
create db_control.make
keep_connection := connection
if keep_connection then
connect
end
end
login_with_connection_string (a_string: STRING)
-- Login with `a_connection_string' and immediately connect to database.
local
l_server: STRING
l_port: STRING
l_database: STRING
l_user: STRING
l_password: STRING
do
create database_error_handler.make
l_server := connection_string_item (a_string, "Server", default_hostname)
l_database := connection_string_item (a_string, "Database", default_database_name)
l_port := connection_string_item (a_string, "Port", "3306")
l_user := connection_string_item (a_string, "Uid", default_username)
l_password := connection_string_item (a_string, "Pwd", default_password)
create db_application
db_application.set_application (l_database)
db_application.set_hostname (l_server + ":" + l_port)
db_application.login_and_connect (l_user, l_password)
db_application.set_base
create db_control.make
keep_connection := is_keep_connection
end
connection_string_item (a_connection_string: STRING; k: STRING; dft: STRING): STRING
local
i,j: INTEGER
do
i := a_connection_string.substring_index (k + "=", 1)
if i = 0 then
i := a_connection_string.substring_index (k.as_lower + "=", 1)
end
if i > 0 then
i := i + k.count + 1
j := a_connection_string.index_of (';', i)
if j = 0 then
j := a_connection_string.count + 1
end
Result := a_connection_string.substring (i, j - 1)
else
Result := dft
end
end
login_with_schema (a_schema: STRING; a_username: STRING; a_password: STRING)
-- Login with `a_connection_string'and immediately connect to database.
do
create database_error_handler.make
create db_application
db_application.set_application (a_schema)
db_application.login_and_connect (a_username, a_password)
db_application.set_base
create db_control.make
keep_connection := is_keep_connection
end
feature -- Databse Connection
db_application: DATABASE_APPL [MYSQL]
-- Database application.
end