File inc/state.inc.php changed (mode: 100644) (index 54bfaab..e35035c) |
... |
... |
function rg_state_get($db, $var) |
41 |
41 |
break; |
break; |
42 |
42 |
} |
} |
43 |
43 |
|
|
44 |
|
// Not found in cache, try the database |
|
45 |
|
$params = array("var" => $var); |
|
46 |
|
$sql = "SELECT value FROM state WHERE var = @@var@@ LIMIT 1"; |
|
47 |
|
$res = rg_sql_query_params($db, $sql, $params); |
|
|
44 |
|
// It may be possible the database was not created |
|
45 |
|
// We return an empty string |
|
46 |
|
$k = '__internal' . '::' . 'STATE_TABLE_EXISTS'; |
|
47 |
|
$r = rg_cache_get($k); |
|
48 |
|
if ($r === FALSE) { |
|
49 |
|
// Let's see if the 'state' table is present |
|
50 |
|
$r = rg_sql_rel_exists($db, 'state'); |
|
51 |
|
if (($r === FALSE) || ($r === 0)) { |
|
52 |
|
$ret = FALSE; |
|
53 |
|
break; |
|
54 |
|
} |
|
55 |
|
rg_cache_set($k, 1, RG_SOCKET_NO_WAIT); |
|
56 |
|
} |
|
57 |
|
|
|
58 |
|
if ($r === 2) { // state table was loaded |
|
59 |
|
// but the var is not there |
|
60 |
|
$ret = ''; |
|
61 |
|
break; |
|
62 |
|
} |
|
63 |
|
|
|
64 |
|
// We have to go in the database... |
|
65 |
|
$sql = 'SELECT * FROM state'; |
|
66 |
|
$res = rg_sql_query($db, $sql); |
48 |
67 |
if ($res === FALSE) { |
if ($res === FALSE) { |
49 |
68 |
rg_state_set_error(rg_sql_error()); |
rg_state_set_error(rg_sql_error()); |
50 |
69 |
break; |
break; |
|
... |
... |
function rg_state_get($db, $var) |
52 |
71 |
|
|
53 |
72 |
$rows = rg_sql_num_rows($res); |
$rows = rg_sql_num_rows($res); |
54 |
73 |
if ($rows == 0) { |
if ($rows == 0) { |
55 |
|
$ret = ""; |
|
|
74 |
|
$ret = ''; |
56 |
75 |
} else { |
} else { |
57 |
|
$row = rg_sql_fetch_array($res); |
|
58 |
|
$ret = $row['value']; |
|
59 |
|
rg_cache_set("state::" . $var, $ret, RG_SOCKET_NO_WAIT); |
|
|
76 |
|
$rows = array(); |
|
77 |
|
while (($row = rg_sql_fetch_array($res))) { |
|
78 |
|
$v = $row['var']; |
|
79 |
|
$rows[$v] = $row['value']; |
|
80 |
|
} |
|
81 |
|
rg_cache_set('state', $rows, RG_SOCKET_NO_WAIT); |
|
82 |
|
rg_cache_set($k, 2, RG_SOCKET_NO_WAIT); |
|
83 |
|
|
|
84 |
|
if (isset($rows[$var])) |
|
85 |
|
$ret = $rows[$var]; |
|
86 |
|
else |
|
87 |
|
$ret = ''; |
60 |
88 |
} |
} |
61 |
89 |
rg_sql_free_result($res); |
rg_sql_free_result($res); |
62 |
|
|
|
63 |
90 |
break; |
break; |
64 |
91 |
} |
} |
65 |
92 |
|
|
|
... |
... |
function rg_state_set($db, $var, $value) |
94 |
121 |
|
|
95 |
122 |
$ret = FALSE; |
$ret = FALSE; |
96 |
123 |
while (1) { |
while (1) { |
97 |
|
$params = array("var" => $var, "value" => $value); |
|
98 |
|
$old = rg_state_get($db, $var); |
|
99 |
|
if ($old === FALSE) |
|
100 |
|
break; |
|
101 |
|
|
|
102 |
|
if (strcmp($old, $value) == 0) |
|
103 |
|
return TRUE; |
|
104 |
|
|
|
|
124 |
|
$params = array('var' => $var, 'value' => $value); |
105 |
125 |
$sql = 'UPDATE state SET value = @@value@@' |
$sql = 'UPDATE state SET value = @@value@@' |
106 |
126 |
. ' WHERE var = @@var@@'; |
. ' WHERE var = @@var@@'; |
107 |
127 |
$res = rg_sql_query_params($db, $sql, $params); |
$res = rg_sql_query_params($db, $sql, $params); |