From 7dc56a7c2207f2fd40df910ad57337009f2c185c Mon Sep 17 00:00:00 2001 From: acanas Date: Wed, 24 Mar 2021 10:27:59 +0100 Subject: [PATCH] Version 20.51.38: Mar 24, 2021 API keys database table renamed. --- sql/swad.sql | 24 ++++++++++++------------ swad_API.c | 9 +++++---- swad_changelog.h | 6 +++++- swad_database.c | 46 +++++++++++++++++++++++----------------------- 4 files changed, 45 insertions(+), 40 deletions(-) diff --git a/sql/swad.sql b/sql/swad.sql index 3fb2d4f32..6fb3e4877 100644 --- a/sql/swad.sql +++ b/sql/swad.sql @@ -1,18 +1,6 @@ CREATE DATABASE IF NOT EXISTS swad DEFAULT CHARACTER SET=latin1 DEFAULT COLLATE latin1_spanish_ci; USE swad; -- --- Table API_keys: stores the keys used in the API / web service --- -CREATE TABLE IF NOT EXISTS API_keys ( - WSKey CHAR(43) NOT NULL, - UsrCod INT NOT NULL, - PlgCod INT NOT NULL, - LastTime DATETIME NOT NULL, - UNIQUE INDEX(WSKey), - INDEX(UsrCod), - INDEX(PlgCod), - INDEX(LastTime)); --- -- Table act_MFU: stores the recent actions more frequently made by each user -- CREATE TABLE IF NOT EXISTS act_MFU ( @@ -54,6 +42,18 @@ CREATE TABLE IF NOT EXISTS ann_seen ( UsrCod INT NOT NULL, UNIQUE INDEX(AnnCod,UsrCod)); -- +-- Table api_keys: stores the keys used in the API / web service +-- +CREATE TABLE IF NOT EXISTS api_keys ( + WSKey CHAR(43) NOT NULL, + UsrCod INT NOT NULL, + PlgCod INT NOT NULL, + LastTime DATETIME NOT NULL, + UNIQUE INDEX(WSKey), + INDEX(UsrCod), + INDEX(PlgCod), + INDEX(LastTime)); +-- -- Table asg_assignments: stores the assignments proposed by the teachers to their students -- CREATE TABLE IF NOT EXISTS asg_assignments ( diff --git a/swad_API.c b/swad_API.c index 951ed6afb..ed6212e09 100644 --- a/swad_API.c +++ b/swad_API.c @@ -465,7 +465,7 @@ static int API_CheckWSKey (char WSKey[API_BYTES_WS_KEY + 1]) if (DB_QuerySELECT (&mysql_res,"can not get existence of key", "SELECT UsrCod," // row[0] "PlgCod" // row[1] - " FROM API_keys" + " FROM api_keys" " WHERE WSKey='%s'", WSKey)) // Session found in table of sessions { @@ -543,7 +543,8 @@ static int API_GenerateNewWSKey (struct soap *soap, /***** Check that key does not exist in database *****/ if (DB_QueryCOUNT ("can not get existence of key", - "SELECT COUNT(*) FROM API_keys" + "SELECT COUNT(*)" + " FROM api_keys" " WHERE WSKey='%s'", WSKey)) return soap_receiver_fault (soap, @@ -552,7 +553,7 @@ static int API_GenerateNewWSKey (struct soap *soap, /***** Insert key into database *****/ DB_QueryINSERT ("can not insert new key", - "INSERT INTO API_keys" + "INSERT INTO api_keys" " (WSKey,UsrCod,PlgCod,LastTime)" " VALUES" " ('%s',%ld,%ld,NOW())", @@ -572,7 +573,7 @@ static int API_RemoveOldWSKeys (struct soap *soap) /***** Remove expired sessions *****/ /* A session expire when last click (LastTime) is too old, or when there was at least one refresh (navigator supports AJAX) and last refresh is too old (browser probably was closed) */ - sprintf (Query,"DELETE LOW_PRIORITY FROM API_keys" + sprintf (Query,"DELETE LOW_PRIORITY FROM api_keys" " WHERE LastTime DESCRIBE ann_seen; "UsrCod INT NOT NULL," "UNIQUE INDEX(AnnCod,UsrCod))"); +/***** Table api_keys *****/ +/* +mysql> DESCRIBE api_keys; ++----------+----------+------+-----+---------+-------+ +| Field | Type | Null | Key | Default | Extra | ++----------+----------+------+-----+---------+-------+ +| WSKey | char(43) | NO | PRI | NULL | | +| UsrCod | int(11) | NO | MUL | NULL | | +| PlgCod | int(11) | NO | | NULL | | +| LastTime | datetime | NO | MUL | NULL | | ++----------+----------+------+-----+---------+-------+ +4 rows in set (0.00 sec) +*/ + DB_CreateTable ("CREATE TABLE IF NOT EXISTS api_keys (" + "WSKey CHAR(43) NOT NULL," // API_BYTES_WS_KEY + "UsrCod INT NOT NULL," + "PlgCod INT NOT NULL," + "LastTime DATETIME NOT NULL," + "UNIQUE INDEX(WSKey)," + "INDEX(UsrCod)," + "INDEX(PlgCod)," + "INDEX(LastTime))"); + /***** Table asg_assignments *****/ /* mysql> DESCRIBE asg_assignments; @@ -3691,29 +3714,6 @@ mysql> DESCRIBE usr_webs; "URL VARCHAR(255) NOT NULL," // Cns_MAX_BYTES_WWW "UNIQUE INDEX(UsrCod,Web))"); -/***** Table API_keys *****/ -/* -mysql> DESCRIBE API_keys; -+----------+----------+------+-----+---------+-------+ -| Field | Type | Null | Key | Default | Extra | -+----------+----------+------+-----+---------+-------+ -| WSKey | char(43) | NO | PRI | NULL | | -| UsrCod | int(11) | NO | MUL | NULL | | -| PlgCod | int(11) | NO | | NULL | | -| LastTime | datetime | NO | MUL | NULL | | -+----------+----------+------+-----+---------+-------+ -4 rows in set (0.00 sec) -*/ - DB_CreateTable ("CREATE TABLE IF NOT EXISTS API_keys (" - "WSKey CHAR(43) NOT NULL," // API_BYTES_WS_KEY - "UsrCod INT NOT NULL," - "PlgCod INT NOT NULL," - "LastTime DATETIME NOT NULL," - "UNIQUE INDEX(WSKey)," - "INDEX(UsrCod)," - "INDEX(PlgCod)," - "INDEX(LastTime))"); - /***** Show success message *****/ HTM_OL_End (); Ale_ShowAlert (Ale_SUCCESS,Txt_Created_tables_in_the_database_that_did_not_exist);