2021-09-10 20:24:48 +02:00
|
|
|
|
// swad_figure_database.c: figures (global stats) operations with database
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
SWAD (Shared Workspace At a Distance),
|
|
|
|
|
is a web platform developed at the University of Granada (Spain),
|
|
|
|
|
and used to support university teaching.
|
|
|
|
|
|
|
|
|
|
This file is part of SWAD core.
|
2024-02-07 00:40:28 +01:00
|
|
|
|
Copyright (C) 1999-2024 Antonio Ca<EFBFBD>as Vargas
|
2021-09-10 20:24:48 +02:00
|
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Affero General Public License as
|
|
|
|
|
published by the Free Software Foundation, either version 3 of the
|
|
|
|
|
License, or (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU Affero General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Affero General Public License
|
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/********************************* Headers ***********************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2023-02-08 14:25:42 +01:00
|
|
|
|
#include "swad_alert.h"
|
2021-09-10 20:24:48 +02:00
|
|
|
|
#include "swad_database.h"
|
|
|
|
|
#include "swad_figure_database.h"
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/****************** Update unsigned figure value into cache ******************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
void Fig_DB_UpdateUnsignedFigureIntoCache (FigCch_FigureCached_t Figure,
|
2023-09-22 14:47:56 +02:00
|
|
|
|
Hie_Level_t Level,long HieCod,
|
2021-09-10 20:24:48 +02:00
|
|
|
|
unsigned Value)
|
|
|
|
|
{
|
|
|
|
|
DB_QueryREPLACE ("can not update cached figure value",
|
|
|
|
|
"REPLACE INTO fig_figures"
|
|
|
|
|
" (Figure,Scope,Cod,ValueInt,ValueDouble)"
|
|
|
|
|
" VALUES"
|
|
|
|
|
" (%u,'%s',%ld,%u,'0.0')",
|
|
|
|
|
(unsigned) Figure,
|
2023-07-11 19:12:24 +02:00
|
|
|
|
Hie_GetDBStrFromLevel (Level),
|
2023-09-20 20:07:04 +02:00
|
|
|
|
HieCod,
|
2021-09-10 20:24:48 +02:00
|
|
|
|
Value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/******************* Update double figure value into cache *******************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
void Fig_DB_UpdateDoubleFigureIntoCache (FigCch_FigureCached_t Figure,
|
2023-09-22 14:47:56 +02:00
|
|
|
|
Hie_Level_t Level,long HieCod,
|
2021-09-10 20:24:48 +02:00
|
|
|
|
double Value)
|
|
|
|
|
{
|
|
|
|
|
Str_SetDecimalPointToUS (); // To write the decimal point as a dot
|
|
|
|
|
DB_QueryREPLACE ("can not update cached figure value",
|
|
|
|
|
"REPLACE INTO fig_figures"
|
|
|
|
|
" (Figure,Scope,Cod,ValueInt,ValueDouble)"
|
|
|
|
|
" VALUES"
|
|
|
|
|
" (%u,'%s',%ld,0,'%.15lg')",
|
|
|
|
|
(unsigned) Figure,
|
2023-07-11 19:12:24 +02:00
|
|
|
|
Hie_GetDBStrFromLevel (Level),
|
2023-09-20 20:07:04 +02:00
|
|
|
|
HieCod,
|
2021-09-10 20:24:48 +02:00
|
|
|
|
Value);
|
|
|
|
|
Str_SetDecimalPointToLocal (); // Return to local system
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/************************** Get figure from cache ****************************/
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
unsigned Fig_DB_GetFigureFromCache (MYSQL_RES **mysql_res,
|
|
|
|
|
FigCch_FigureCached_t Figure,
|
2023-09-22 14:47:56 +02:00
|
|
|
|
Hie_Level_t Level,long HieCod,
|
2021-09-10 20:24:48 +02:00
|
|
|
|
FigCch_Type_t Type,time_t TimeCached)
|
|
|
|
|
{
|
|
|
|
|
static const char *Field[FigCch_NUM_TYPES] =
|
|
|
|
|
{
|
|
|
|
|
[FigCch_UNSIGNED] = "ValueInt",
|
|
|
|
|
[FigCch_DOUBLE ] = "ValueDouble",
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (unsigned)
|
|
|
|
|
DB_QuerySELECT (mysql_res,"can not get cached figure value",
|
|
|
|
|
"SELECT %s" // row[0]
|
|
|
|
|
" FROM fig_figures"
|
|
|
|
|
" WHERE Figure=%u"
|
|
|
|
|
" AND Scope='%s'"
|
|
|
|
|
" AND Cod=%ld"
|
|
|
|
|
" AND LastUpdate>FROM_UNIXTIME(UNIX_TIMESTAMP()-%lu)",
|
|
|
|
|
Field[Type],
|
2023-09-20 20:07:04 +02:00
|
|
|
|
(unsigned) Figure,Hie_GetDBStrFromLevel (Level),HieCod,
|
2021-09-10 20:24:48 +02:00
|
|
|
|
TimeCached);
|
|
|
|
|
}
|