Skip to content

Commit

Permalink
- Database scripts added.
Browse files Browse the repository at this point in the history
- Unused store procedures removed from application core.
  • Loading branch information
Luis Lema committed Feb 16, 2020
1 parent 36e8bf6 commit e73948b
Show file tree
Hide file tree
Showing 95 changed files with 2,451 additions and 142 deletions.
16 changes: 16 additions & 0 deletions Database/CONFIG/Create_CONFIG_database.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

------------------------------------------------------------------------------
-- Create date: 2020-02-15
-- Autor: Luis Lema
--
-- Description:
-- Create database file for Firebird Engine. This database will be used to
-- store configurations used by application.
-- The name of this database depends of the name of application executable
-- file plus .dat extension.
------------------------------------------------------------------------------

CREATE DATABASE 'DATABASE_FILE_PATH\CONFIG.dat'
USER 'SYSDBA'
PAGE_SIZE = 4096
DEFAULT CHARACTER SET NONE;
3 changes: 3 additions & 0 deletions Database/CONFIG/Generators/APPCONFIG_ID_GEN.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/* Definition for the APPCONFIG_ID_GEN generator : */

CREATE GENERATOR APPCONFIG_ID_GEN;
3 changes: 3 additions & 0 deletions Database/CONFIG/Generators/CONNSTR_ID_GEN.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/* Definition for the CONNSTR_ID_GEN generator : */

CREATE GENERATOR CONNSTR_ID_GEN;
32 changes: 32 additions & 0 deletions Database/CONFIG/Procedures/GET_STR.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/* Definition for the GET_STR procedure : */

------------------------------------------------------------------------------
-- Create date: 2020-02-15
-- Autor: Luis Lema
--
-- Description:
-- Get the value of a connection string.
--
-- Parameters:
-- IDKEY - The name of connection string, this value is unique across others.
--
-- Returns:
-- The value of connection string.
------------------------------------------------------------------------------

CREATE OR ALTER PROCEDURE GET_STR
(
IDKEY TYPE OF COLUMN CONNSTR.IDKEY
)
RETURNS
(
VAL TYPE OF COLUMN CONNSTR.STR
)
AS
BEGIN
FOR SELECT STR FROM CONNSTR
WHERE
IDKEY=:IDKEY
INTO :VAL
DO SUSPEND;
END
33 changes: 33 additions & 0 deletions Database/CONFIG/Procedures/GET_VALUE.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/* Definition for the GET_VALUE procedure : */

------------------------------------------------------------------------------
-- Create date: 2020-02-15
-- Autor: Luis Lema
--
-- Description:
-- Get the value of a configuration.
--
-- Parameters:
-- IDKEY - The name of configuration, this value is unique across others.
--
-- Returns:
-- The value of configuration.
------------------------------------------------------------------------------

CREATE OR ALTER PROCEDURE GET_VALUE
(
IDKEY TYPE OF COLUMN APPCONFIG.IDKEY
)
RETURNS
(
RESULT TYPE OF COLUMN APPCONFIG.VAL
)
AS
BEGIN
FOR SELECT VAL FROM APPCONFIG
WHERE
IDKEY=:IDKEY
INTO
:RESULT
DO SUSPEND;
END
25 changes: 25 additions & 0 deletions Database/CONFIG/Procedures/SET_STR.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/* Definition for the SET_STR procedure : */

------------------------------------------------------------------------------
-- Create date: 2020-02-15
-- Autor: Luis Lema
--
-- Description:
-- Set the value of a connection string.
--
-- Parameters:
-- IDKEY - The name of connection string, this value is unique across others.
-- VAL - The connections string.
------------------------------------------------------------------------------

CREATE OR ALTER PROCEDURE SET_STR
(
IDKEY TYPE OF COLUMN CONNSTR.IDKEY,
VAL TYPE OF COLUMN CONNSTR.STR
)
AS
BEGIN
UPDATE OR INSERT INTO CONNSTR(IDKEY,STR)
VALUES(:IDKEY,:VAL)
MATCHING(IDKEY);
END
23 changes: 23 additions & 0 deletions Database/CONFIG/Procedures/SET_VALUE.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/* Definition for the SET_VALUE procedure : */

------------------------------------------------------------------------------
-- Create date: 2020-02-15
-- Autor: Luis Lema
--
-- Description:
-- Set the value of a configuration.
--
-- Parameters:
-- IDKEY - The name of configuration, this value is unique across others.
-- VAL - The value.
------------------------------------------------------------------------------

