Take into account database errors.
User and Node id are integer_64. Fixed sql_read_string
This commit is contained in:
@@ -32,6 +32,7 @@ feature {NONE} -- Initialization
|
||||
create {DATABASE_HANDLER_IMPL} db_handler.make (a_connection)
|
||||
|
||||
create error_handler.make
|
||||
-- error_handler.add_synchronization (db_handler.database_error_handler)
|
||||
end
|
||||
|
||||
db_handler: DATABASE_HANDLER
|
||||
@@ -44,7 +45,7 @@ feature -- Query
|
||||
sql_post_execution
|
||||
-- Post database execution.
|
||||
do
|
||||
-- error_handler.add_synchronization (db_handler.database_error_handler)
|
||||
error_handler.append (db_handler.database_error_handler)
|
||||
if error_handler.has_error then
|
||||
log.write_critical (generator + ".post_execution " + error_handler.as_string_representation)
|
||||
end
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
</option>
|
||||
<setting name="concurrency" value="thread"/>
|
||||
<library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf"/>
|
||||
<library name="cms" location="..\..\..\..\..\cms-safe.ecf"/>
|
||||
<library name="model" location="..\..\..\..\model\cms_model-safe.ecf"/>
|
||||
<library name="crypto" location="$ISE_LIBRARY\unstable\library\text\encryption\crypto\crypto-safe.ecf"/>
|
||||
<library name="persitence_mysql" location="..\persistence_mysql-safe.ecf" readonly="false"/>
|
||||
|
||||
@@ -31,6 +31,7 @@ feature {NONE} -- Initialization
|
||||
create {DATABASE_HANDLER_IMPL} db_handler.make (a_connection)
|
||||
|
||||
create error_handler.make
|
||||
-- error_handler.add_synchronization (db_handler.database_error_handler)
|
||||
end
|
||||
|
||||
db_handler: DATABASE_HANDLER
|
||||
@@ -43,7 +44,7 @@ feature -- Access: user
|
||||
sql_post_execution
|
||||
-- Post database execution.
|
||||
do
|
||||
-- error_handler.add_synchronization (db_handler.database_error_handler)
|
||||
error_handler.append (db_handler.database_error_handler)
|
||||
if error_handler.has_error then
|
||||
log.write_critical (generator + ".post_execution " + error_handler.as_string_representation)
|
||||
end
|
||||
|
||||
@@ -120,7 +120,7 @@ feature -- HTTP Methods
|
||||
if attached {WSF_STRING} req.path_parameter ("id") as l_id then
|
||||
if l_id.is_integer and then attached {CMS_NODE} api.node (l_id.integer_value) as l_node then
|
||||
u_node := extract_data_form (req)
|
||||
u_node.set_id (l_id.integer_value)
|
||||
u_node.set_id (l_id.value.to_integer_64)
|
||||
api.update_node_content (l_user.id, u_node.id, u_node.content)
|
||||
(create {CMS_GENERIC_RESPONSE}).new_response_redirect (req, res, req.absolute_script_url (""))
|
||||
else
|
||||
|
||||
@@ -124,7 +124,7 @@ feature -- HTTP Methods
|
||||
if attached {WSF_STRING} req.path_parameter ("id") as l_id then
|
||||
if l_id.is_integer and then attached {CMS_NODE} api.node (l_id.integer_value) as l_node then
|
||||
u_node := extract_data_form (req)
|
||||
u_node.set_id (l_id.integer_value)
|
||||
u_node.set_id (l_id.value.to_integer_64)
|
||||
api.update_node (l_user.id,u_node)
|
||||
(create {CMS_GENERIC_RESPONSE}).new_response_redirect (req, res, req.absolute_script_url (""))
|
||||
else
|
||||
|
||||
@@ -118,7 +118,7 @@ feature -- HTTP Methods
|
||||
if attached {WSF_STRING} req.path_parameter ("id") as l_id then
|
||||
if l_id.is_integer and then attached {CMS_NODE} api.node (l_id.integer_value) as l_node then
|
||||
u_node := extract_data_form (req)
|
||||
u_node.set_id (l_id.integer_value)
|
||||
u_node.set_id (l_id.value.to_integer_64)
|
||||
api.update_node_summary (l_user.id,u_node.id, u_node.summary)
|
||||
(create {CMS_GENERIC_RESPONSE}).new_response_redirect (req, res, req.absolute_script_url (""))
|
||||
else
|
||||
|
||||
@@ -118,7 +118,7 @@ feature -- HTTP Methods
|
||||
if attached {WSF_STRING} req.path_parameter ("id") as l_id then
|
||||
if l_id.is_integer and then attached {CMS_NODE} api.node (l_id.integer_value) as l_node then
|
||||
u_node := extract_data_form (req)
|
||||
u_node.set_id (l_id.integer_value)
|
||||
u_node.set_id (l_id.value.to_integer_64)
|
||||
api.update_node_title (l_user.id,u_node.id, u_node.title)
|
||||
(create {CMS_GENERIC_RESPONSE}).new_response_redirect (req, res, req.absolute_script_url (""))
|
||||
else
|
||||
|
||||
@@ -159,10 +159,22 @@ feature -- Handler
|
||||
local
|
||||
r: CMS_RESPONSE
|
||||
s: STRING
|
||||
l_user: CMS_USER
|
||||
l_node: CMS_NODE
|
||||
do
|
||||
create {NOT_IMPLEMENTED_ERROR_CMS_RESPONSE} r.make (req, res, a_api)
|
||||
|
||||
a_api.new_node (create {CMS_NODE}.make ("This is a body", "summary this node", "Oh a node"))
|
||||
if attached a_api.user_by_name ("foo") as u then
|
||||
l_user := u
|
||||
else
|
||||
create l_user.make ("foo")
|
||||
l_user.set_password ("foobar#")
|
||||
l_user.set_email ("jfiat@eiffel.com")
|
||||
a_api.new_user (l_user)
|
||||
end
|
||||
create l_node.make ({STRING_32} "This is a content", {STRING_32} "And a summary", {STRING_32} "Nice title")
|
||||
l_node.set_author (l_user)
|
||||
a_api.new_node (l_node)
|
||||
|
||||
create s.make_from_string ("<p>Sorry: listing the CMS nodes is not yet implemented.</p>")
|
||||
if attached a_api.nodes as lst then
|
||||
|
||||
@@ -95,7 +95,7 @@ feature -- Access
|
||||
l_item: like sql_item
|
||||
do
|
||||
l_item := sql_item (a_index)
|
||||
if attached {READABLE_STRING_32} l_item as l_string then
|
||||
if attached {READABLE_STRING_8} l_item as l_string then
|
||||
Result := l_string
|
||||
elseif attached {BOOLEAN} l_item as l_boolean then
|
||||
Result := l_boolean.out
|
||||
|
||||
@@ -111,14 +111,14 @@ feature -- Access
|
||||
sql_post_execution
|
||||
end
|
||||
|
||||
last_inserted_node_id: INTEGER
|
||||
last_inserted_node_id: INTEGER_64
|
||||
-- Last insert node id.
|
||||
do
|
||||
error_handler.reset
|
||||
log.write_information (generator + ".last_inserted_node_id")
|
||||
sql_query (Sql_last_insert_node_id, Void)
|
||||
if sql_rows_count = 1 then
|
||||
Result := sql_read_integer_32 (1)
|
||||
Result := sql_read_integer_64 (1)
|
||||
end
|
||||
sql_post_execution
|
||||
end
|
||||
@@ -133,6 +133,7 @@ feature -- Change: Node
|
||||
if a_node.has_id and attached a_node.author as l_author and then l_author.has_id then
|
||||
update_node (l_author.id, a_node)
|
||||
else
|
||||
-- New node
|
||||
error_handler.reset
|
||||
log.write_information (generator + ".save_node")
|
||||
create l_parameters.make (7)
|
||||
@@ -151,8 +152,11 @@ feature -- Change: Node
|
||||
l_parameters.put (0, "author_id")
|
||||
end
|
||||
sql_change (sql_insert_node, l_parameters)
|
||||
a_node.set_id (last_inserted_node_id)
|
||||
sql_post_execution
|
||||
if not error_handler.has_error then
|
||||
a_node.set_id (last_inserted_node_id)
|
||||
sql_post_execution
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -298,7 +302,7 @@ feature {NONE} -- Implementation
|
||||
fetch_node: CMS_NODE
|
||||
do
|
||||
create Result.make ("", "", "")
|
||||
if attached sql_read_integer_32 (1) as l_id then
|
||||
if attached sql_read_integer_64 (1) as l_id then
|
||||
Result.set_id (l_id)
|
||||
end
|
||||
if attached sql_read_date_time (2) as l_publication_date then
|
||||
|
||||
@@ -195,6 +195,8 @@ feature {NONE} -- Implementation
|
||||
|
||||
new_user (a_user: CMS_USER)
|
||||
-- Add a new user `a_user'.
|
||||
require
|
||||
no_id: not a_user.has_id
|
||||
local
|
||||
l_parameters: STRING_TABLE [detachable ANY]
|
||||
l_password_salt, l_password_hash: STRING
|
||||
@@ -217,6 +219,11 @@ feature {NONE} -- Implementation
|
||||
l_parameters.put (l_email, "email")
|
||||
|
||||
sql_change (sql_insert_user, l_parameters)
|
||||
sql_post_execution
|
||||
if not error_handler.has_error then
|
||||
a_user.set_id (last_inserted_user_id)
|
||||
sql_post_execution
|
||||
end
|
||||
else
|
||||
-- set error
|
||||
error_handler.add_custom_error (-1, "bad request" , "Missing password or email")
|
||||
@@ -258,11 +265,25 @@ feature {NONE} -- Implementation
|
||||
end
|
||||
end
|
||||
|
||||
last_inserted_user_id: INTEGER_64
|
||||
-- Last insert user id.
|
||||
do
|
||||
error_handler.reset
|
||||
log.write_information (generator + ".last_inserted_user_id")
|
||||
sql_query (Sql_last_insert_user_id, Void)
|
||||
if sql_rows_count = 1 then
|
||||
Result := sql_read_integer_64 (1)
|
||||
end
|
||||
sql_post_execution
|
||||
end
|
||||
|
||||
feature {NONE} -- Sql Queries: USER
|
||||
|
||||
Select_users_count: STRING = "select count(*) from Users;"
|
||||
-- Number of users.
|
||||
|
||||
Sql_last_insert_user_id: STRING = "SELECT MAX(id) from Users;"
|
||||
|
||||
Select_users: STRING = "select * from Users;"
|
||||
-- List of users.
|
||||
|
||||
@@ -279,7 +300,7 @@ feature {NONE} -- Sql Queries: USER
|
||||
-- Retrieve salt by username if exists.
|
||||
|
||||
SQL_Insert_user: STRING = "insert into users (username, password, salt, email) values (:username, :password, :salt, :email);"
|
||||
-- SQL Insert to add a new node.
|
||||
-- SQL Insert to add a new node.
|
||||
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user