function SQLDrop($sqlarray) { global $db; foreach ($sqlarray as $query) { $lowquery = strtolower(substr($query, 0, 6)); $next = CheckDrop($query); if ($next && $lowquery == 'create') { $t_name = trim(substr($query, 0, strpos($query, '('))); $t_name = substr($t_name, strrpos($t_name, ' ') + 1); $db->query("DROP TABLE IF EXISTS {$t_name}"); } } }
function SQLCreate($sqlarray, $hack = null) { global $db, $charset, $writearray, $lang; $query = $updatesql = ''; $cachename = empty($hack) ? 'sys' : $hack; foreach ($sqlarray as $value) { $value = trim($value, " \t"); if ($value && $value[0] != '#') { $query .= $value; if (substr($value, -7) == ';<wind>') { $lowquery = strtolower(substr($query, 0, 5)); $checkdrop = CheckDrop($value); if (in_array($lowquery, array('drop ', 'creat'))) { if ($cachename == 'sys' || $checkdrop) { if ($lowquery == 'creat') { $tablename = trim(substr($query, 0, strpos($query, '('))); $tablename = substr($tablename, strrpos($tablename, ' ') + 1); $writearray[] = str_replace('{#tablename}', $tablename, $lang['success_3_1']); $search = trim(substr(strrchr($value, ')'), 1)); $tabtype = substr(strchr($search, '='), 1); $tabtype = substr($tabtype, 0, strpos($tabtype, strpos($tabtype, ' ') ? ' ' : ';')); if ($db->server_info() >= '4.1') { $replace = "ENGINE={$tabtype}" . ($charset ? " DEFAULT CHARSET={$charset}" : '') . ';'; } else { $replace = "TYPE={$tabtype};"; } $query = str_replace(array($search, '<wind>'), array($replace, ''), $query); } else { $query = str_replace('<wind>', '', $query); } $db->query($query); } } elseif (in_array($lowquery, array('inser', 'repla')) && ($cachename == 'sys' || $checkdrop) || $lowquery == 'alter' && $cachename != 'sys' && $checkdrop && strpos(strtolower($query), 'drop') === false) { $lowquery == 'inser' && ($query = 'REPLACE ' . substr($query, 6)); $updatesql .= $query; } $query = ''; } } } $updatesql && writeover(D_P . "data/install_{$cachename}.sql", $updatesql); return $writearray; }
function SQLCreate($sqlarray) { global $db, $charset; $query = ''; foreach ($sqlarray as $value) { if ($value[0] != '#') { $query .= $value; if (substr($value, -1) == ';' && !in_array(strtolower(substr($query, 0, 5)), array('drop ', 'delet', 'updat'))) { $lowquery = strtolower(substr($query, 0, 5)); if (in_array($lowquery, array('creat', 'alter', 'inser', 'repla'))) { $next = CheckDrop($query); if ($lowquery == 'creat') { if (!$next) { continue; } strpos($query, 'IF NOT EXISTS') === false && ($query = str_replace('TABLE', 'TABLE IF NOT EXISTS', $query)); $extra1 = trim(substr(strrchr($value, ')'), 1)); $tabtype = substr(strchr($extra1, '='), 1); $tabtype = substr($tabtype, 0, strpos($tabtype, strpos($tabtype, ' ') ? ' ' : ';')); if ($db->server_info() >= '4.1') { $extra2 = "ENGINE={$tabtype}" . ($charset ? " DEFAULT CHARSET={$charset}" : ''); } else { $extra2 = "TYPE={$tabtype}"; } $query = str_replace($extra1, $extra2 . ';', $query); } elseif (in_array($lowquery, array('inser', 'repla'))) { if (!$next) { continue; } $lowquery == 'inser' && ($query = 'REPLACE ' . substr($query, 6)); } elseif ($lowquery == 'alter' && !$next && strpos(strtolower($query), 'drop') !== false) { continue; } $db->query($query); $query = ''; } } } } }