3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the Revised BSD License.
6 This program is distributed in the hope that it will be useful,
7 but WITHOUT ANY WARRANTY; without even the implied warranty of
8 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 Revised BSD License for more details.
11 Copyright 2004-2024 iDB Support - https://idb.osdn.jp/support/category.php?act=view&id=1
12 Copyright 2004-2024 Game Maker 2k - https://idb.osdn.jp/support/category.php?act=view&id=2
14 $FileInfo: sqlite.php - Last Update: 8/30/2024 SVN 1063 - Author: cooldude2k $
16 $File3Name = basename($_SERVER['SCRIPT_NAME']);
17 if ($File3Name == "sqlite.php" ||
$File3Name == "/sqlite.php") {
22 if ($_SESSION['UserGroup'] == $Settings['GuestGroup'] ||
$GroupInfo['HasAdminCP'] == "no") {
23 redirect("location", $rbasedir.url_maker($exfile['index'], $Settings['file_ext'], "act=view", $Settings['qstr'], $Settings['qsep'], $prexqstr['index'], $exqstr['index'], false));
25 header("Content-Type: text/plain; charset=".$Settings['charset']);
26 gzip_page($Settings['use_gzip'], $GZipEncode['Type']);
27 session_write_close();
30 if ($Settings['sqltype'] != "sqlite3" && $Settings['sqltype'] != "sqlite3_prepare" && $Settings['sqltype'] != "pdo_sqlite3") {
31 redirect("location", $rbasedir.url_maker($exfile['index'], $Settings['file_ext'], "act=view", $Settings['qstr'], $Settings['qsep'], $prexqstr['index'], $exqstr['index'], false));
33 header("Content-Type: text/plain; charset=".$Settings['charset']);
34 gzip_page($Settings['use_gzip'], $GZipEncode['Type']);
35 session_write_close();
38 if (!isset($_GET['outtype'])) {
39 $_GET['outtype'] = "UTF-8";
41 header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
42 header("Cache-Control: private", false);
43 header("Content-Description: File Transfer");
44 if (!isset($_GET['comlevel'])) {
45 $_GET['comlevel'] = -1;
47 if (!is_numeric($_GET['comlevel'])) {
48 $_GET['comlevel'] = -1;
50 if ($_GET['comlevel'] > 9 ||
$_GET['comlevel'] < -1) {
51 $_GET['comlevel'] = -1;
53 if (!isset($_GET['compress'])) {
54 $_GET['compress'] = "none";
56 if ($_GET['compress'] == "gzip") {
57 $_GET['compress'] = "gzencode";
59 if ($_GET['compress'] == "bzip" ||
60 $_GET['compress'] == "bzip2") {
61 $_GET['compress'] = "bzcompress";
63 if ($_GET['compress'] != "none" &&
64 $_GET['compress'] != "gzencode" &&
65 $_GET['compress'] != "gzcompress" &&
66 $_GET['compress'] != "gzdeflate" &&
67 $_GET['compress'] != "bzcompress") {
68 $_GET['compress'] = "none";
70 if (!extension_loaded("zlib")) {
71 if ($_GET['compress'] == "gzencode" &&
72 $_GET['compress'] == "gzcompress" &&
73 $_GET['compress'] == "gzdeflate") {
74 $_GET['compress'] = "none";
77 if (!extension_loaded("bz2")) {
78 if ($_GET['compress'] == "bzcompress") {
79 $_GET['compress'] = "none";
82 if ($_GET['compress'] == "bzcompress") {
83 if ($_GET['comlevel'] > 9 ||
$_GET['comlevel'] < 0) {
84 $_GET['comlevel'] = 4;
88 if (isset($Settings['sqldb']) && $Settings['sqldb'] != "") {
89 $fname = str_replace("_", "", $Settings['sqldb'])."_";
91 if ($_GET['compress'] == "none") {
92 $fname .= str_replace("_", "", $Settings['sqltable']).".sql";
94 if ($_GET['compress'] == "gzencode") {
95 $fname .= str_replace("_", "", $Settings['sqltable']).".sql.gz";
97 if ($_GET['compress'] == "gzcompress") {
98 $fname .= str_replace("_", "", $Settings['sqltable']).".sql.gz";
100 if ($_GET['compress'] == "gzdeflate") {
101 $fname .= str_replace("_", "", $Settings['sqltable']).".sql.gz";
103 if ($_GET['compress'] == "bzcompress") {
104 $fname .= str_replace("_", "", $Settings['sqltable']).".sql.bz2";
106 header("Content-Disposition: attachment; filename=".$fname);
107 header("Content-Type: application/octet-stream");
108 header("Content-Transfer-Encoding: binary");
109 if (!isset($AltSQLDumper) ||
$AltSQLDumper === null) {
110 $SQLDumper = "SQL Dumper";
112 if (isset($AltSQLDumper) && $AltSQLDumper !== null) {
113 $SQLDumper = $AltSQLDumper;
115 function GetAllRows($table)
120 $tresult = sql_query("SELECT * FROM \"".$table."\"", $SQLStat);
121 while ($trow = sql_fetch_assoc($tresult)) {
122 $trowout[$rene_j] = $trow;
125 sql_free_result($tresult);
128 $TablePreFix = $Settings['sqltable'];
129 function add_prefix($tarray)
132 return $TablePreFix.$tarray;
134 $TableChCk = array("categories", "catpermissions", "events", "forums", "groups", "levels", "members", "mempermissions", "messenger", "permissions", "polls", "posts", 'ranks', "restrictedwords", "sessions", "smileys", "themes", "topics", "wordfilter");
136 $TableChCk = array_map("add_prefix", $TableChCk);
137 if (!isset($_GET['outtype']) ||
$_GET['outtype'] == "UTF-8") {
138 header("Content-Type: text/plain; charset=UTF-8");
140 if ($_GET['outtype'] == "latin1") {
141 header("Content-Type: text/plain; charset=ISO-8859-15");
143 if ($_GET['outtype'] == "latin15") {
144 header("Content-Type: text/plain; charset=ISO-8859-15");
147 $slnum = count($TableChCk);
148 while ($sli < $slnum) {
150 $FullTable[$sli] = "CREATE TABLE \"".$TableChCk[$sli]."\" (\n";
152 $tabsta = sql_query("SELECT * FROM sqlite_master WHERE type=\"table\" and tbl_name=\"".$TableChCk[$sli]."\";", $SQLStat);
153 $tabstats = sql_fetch_assoc($tabsta);
154 $FullTable[$sli] = $tabstats['sql'].";\n";
157 $tabsta = sql_query("PRAGMA table_info(\"".$TableChCk[$sli]."\");",$SQLStat);
158 while ($tabstats = sql_fetch_assoc($tabsta)) {
160 if($zli>0) { $FullTable[$sli] .= ",\n"; }
161 $SQLDefault = null; $PrimeKey = " ";
162 if($tabstats['dflt_value']!==null) {
163 $SQLDefault = " default '".$tabstats['dflt_value']."'"; }
164 if($tabstats['dflt_value']===null) {
166 if($tabstats['pk']=="1") {
167 $PrimeKey = " PRIMARY KEY "; }
168 $FullTable[$sli] .= " \"".$tabstats['name']."\" ".$tabstats['type'].$PrimeKey."NOT NULL".$SQLDefault;
170 $FullTable[$sli] .= "\n);\n";
174 $TableNames = $TableChCk;
175 $num = count($TableNames);
177 $sqldump = "-- ".$OrgName." ".$SQLDumper."\n";
178 $sqldump .= "-- version ".$VerInfo['iDB_Ver_SVN']."\n";
179 $sqldump .= "-- ".$iDBHome."support/\n";
181 $sqldump .= "-- Generation Time: ".$usercurtime->format('F d, Y \a\t h:i A')."\n";
182 $sqldump .= "-- SQLite Server version: ".sql_server_info($SQLStat)."\n";
183 $sqldump .= "-- PHP Version: ".phpversion()."\n\n";
185 $sqldump .= "-- Database: \"".$Settings['sqldb']."\"\n";
186 $sqldump .= "--\n\n";
187 $sqldump .= "-- --------------------------------------------------------\n\n";
188 while ($melanie_p < $num) {
190 $trow = GetAllRows($TableNames[$melanie_p]);
191 $numz = count($trow);
194 $sqldump .= "-- Table structure for table \"".$TableNames[$melanie_p]."\"\n";
195 $sqldump .= "--\n\n";
196 $sqldump .= $FullTable[$melanie_p]."\n";
197 while ($kazuki_p < $numz) {
201 $trownew = $trow[$kazuki_p];
202 $trowname = array_keys($trownew);
203 $nums = count($trownew);
205 while ($il < $nums) {
207 $trowrname = sql_escape_string($trowname[$il], $SQLStat);
208 $trowrvalue = sql_escape_string($trownew[$trowrname], $SQLStat);
209 if ($_GET['outtype'] == "UTF-8" && $Settings['charset'] != "UTF-8") {
210 $trowrvalue = utf8_encode($trowrvalue);
212 $trowrvalue = str_replace(array("\n", "\r"), array('\n', '\r'), $trowrvalue);
214 $srow = "INSERT INTO \"".$TableNames[$melanie_p]."\" (";
216 if ($il < $tnums && $il != $tnums) {
217 $srow .= "\"".$trowrname."\", ";
220 $srow .= "\"".$trowrname."\") VALUES";
225 if (!is_numeric($trowrvalue)) {
226 $trowrvalue = "'".$trowrvalue."'";
229 $srowvalue .= $trowrvalue.", ";
232 $srowvalue .= $trowrvalue;
233 if ($kazuki_p < $tnumz) {
236 if ($kazuki_p == $tnumz) {
242 if ($kazuki_p === 0) {
244 $sqldump .= "-- Dumping data for table \"".$TableNames[$melanie_p]."\"\n";
245 $sqldump .= "--\n\n";
247 $sqldump .= $srow."\n";
248 $sqldump .= $srowvalue."\n";
249 if ($kazuki_p == $tnumz && $melanie_p < $tnum) {
250 $sqldump .= "\n-- --------------------------------------------------------\n";
256 $sqldump .= "-- Dumping data for table \"".$TableNames[$melanie_p]."\"\n";
257 $sqldump .= "--\n\n";
258 $sqldump .= "\n-- --------------------------------------------------------\n";
263 if ($_GET['compress'] == "none") {
266 if ($_GET['compress'] == "gzencode") {
267 echo gzencode($sqldump, $_GET['comlevel']);
269 if ($_GET['compress'] == "gzcompress") {
270 echo gzcompress($sqldump, $_GET['comlevel']);
272 if ($_GET['compress'] == "gzdeflate") {
273 echo gzdeflate($sqldump, $_GET['comlevel']);
275 if ($_GET['compress'] == "bzcompress") {
276 echo bzcompress($sqldump, $_GET['comlevel']);
278 fix_amp($Settings['use_gzip'], $GZipEncode['Type']);