CREATE OR ALTER PROCEDURE SET_VALUE(
IDKEY TYPE OF COLUMN APPCONFIG.IDKEY,
VAL TYPE OF COLUMN APPCONFIG.VAL)
AS
BEGIN
UPDATE OR INSERT INTO APPCONFIG(IDKEY,VAL)
VALUES(:IDKEY,:VAL)
MATCHING(IDKEY);
END
36 changes: 36 additions & 0 deletions Database/CONFIG/Procedures/VERIFY_INITIALIZATION.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/* Definition for the VERIFY_INITIALIZATION procedure : */

------------------------------------------------------------------------------
-- Create date: 2020-02-15
-- Autor: Luis Lema
--
-- Description:
-- Verify if configurations have been added.
--
-- Returns:
-- True if there are configurations otherwise false.
------------------------------------------------------------------------------

CREATE OR ALTER PROCEDURE VERIFY_INITIALIZATION
RETURNS
(
IS_INITIALIZED BOOLEAN
)
AS
DECLARE VARIABLE COUNTER INT;
BEGIN
SELECT COUNT(1)FROM APPCONFIG
INTO :COUNTER;

COUNTER=COUNTER+(SELECT COUNT(1)FROM CONNSTR);

IF(:COUNTER=0)THEN
BEGIN
:IS_INITIALIZED='FALSE';
END
ELSE
BEGIN
:IS_INITIALIZED='TRUE';
END

END
9 changes: 9 additions & 0 deletions Database/CONFIG/Tables/APPCONFIG.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/* Structure for the APPCONFIG table : */

CREATE TABLE APPCONFIG (
ID INTEGER NOT NULL,
IDKEY VARCHAR(190) NOT NULL,
VAL BLOB);


ALTER TABLE APPCONFIG ADD CONSTRAINT PK_APPCONFIG PRIMARY KEY (ID,IDKEY);
8 changes: 8 additions & 0 deletions Database/CONFIG/Tables/CONNSTR.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/* Structure for the CONNSTR table : */

CREATE TABLE CONNSTR (
ID INTEGER NOT NULL,
IDKEY VARCHAR(190) NOT NULL,
STR BLOB);

ALTER TABLE CONNSTR ADD CONSTRAINT PK_CONNSTR PRIMARY KEY (ID,IDKEY);
11 changes: 11 additions & 0 deletions Database/CONFIG/Triggers/BI_APPCONFIG_ID.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* Definition for the BI_APPCONFIG_ID trigger : */

CREATE TRIGGER BI_APPCONFIG_ID FOR APPCONFIG
ACTIVE BEFORE
INSERT
POSITION 0
AS
BEGIN
IF (NEW.ID IS NULL) THEN
NEW.ID = GEN_ID(APPCONFIG_ID_GEN, 1);
END
13 changes: 13 additions & 0 deletions Database/CONFIG/Triggers/BI_CONNSTR_ID.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/* Definition for the BI_CONNSTR_ID trigger : */

SET TERM ^ ;

CREATE TRIGGER BI_CONNSTR_ID FOR CONNSTR
ACTIVE BEFORE
INSERT
POSITION 0
AS
BEGIN
IF (NEW.ID IS NULL) THEN
NEW.ID = GEN_ID(CONNSTR_ID_GEN, 1);
END
15 changes: 15 additions & 0 deletions Database/KH/Create_KH_database.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

------------------------------------------------------------------------------
-- Create date: 2020-02-15
-- Autor: Luis Lema
--
-- Description:
-- Create database file for Firebird Engine. This database will be used to
-- store data used by application.
-- The name of this database is E7FE8601FEAE and has a .KND extension.
------------------------------------------------------------------------------

CREATE DATABASE 'DATABASE_FILE_PATH\E7FE8601FEAE.KND'
USER 'SYSDBA'
PAGE_SIZE = 4096
DEFAULT CHARACTER SET NONE;
3 changes: 3 additions & 0 deletions Database/KH/Generators/ACCOUNT_ID_GEN.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/* Definition for the ACCOUNT_ID_GEN generator : */

CREATE GENERATOR ACCOUNT_ID_GEN;
3 changes: 3 additions & 0 deletions Database/KH/Generators/ANIMATION_ID_GEN.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/* Definition for the ANIMATION_ID_GEN generator : */

CREATE GENERATOR ANIMATION_ID_GEN;
3 changes: 3 additions & 0 deletions Database/KH/Generators/MESSAGE_FILE_ID_GEN.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/* Definition for the MESSAGE_FILE_ID_GEN generator : */

