Skip to content

Commit

Permalink
Fixed item expiration SQL queries
Browse files Browse the repository at this point in the history
Thanks to #146 for reporting an SQL error
  • Loading branch information
azalty authored and nuclearsilo583 committed Feb 18, 2023
1 parent 64955fa commit 4a3364e
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 10 deletions.
13 changes: 9 additions & 4 deletions addons/sourcemod/scripting/store/db.sp
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,15 @@ public void Store_DB_HouseKeeping(Handle db)
{
// Do some housekeeping
char m_szQuery[256], m_szLogCleaningQuery[256];
Format(STRING(m_szQuery), "delete `store_items`, `store_equipment`"
... "from `store_items`, `store_equipment` "
... "where (store_items.unique_id = store_equipment.unique_id) "
... "and store_items.date_of_expiration<>0 and store_items.date_of_expiration<%d", GetTime());
// Remove expired and equipped items
Format(STRING(m_szQuery), "DELETE FROM store_items, store_equipment "
... "WHERE (store_items.unique_id = store_equipment.unique_id) "
... "AND store_items.date_of_expiration != 0 "
... "AND store_items.date_of_expiration < %d", GetTime());
SQL_TVoid(db, m_szQuery);

// Remove expired and unequipped items
Format(STRING(m_szQuery), "DELETE FROM store_items WHERE date_of_expiration != 0 AND date_of_expiration < %d", GetTime());
SQL_TVoid(db, m_szQuery);

char m_szDriver[2];
Expand Down
10 changes: 9 additions & 1 deletion addons/sourcemod/scripting/store/sql.sp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,15 @@ public void SQLCallback_Connect(Handle owner, Handle hndl, const char[] error, a

// Do some housekeeping
char m_szQuery[256], m_szLogCleaningQuery[256];
Format(STRING(m_szQuery), "DELETE FROM store_items WHERE `date_of_expiration` <> 0 AND `date_of_expiration` < %d", GetTime());
// Remove expired and equipped items
Format(STRING(m_szQuery), "DELETE FROM store_items, store_equipment "
... "WHERE (store_items.unique_id = store_equipment.unique_id) "
... "AND store_items.date_of_expiration != 0 "
... "AND store_items.date_of_expiration < %d", GetTime());
SQL_TVoid(g_hDatabase, m_szQuery);

// Remove expired and unequipped items
Format(STRING(m_szQuery), "DELETE FROM store_items WHERE date_of_expiration != 0 AND date_of_expiration < %d", GetTime());
SQL_TVoid(g_hDatabase, m_szQuery);


Expand Down
23 changes: 18 additions & 5 deletions addons/sourcemod/scripting/store_combine.sp
Original file line number Diff line number Diff line change
Expand Up @@ -826,10 +826,15 @@ public void OnConfigsExecuted()
else
{
char m_szQuery[256], m_szLogCleaningQuery[256];
Format(STRING(m_szQuery), "delete `store_items`, `store_equipment`"
... "from `store_items`, `store_equipment` "
... "where (store_items.unique_id = store_equipment.unique_id) "
... "and store_items.date_of_expiration<>0 and store_items.date_of_expiration<%d", GetTime());
// Remove expired and equipped items
Format(STRING(m_szQuery), "DELETE FROM store_items, store_equipment "
... "WHERE (store_items.unique_id = store_equipment.unique_id) "
... "AND store_items.date_of_expiration != 0 "
... "AND store_items.date_of_expiration < %d", GetTime());
SQL_TVoid(g_hDatabase, m_szQuery);

// Remove expired and unequipped items
Format(STRING(m_szQuery), "DELETE FROM store_items WHERE date_of_expiration != 0 AND date_of_expiration < %d", GetTime());
SQL_TVoid(g_hDatabase, m_szQuery);

char m_szDriver[2];
Expand Down Expand Up @@ -3552,7 +3557,15 @@ public void SQLCallback_Connect(Handle owner, Handle hndl, const char[] error, a

// Do some housekeeping
char m_szQuery[256], m_szLogCleaningQuery[256];
Format(STRING(m_szQuery), "DELETE FROM store_items WHERE `date_of_expiration` <> 0 AND `date_of_expiration` < %d", GetTime());
// Remove expired and equipped items
Format(STRING(m_szQuery), "DELETE FROM store_items, store_equipment "
... "WHERE (store_items.unique_id = store_equipment.unique_id) "
... "AND store_items.date_of_expiration != 0 "
... "AND store_items.date_of_expiration < %d", GetTime());
SQL_TVoid(g_hDatabase, m_szQuery);

// Remove expired and unequipped items
Format(STRING(m_szQuery), "DELETE FROM store_items WHERE date_of_expiration != 0 AND date_of_expiration < %d", GetTime());
SQL_TVoid(g_hDatabase, m_szQuery);

/*Format(STRING(m_szVoucherQuery), "UPDATE store_voucher SET"
Expand Down

0 comments on commit 4a3364e

Please sign in to comment.