CREATE GENERATOR MESSAGE_FILE_ID_GEN;
3 changes: 3 additions & 0 deletions Database/KH/Generators/MESSAGE_ID_GEN.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/* Definition for the MESSAGE_ID_GEN generator : */

CREATE GENERATOR MESSAGE_ID_GEN;
3 changes: 3 additions & 0 deletions Database/KH/Generators/MESSAGE_TEXT_ID_GEN.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/* Definition for the MESSAGE_TEXT_ID_GEN generator : */

CREATE GENERATOR MESSAGE_TEXT_ID_GEN;
3 changes: 3 additions & 0 deletions Database/KH/Generators/PEER_ADDRESS_ID_GEN.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/* Definition for the PEER_ADDRESS_ID_GEN generator : */

CREATE GENERATOR PEER_ADDRESS_ID_GEN;
3 changes: 3 additions & 0 deletions Database/KH/Generators/PEER_ID_GEN.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/* Definition for the PEER_ID_GEN generator : */

CREATE GENERATOR PEER_ID_GEN;
36 changes: 36 additions & 0 deletions Database/KH/Procedures/BULK_MARK_AS_READ_MESSAGE.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/* Definition for the BULK_MARK_AS_READ_MESSAGE procedure : */

------------------------------------------------------------------------------
-- Create date: 2020-02-15
-- Autor: Luis Lema
--
-- Description:
-- Mark messages as read as a whole
--
-- Parameters:
-- LAST_MESSAGE_ID - The last message to be marked, all earlier ones
-- will be marked too
------------------------------------------------------------------------------

CREATE OR ALTER PROCEDURE BULK_MARK_AS_READ_MESSAGE
(
LAST_MESSAGE_ID TYPE OF COLUMN MESSAGE.ID
)
AS
DECLARE VARIABLE ID_SENDER INTEGER;
BEGIN
ID_SENDER=(SELECT ID FROM MESSAGE WHERE ID=:LAST_MESSAGE_ID);

UPDATE MESSAGE
SET READ_STATE='TRUE'
WHERE
ID<=:LAST_MESSAGE_ID
AND READ_STATE='FALSE';

DELETE FROM NOTIFICATION
WHERE
ID_TOKEN=:ID_SENDER
AND PROCESSED='FALSE'
AND TYPE_NOT=0;

END
15 changes: 15 additions & 0 deletions Database/KH/Procedures/CLEAR_NOTIFICATIONS.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* Definition for the CLEAR_NOTIFICATIONS procedure : */

------------------------------------------------------------------------------
-- Create date: 2020-02-15
-- Autor: Luis Lema
--
-- Description:
-- Deletes all notifications.
------------------------------------------------------------------------------

CREATE OR ALTER PROCEDURE CLEAR_NOTIFICATIONS
AS
BEGIN
DELETE FROM NOTIFICATION;
END
15 changes: 15 additions & 0 deletions Database/KH/Procedures/CLEAR_PARTIAL_MESSAGES.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* Definition for the CLEAR_PARTIAL_MESSAGES procedure : */

------------------------------------------------------------------------------
-- Create date: 2020-02-15
-- Autor: Luis Lema
--
-- Description:
-- Deletes all messages fragments used when sending text messages.
------------------------------------------------------------------------------

CREATE OR ALTER PROCEDURE CLEAR_PARTIAL_MESSAGES
AS
BEGIN
DELETE FROM PARTIAL_MESSAGE;
END
16 changes: 16 additions & 0 deletions Database/KH/Procedures/CLEAR_PEERS.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/* Definition for the CLEAR_PEERS procedure : */

------------------------------------------------------------------------------
-- Create date: 2020-02-15
-- Autor: Luis Lema
--
-- Description:
-- Deletes peer information like address, name and so on.
------------------------------------------------------------------------------

CREATE OR ALTER PROCEDURE CLEAR_PEERS
AS
BEGIN
DELETE FROM PEER_ADDRESS;
DELETE FROM PEER;
END
16 changes: 16 additions & 0 deletions Database/KH/Procedures/CLEAR_PEER_STATE.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/* Definition for the CLEAR_PEER_STATE procedure : */

------------------------------------------------------------------------------
-- Create date: 2020-02-15
-- Autor: Luis Lema
--
-- Description:
-- Set all peers' state as offline
------------------------------------------------------------------------------

CREATE OR ALTER PROCEDURE CLEAR_PEER_STATE
AS
BEGIN
UPDATE PEER
SET STATE=0; --Offline state
END
Loading

0 comments on commit e73948b

Please sign in to comment.