• R/O
  • HTTP
  • SSH
  • HTTPS

nucleus-plugins: Commit

Nucleus CMS日本語版用プラグインのうち、日本語版開発者がサポートしているもの


Commit MetaInfo

Revision38d659f6bc34c648a93c25da4a6a4b31e885e404 (tree)
Time2008-02-23 11:03:26
Author(no author) <(no author)@1ca2...>
Commiter(no author)

Log Message

This commit was manufactured by cvs2svn to create tag 'sqlite0903'.

git-svn-id: https://svn.sourceforge.jp/svnroot/nucleus-jp/plugin@608 1ca29b6e-896d-4ea0-84a5-967f57386b96

Change Summary

Incremental Difference

--- /dev/null
+++ b/tags/sqlite0903/sqlite/extra/sqlite/installsqlite.php
@@ -0,0 +1,86 @@
1+<?php
2+/*******************************************
3+* mysql_xxx => nucleus_mysql_xxx converter *
4+* for Nucleus *
5+* ver 0.6.1b Written by Katsumi *
6+*******************************************/
7+
8+// The license of this script is GPL
9+
10+// Check lanuage
11+if (strpos(strtolower($_SERVER['HTTP_ACCEPT_LANGUAGE']),'ja')===0) {
12+ $charset='EUC-JP';
13+} else {
14+ $charset='iso-8859-1';
15+}
16+header("Content-Type: text/html; charset=$charset");
17+
18+if (!file_exists('./nucleus/sqlite/convert.php')) exit;
19+include('./nucleus/sqlite/convert.php');
20+
21+?><html><body><?php
22+
23+$myself='installsqlite.php';
24+if ((@$_GET['go'])!='yes') {
25+
26+ if ($charset=='EUC-JP') {
27+ ?>このページでは、SQLite で使用するための Nucleus の各ファイルの変更を行います。<br /><br />
28+ すべての &quot;mysql_xxx&quot; 関数呼び出しの表記が &quot;nucleus_mysql_xxx&quot;に変更されます.<br /><br />
29+ <?php if (!function_exists('mysql_query')) {?>
30+ この変更は、MySQL 関数が PHP にインストールされていない場合には、必須ではありません。<br />
31+ この場合 &quot;install.php&quot; と &quot;config.php&quot; だけに変更が必要です。<br />
32+ もしMySQL 関数がインストールされておらず、将来的にもインストールされないことが確実な場合、<br />
33+ <a href="?go=yes&amp;modify=no">ここをクリックしてください</a>(install.php と config.php が変更されます)。<br /><br />
34+ そうでなければ、下のリンクをクリックしてください。<br /><br />
35+ <?php } ?>
36+ <a href="?go=yes&amp;modify=yes">変更を開始</a>(このディレクトリのすべての PHP ファイルが変更されます)。<br /><br />
37+ 始める前に、変更されるべき PHP ファイルのパーミッションが、読み書き可能になっていることを確認してください。
38+ </body></html><?php
39+ } else {
40+ ?>This page is to modify Nucleus core files for using SQLite as database engine.<br /><br />
41+ All the &quot;mysql_xxx&quot; functions will be converted to &quot;nucleus_mysql_xxx&quot;.<br /><br />
42+ <?php if (!function_exists('mysql_query')) {?>
43+ This modification is not required if MySQL functions of PHP are not installed in the server.<br />
44+ In this case, only the &quot;install.php&quot; and &quot;config.php&quot; must be modified.<br />
45+ If you are sure that the MySQL function is never (now and in future) installed, <br />
46+ <a href="?go=yes&amp;modify=no">please click here</a>(install.php and config.php will be changed).<br /><br />
47+ Otherwise, please click following link.<br /><br />
48+ <?php } ?>
49+ <a href="?go=yes&amp;modify=yes">Start modification</a>(all the PHP files in this directory will be changed).<br /><br />
50+ Please make sure that all PHP files to be modified are readable and writable.
51+ </body></html><?php
52+ }
53+ exit;
54+}
55+
56+if ((@$_GET['modify'])=='yes') {
57+ // Obtain all PHP files in current and child directories.
58+ $phpfiles=array();
59+ seekPhpFiles('./',$phpfiles,$myself);
60+
61+ // Modify all PHP files; mysql_xxxx is replaced by nucleus_mysql_XXXX.
62+ $allok=true;
63+ foreach ($phpfiles as $file) $allok=$allok && changeFunctions($file);
64+ if (!$allok) ExitWithError();
65+}
66+
67+// Modify config.php, install.php and backup.php
68+modifyConfigInstall();
69+
70+if ($charset=='EUC-JP') {
71+ ?>すべての変更が終了しました。<hr />
72+ <a href="install.php">ここをクリックして Nucleus w/SQLite のインストールを開始してください。</a><br />
73+ <?php
74+} else {
75+ ?>All modificatios are sccesfully done.<hr />
76+ <a href="install.php">Click here to install Nucleus w/SQLite</a><br />
77+ <?php
78+}
79+if (@rename('installsqlite.php','installsqlite.php~')) {
80+ if ($charset=='EUC-JP') {
81+ echo '(&quot;installsqlite.php&quot; は &quot;installsqlite.php~&quot; にファイル名が変更されています。)';
82+ } else {
83+ echo '(&quot;installsqlite.php&quot; has been renamed to &quot;installsqlite.php~&quot;.)';
84+ }
85+}
86+?></body></html>
\ No newline at end of file
--- /dev/null
+++ b/tags/sqlite0903/sqlite/extra/sqlite/readme-ja.txt
@@ -0,0 +1,45 @@
1+ このノートでは、Nucleus の新しいバージョンが公開され
2+た際に、SQLite 版を製作する方法について述べます。
3+
4+
5+***** installsqlite.php について。 *****
6+
7+ 主な使用目的は、Nucleus のバージョンアップがあった際
8+に、SQLite 対応にするためにコアファイルを書き換えるこ
9+とです。コアの PHP ファイルの mysql_xxxx() がすべて、
10+nucleus_mysql_xxxx() に書き換えられます。使用する際は、
11+このファイルを Nucleus のルートディレクトリ(config.php
12+のある場所)に移動し、ブラウザでアクセスしてください。
13+
14+ 加えて、install.php 及び、config.php に、
15+『include($DIR_NUCLEUS.'sqlite/sqlite.php');』が自動的に
16+書き足されます。
17+
18+ backup.php は、SQLite でのデータリストアが最適化され
19+るように、変更されます(sqlite_restore_execute_queries()
20+が使用されるようになります)。
21+
22+ さらに、install.php でのインストール画面のHTMLが若干
23+修正され、一部のMySQL特異的なオプションに『dummy』が指
24+定されるように変更されます。
25+
26+ install.sql の nucleus_plugin_option テーブル作成部分の
27+クエリー文が以下のように変更されます(auto_incrementが削除
28+されます)。
29+
30+CREATE TABLE `nucleus_plugin_option` (
31+ `ovalue` text NOT NULL,
32+ `oid` int(11) NOT NULL,
33+ `ocontextid` int(11) NOT NULL default '0',
34+ PRIMARY KEY (`oid`,`ocontextid`)
35+) TYPE=MyISAM;
36+
37+
38+***** 手動で変更しないといけない事項 *****
39+
40+ installsqlite.php の実行で必要な変更のうち重要な物に
41+ついては殆ど行われますが、一部手動で変更しなければなら
42+ない部分がある可能性があります。
43+
44+ SQLite wrapper 0.81 では、Nucleus 3.2xとNucleus3.3を
45+変更する上で、手動での変更は必要ありません。
--- /dev/null
+++ b/tags/sqlite0903/sqlite/license.txt
@@ -0,0 +1,340 @@
1+ GNU GENERAL PUBLIC LICENSE
2+ Version 2, June 1991
3+
4+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.
5+ 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
6+ Everyone is permitted to copy and distribute verbatim copies
7+ of this license document, but changing it is not allowed.
8+
9+ Preamble
10+
11+ The licenses for most software are designed to take away your
12+freedom to share and change it. By contrast, the GNU General Public
13+License is intended to guarantee your freedom to share and change free
14+software--to make sure the software is free for all its users. This
15+General Public License applies to most of the Free Software
16+Foundation's software and to any other program whose authors commit to
17+using it. (Some other Free Software Foundation software is covered by
18+the GNU Library General Public License instead.) You can apply it to
19+your programs, too.
20+
21+ When we speak of free software, we are referring to freedom, not
22+price. Our General Public Licenses are designed to make sure that you
23+have the freedom to distribute copies of free software (and charge for
24+this service if you wish), that you receive source code or can get it
25+if you want it, that you can change the software or use pieces of it
26+in new free programs; and that you know you can do these things.
27+
28+ To protect your rights, we need to make restrictions that forbid
29+anyone to deny you these rights or to ask you to surrender the rights.
30+These restrictions translate to certain responsibilities for you if you
31+distribute copies of the software, or if you modify it.
32+
33+ For example, if you distribute copies of such a program, whether
34+gratis or for a fee, you must give the recipients all the rights that
35+you have. You must make sure that they, too, receive or can get the
36+source code. And you must show them these terms so they know their
37+rights.
38+
39+ We protect your rights with two steps: (1) copyright the software, and
40+(2) offer you this license which gives you legal permission to copy,
41+distribute and/or modify the software.
42+
43+ Also, for each author's protection and ours, we want to make certain
44+that everyone understands that there is no warranty for this free
45+software. If the software is modified by someone else and passed on, we
46+want its recipients to know that what they have is not the original, so
47+that any problems introduced by others will not reflect on the original
48+authors' reputations.
49+
50+ Finally, any free program is threatened constantly by software
51+patents. We wish to avoid the danger that redistributors of a free
52+program will individually obtain patent licenses, in effect making the
53+program proprietary. To prevent this, we have made it clear that any
54+patent must be licensed for everyone's free use or not licensed at all.
55+
56+ The precise terms and conditions for copying, distribution and
57+modification follow.
58+
59+ GNU GENERAL PUBLIC LICENSE
60+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
61+
62+ 0. This License applies to any program or other work which contains
63+a notice placed by the copyright holder saying it may be distributed
64+under the terms of this General Public License. The "Program", below,
65+refers to any such program or work, and a "work based on the Program"
66+means either the Program or any derivative work under copyright law:
67+that is to say, a work containing the Program or a portion of it,
68+either verbatim or with modifications and/or translated into another
69+language. (Hereinafter, translation is included without limitation in
70+the term "modification".) Each licensee is addressed as "you".
71+
72+Activities other than copying, distribution and modification are not
73+covered by this License; they are outside its scope. The act of
74+running the Program is not restricted, and the output from the Program
75+is covered only if its contents constitute a work based on the
76+Program (independent of having been made by running the Program).
77+Whether that is true depends on what the Program does.
78+
79+ 1. You may copy and distribute verbatim copies of the Program's
80+source code as you receive it, in any medium, provided that you
81+conspicuously and appropriately publish on each copy an appropriate
82+copyright notice and disclaimer of warranty; keep intact all the
83+notices that refer to this License and to the absence of any warranty;
84+and give any other recipients of the Program a copy of this License
85+along with the Program.
86+
87+You may charge a fee for the physical act of transferring a copy, and
88+you may at your option offer warranty protection in exchange for a fee.
89+
90+ 2. You may modify your copy or copies of the Program or any portion
91+of it, thus forming a work based on the Program, and copy and
92+distribute such modifications or work under the terms of Section 1
93+above, provided that you also meet all of these conditions:
94+
95+ a) You must cause the modified files to carry prominent notices
96+ stating that you changed the files and the date of any change.
97+
98+ b) You must cause any work that you distribute or publish, that in
99+ whole or in part contains or is derived from the Program or any
100+ part thereof, to be licensed as a whole at no charge to all third
101+ parties under the terms of this License.
102+
103+ c) If the modified program normally reads commands interactively
104+ when run, you must cause it, when started running for such
105+ interactive use in the most ordinary way, to print or display an
106+ announcement including an appropriate copyright notice and a
107+ notice that there is no warranty (or else, saying that you provide
108+ a warranty) and that users may redistribute the program under
109+ these conditions, and telling the user how to view a copy of this
110+ License. (Exception: if the Program itself is interactive but
111+ does not normally print such an announcement, your work based on
112+ the Program is not required to print an announcement.)
113+
114+These requirements apply to the modified work as a whole. If
115+identifiable sections of that work are not derived from the Program,
116+and can be reasonably considered independent and separate works in
117+themselves, then this License, and its terms, do not apply to those
118+sections when you distribute them as separate works. But when you
119+distribute the same sections as part of a whole which is a work based
120+on the Program, the distribution of the whole must be on the terms of
121+this License, whose permissions for other licensees extend to the
122+entire whole, and thus to each and every part regardless of who wrote it.
123+
124+Thus, it is not the intent of this section to claim rights or contest
125+your rights to work written entirely by you; rather, the intent is to
126+exercise the right to control the distribution of derivative or
127+collective works based on the Program.
128+
129+In addition, mere aggregation of another work not based on the Program
130+with the Program (or with a work based on the Program) on a volume of
131+a storage or distribution medium does not bring the other work under
132+the scope of this License.
133+
134+ 3. You may copy and distribute the Program (or a work based on it,
135+under Section 2) in object code or executable form under the terms of
136+Sections 1 and 2 above provided that you also do one of the following:
137+
138+ a) Accompany it with the complete corresponding machine-readable
139+ source code, which must be distributed under the terms of Sections
140+ 1 and 2 above on a medium customarily used for software interchange; or,
141+
142+ b) Accompany it with a written offer, valid for at least three
143+ years, to give any third party, for a charge no more than your
144+ cost of physically performing source distribution, a complete
145+ machine-readable copy of the corresponding source code, to be
146+ distributed under the terms of Sections 1 and 2 above on a medium
147+ customarily used for software interchange; or,
148+
149+ c) Accompany it with the information you received as to the offer
150+ to distribute corresponding source code. (This alternative is
151+ allowed only for noncommercial distribution and only if you
152+ received the program in object code or executable form with such
153+ an offer, in accord with Subsection b above.)
154+
155+The source code for a work means the preferred form of the work for
156+making modifications to it. For an executable work, complete source
157+code means all the source code for all modules it contains, plus any
158+associated interface definition files, plus the scripts used to
159+control compilation and installation of the executable. However, as a
160+special exception, the source code distributed need not include
161+anything that is normally distributed (in either source or binary
162+form) with the major components (compiler, kernel, and so on) of the
163+operating system on which the executable runs, unless that component
164+itself accompanies the executable.
165+
166+If distribution of executable or object code is made by offering
167+access to copy from a designated place, then offering equivalent
168+access to copy the source code from the same place counts as
169+distribution of the source code, even though third parties are not
170+compelled to copy the source along with the object code.
171+
172+ 4. You may not copy, modify, sublicense, or distribute the Program
173+except as expressly provided under this License. Any attempt
174+otherwise to copy, modify, sublicense or distribute the Program is
175+void, and will automatically terminate your rights under this License.
176+However, parties who have received copies, or rights, from you under
177+this License will not have their licenses terminated so long as such
178+parties remain in full compliance.
179+
180+ 5. You are not required to accept this License, since you have not
181+signed it. However, nothing else grants you permission to modify or
182+distribute the Program or its derivative works. These actions are
183+prohibited by law if you do not accept this License. Therefore, by
184+modifying or distributing the Program (or any work based on the
185+Program), you indicate your acceptance of this License to do so, and
186+all its terms and conditions for copying, distributing or modifying
187+the Program or works based on it.
188+
189+ 6. Each time you redistribute the Program (or any work based on the
190+Program), the recipient automatically receives a license from the
191+original licensor to copy, distribute or modify the Program subject to
192+these terms and conditions. You may not impose any further
193+restrictions on the recipients' exercise of the rights granted herein.
194+You are not responsible for enforcing compliance by third parties to
195+this License.
196+
197+ 7. If, as a consequence of a court judgment or allegation of patent
198+infringement or for any other reason (not limited to patent issues),
199+conditions are imposed on you (whether by court order, agreement or
200+otherwise) that contradict the conditions of this License, they do not
201+excuse you from the conditions of this License. If you cannot
202+distribute so as to satisfy simultaneously your obligations under this
203+License and any other pertinent obligations, then as a consequence you
204+may not distribute the Program at all. For example, if a patent
205+license would not permit royalty-free redistribution of the Program by
206+all those who receive copies directly or indirectly through you, then
207+the only way you could satisfy both it and this License would be to
208+refrain entirely from distribution of the Program.
209+
210+If any portion of this section is held invalid or unenforceable under
211+any particular circumstance, the balance of the section is intended to
212+apply and the section as a whole is intended to apply in other
213+circumstances.
214+
215+It is not the purpose of this section to induce you to infringe any
216+patents or other property right claims or to contest validity of any
217+such claims; this section has the sole purpose of protecting the
218+integrity of the free software distribution system, which is
219+implemented by public license practices. Many people have made
220+generous contributions to the wide range of software distributed
221+through that system in reliance on consistent application of that
222+system; it is up to the author/donor to decide if he or she is willing
223+to distribute software through any other system and a licensee cannot
224+impose that choice.
225+
226+This section is intended to make thoroughly clear what is believed to
227+be a consequence of the rest of this License.
228+
229+ 8. If the distribution and/or use of the Program is restricted in
230+certain countries either by patents or by copyrighted interfaces, the
231+original copyright holder who places the Program under this License
232+may add an explicit geographical distribution limitation excluding
233+those countries, so that distribution is permitted only in or among
234+countries not thus excluded. In such case, this License incorporates
235+the limitation as if written in the body of this License.
236+
237+ 9. The Free Software Foundation may publish revised and/or new versions
238+of the General Public License from time to time. Such new versions will
239+be similar in spirit to the present version, but may differ in detail to
240+address new problems or concerns.
241+
242+Each version is given a distinguishing version number. If the Program
243+specifies a version number of this License which applies to it and "any
244+later version", you have the option of following the terms and conditions
245+either of that version or of any later version published by the Free
246+Software Foundation. If the Program does not specify a version number of
247+this License, you may choose any version ever published by the Free Software
248+Foundation.
249+
250+ 10. If you wish to incorporate parts of the Program into other free
251+programs whose distribution conditions are different, write to the author
252+to ask for permission. For software which is copyrighted by the Free
253+Software Foundation, write to the Free Software Foundation; we sometimes
254+make exceptions for this. Our decision will be guided by the two goals
255+of preserving the free status of all derivatives of our free software and
256+of promoting the sharing and reuse of software generally.
257+
258+ NO WARRANTY
259+
260+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
261+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
262+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
263+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
264+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
265+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
266+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
267+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
268+REPAIR OR CORRECTION.
269+
270+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
271+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
272+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
273+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
274+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
275+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
276+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
277+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
278+POSSIBILITY OF SUCH DAMAGES.
279+
280+ END OF TERMS AND CONDITIONS
281+
282+ How to Apply These Terms to Your New Programs
283+
284+ If you develop a new program, and you want it to be of the greatest
285+possible use to the public, the best way to achieve this is to make it
286+free software which everyone can redistribute and change under these terms.
287+
288+ To do so, attach the following notices to the program. It is safest
289+to attach them to the start of each source file to most effectively
290+convey the exclusion of warranty; and each file should have at least
291+the "copyright" line and a pointer to where the full notice is found.
292+
293+ <one line to give the program's name and a brief idea of what it does.>
294+ Copyright (C) <year> <name of author>
295+
296+ This program is free software; you can redistribute it and/or modify
297+ it under the terms of the GNU General Public License as published by
298+ the Free Software Foundation; either version 2 of the License, or
299+ (at your option) any later version.
300+
301+ This program is distributed in the hope that it will be useful,
302+ but WITHOUT ANY WARRANTY; without even the implied warranty of
303+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
304+ GNU General Public License for more details.
305+
306+ You should have received a copy of the GNU General Public License
307+ along with this program; if not, write to the Free Software
308+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
309+
310+
311+Also add information on how to contact you by electronic and paper mail.
312+
313+If the program is interactive, make it output a short notice like this
314+when it starts in an interactive mode:
315+
316+ Gnomovision version 69, Copyright (C) year name of author
317+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
318+ This is free software, and you are welcome to redistribute it
319+ under certain conditions; type `show c' for details.
320+
321+The hypothetical commands `show w' and `show c' should show the appropriate
322+parts of the General Public License. Of course, the commands you use may
323+be called something other than `show w' and `show c'; they could even be
324+mouse-clicks or menu items--whatever suits your program.
325+
326+You should also get your employer (if you work as a programmer) or your
327+school, if any, to sign a "copyright disclaimer" for the program, if
328+necessary. Here is a sample; alter the names:
329+
330+ Yoyodyne, Inc., hereby disclaims all copyright interest in the program
331+ `Gnomovision' (which makes passes at compilers) written by James Hacker.
332+
333+ <signature of Ty Coon>, 1 April 1989
334+ Ty Coon, President of Vice
335+
336+This General Public License does not permit incorporating your program into
337+proprietary programs. If your program is a subroutine library, you may
338+consider it more useful to permit linking proprietary applications with the
339+library. If this is what you want to do, use the GNU Library General
340+Public License instead of this License.
--- /dev/null
+++ b/tags/sqlite0903/sqlite/nucleus/plugins/NP_SQLite.php
@@ -0,0 +1,185 @@
1+<?php
2+ /***********************************
3+ * NP_SQLite plugin ver 0.8.0 *
4+ * *
5+ * This plugin modifies the plugins *
6+ * when these are installed. *
7+ * *
8+ * Written by Katsumi *
9+ ***********************************/
10+// The licence of this script is GPL
11+class NP_SQLite extends NucleusPlugin {
12+ function getName() { return 'NP_SQLite'; }
13+ function getMinNucleusVersion() { return 320; }
14+ function getAuthor() { $this->install(); return 'Katsumi'; }
15+ function getVersion() { global $SQLITECONF; return $SQLITECONF['VERSION']; }
16+ function getURL() {return 'http://hp.vector.co.jp/authors/VA016157/';}
17+ function getDescription() { return $this->showinfo(); }
18+ function supportsFeature($what) { return (int)($what=='SqlTablePrefix'); }
19+ function getEventList() { return array('PreAddPlugin','PreSkinParse','QuickMenu'); }
20+ function hasAdminArea() { return 1; }
21+
22+ function install(){
23+ if (!$this->getOption('allowsql')) {
24+ $this->createOption('allowsql',$this->translated('Allow SQL query during the management?'),'yesno','no');
25+ }
26+ if (!$this->getOption('numatonce')) {
27+ $this->createOption('numatonce',$this->translated('Number of SQL queries at once when DB restore.'),'text','20','datatype=numerical');
28+ $this->createOption('refreshwait',$this->translated('Wating tile (seconds) when DB restore.'),'text','1','datatype=numerical');
29+ }
30+ }
31+
32+ var $infostr;
33+ function showinfo() {
34+ global $SQLITECONF;
35+ if ($this->infostr) echo "<b>".$this->infostr."</b><hr />\n";
36+ return $this->translated('NP_SQLite plugin. Filesize of DB is now ').filesize($SQLITECONF['DBFILENAME']).' bytes.';
37+ }
38+
39+ function init(){
40+ }
41+
42+ function event_QuickMenu(&$data){
43+ global $member;
44+ $this->_showDebugMessage();
45+
46+ // only show to admins
47+ if (!($member->isLoggedIn() && $member->isAdmin())) return;
48+
49+ array_push($data['options'], array(
50+ 'title' => 'SQLite',
51+ 'url' => $this->getAdminURL(),
52+ 'tooltip' => $this->translated('SQLite management')
53+ ) );
54+ }
55+ function event_PreSkinParse(&$data){
56+ $this->_showDebugMessage();
57+ }
58+ function _showDebugMessage(){
59+ global $SQLITECONF;
60+ if (isset($SQLITECONF['DEBUGMESSAGE'])) sqlite_DebugMessage();
61+ unset($SQLITECONF['DEBUGMESSAGE']);
62+ }
63+
64+ function event_PreAddPlugin(&$data){
65+ // This event happens before loading "NP_XXXX.php" file.
66+ // Therefore, modification is possible here.
67+ $this->modify_plugin($data['file'],true);
68+ }
69+ function modify_plugin($pluginfile,$install=false){
70+ global $DIR_PLUGINS,$SQLITECONF;
71+ if ($SQLITECONF['OVERRIDEMODE']) return true;
72+
73+ $admindir=$DIR_PLUGINS.strtolower(substr($pluginfile,3));
74+ $pluginfile=$DIR_PLUGINS.$pluginfile;
75+
76+ // List up all PHP files.
77+ $phpfiles=array();
78+ array_push($phpfiles,$pluginfile.'.php');
79+ $this->seekPhpFiles($admindir,$phpfiles);
80+
81+ // Modify the PHP files.
82+ $allok=true;
83+ foreach ($phpfiles as $file) {
84+ if (!$this->changeFunctions($file)) {
85+ $allok=false;
86+ }
87+ }
88+ if ($allok) {
89+ if ($install) $this->infostr=$this->translated('Pluing was installed sucessfully');
90+ return true;
91+ }
92+
93+ if (!$install) return false;
94+ if ($this->is_japanese()) {
95+ echo '<html><head><meta http-equiv="Content-Type" content="text/html; charset=EUC-JP" /></head>';
96+ echo '<body><h3>PHP ファイルを手動で変更する必要があります。</h3>';
97+ } else echo '<html><body><h3>Need to modify PHP file(s) manually.</h3>';
98+ foreach ($phpfiles as $file) echo $this->show_Lines($file);
99+ exit ('</body></html>');
100+ }
101+
102+ function seekPhpFiles($dir,&$phpfiles){
103+ if (!is_dir($dir)) return;
104+ $d = dir($dir);
105+ $dirpath=realpath($d->path);
106+ $dirs=array();
107+ if (substr($dirpath,-1)!='/' && substr($dirpath,-1)!="\\") $dirpath.='/';
108+ while (false !== ($entry = $d->read())) {
109+ if ($entry=='.' || $entry=='..') continue;
110+ if (is_file($dirpath.$entry) && substr($entry,-4)=='.php') array_push($phpfiles,realpath($dirpath.$entry));
111+ if (is_dir($dirpath.$entry)) array_push($dirs,realpath($dirpath.$entry));
112+ }
113+ $d->close();
114+ foreach($dirs as $dir) $this->seekPhpFiles($dir,$phpfiles);
115+ }
116+ function changeFunctions($file){
117+ if (!is_file($file=realpath($file))) return false;
118+ if (!is_readable($file)) return false;
119+ $before=$this->read_from_file($file);
120+ // Do this process until change does not occur..
121+ // Otherwise, sometime file is not completely modified.
122+ $after=$this->do_replace($before);
123+ if ($before!=$after) return $this->write_to_file($file,$after);
124+ return true;
125+ }
126+ function do_replace(&$text) {
127+ // Do this process until change does not occur..
128+ // Otherwise, sometime file is not completely modified.
129+ $after=$text;
130+ do $after=preg_replace('/([^_])mysql_([_a-z]+)([\s]*?)\(/','$1nucleus_mysql_$2(',($before=$after));
131+ while ($before!=$after);
132+ return $after;
133+ }
134+ function show_Lines($file){
135+ if (!is_file($file=realpath($file))) return '';
136+ if (!is_readable($file)) return '';
137+ $result='';
138+ $lines=file($file);
139+ $firsttime=true;
140+ foreach($lines as $num=>$before) {
141+ $after=$this->do_replace($before);
142+ if ($after!=$before) {
143+ if ($firsttime) $result.="<hr />\nFile: <b>$file</b><br /><br />\n";
144+ $firsttime=false;
145+ $result.="Modify line <b>".($num+1)."</b> like: &quot;\n";
146+ $result.=str_replace('nucleus_mysql_','<font color="#ff0000">nucleus_</font>mysql_',htmlspecialchars($after))."&quot;<br /><br />\n";
147+ }
148+ }
149+ return $result;
150+ }
151+ function read_from_file($file) {
152+ if (function_exists('file_get_contents') ) $ret=file_get_contents($file);
153+ else {
154+ ob_start();
155+ readfile($file);
156+ $ret=ob_get_contents();
157+ ob_end_clean();
158+ }
159+ return $ret;
160+ }
161+ function write_to_file($file,&$text){
162+ if (!$handle = @fopen($file, 'w')) return false;
163+ fwrite($handle,$text);
164+ fclose($handle);
165+ return true;
166+ }
167+ function is_japanese(){
168+ $language = str_replace( array('\\','/'), array('',''), getLanguageName());
169+ return (strpos($language,'japanese')===0);
170+ }
171+
172+ // Language stuff
173+ var $langArray;
174+ function translated($english){
175+ if (!is_array($this->langArray)) {
176+ $this->langArray=array();
177+ $language=$this->getDirectory().'language/'.str_replace( array('\\','/'), array('',''), getLanguageName()).'.php';
178+ if (file_exists($language)) include($language);
179+ }
180+ if (!($ret=$this->langArray[$english])) $ret=$english;
181+ return $ret;
182+ }
183+
184+}
185+?>
\ No newline at end of file
--- /dev/null
+++ b/tags/sqlite0903/sqlite/nucleus/plugins/sqlite/index.php
@@ -0,0 +1,241 @@
1+<?php
2+ /*****************************
3+ * SQLite database tool *
4+ * ver 0.8.0 *
5+ * Written by Katsumi *
6+ *****************************/
7+
8+// This library is GPL.
9+
10+ include('../../../config.php');
11+
12+ include($DIR_LIBS . 'PLUGINADMIN.php');
13+
14+ // create the admin area page
15+ $pa = new PluginAdmin('SQLite');
16+ $pa->start();
17+ $p=&$pa->plugin;
18+ $pluginUrl=$p->getAdminURL();
19+
20+
21+ // check if superadmin is logged in
22+ if (!($member->isLoggedIn() && $member->isAdmin()))
23+ {
24+ echo '<p>' . _ERROR_DISALLOWED . '</p>';
25+ $pa->end();
26+ exit;
27+ }
28+
29+ // Check ticket
30+ if (requestVar('SQLiteCommand') && (!$manager->checkTicket())){
31+ echo '<p>' . _ERROR_BADTICKET . '</p>';
32+ $pa->end();
33+ exit;
34+ }
35+ $ticket=$manager->addTicketToUrl('');
36+ $ticket=substr($ticket,strpos($ticket,'ticket=')+7);
37+
38+?><script type="text/javascript">
39+//<![CDATA[
40+function $(id) {
41+ return document.getElementById(id);
42+}
43+//]]>
44+</script><?php
45+
46+ $idnum=0;
47+ echo '<h2>'.$p->translated('SQLite management')."</h2>\n";
48+
49+ $infostr='';
50+ switch(requestVar('SQLiteCommand')){
51+ case 'VACUUM':
52+ nucleus_mysql_query('VACUUM');
53+ $infostr='VACUUM was done.';
54+ break;
55+ case 'integrity_check':
56+ $res=nucleus_mysql_query('PRAGMA integrity_check');
57+ $infostr='Integrity check result:'."<br />\n";
58+ while ($a=nucleus_mysql_fetch_array($res)) $infostr.=$a[0]."<br />\n";
59+ break;
60+ case 'plugin_check':
61+ $pluginfile=requestVar('plugin');
62+ $query='SELECT COUNT(*) as result FROM `'.sql_table('plugin').'` WHERE pfile="'.addslashes($pluginfile).'"';
63+ if (!quickQuery($query)) {
64+ $infostr="No such plugin!";
65+ break;
66+ }
67+ if ($p->modify_plugin($pluginfile)) {
68+ $infostr=$p->translated('The plugin, ').$pluginfile.$p->translated(' was checked and modified (if modification required)');
69+ break;
70+ }
71+
72+ // Modification failed. Show the lines that must be modified
73+ $phpfiles=array();
74+ array_push($phpfiles,$DIR_PLUGINS.$pluginfile.'.php');
75+ $admindir=$DIR_PLUGINS.strtolower(substr($pluginfile,3));
76+ $p->seekPhpFiles($admindir,$phpfiles);
77+ $infostr=$p->translated('Please modify the PHP files').": <br />\n";
78+ foreach ($phpfiles as $file) $infostr.=$p->show_Lines($file);
79+ break;
80+ case "QUERY":
81+ $infostr='<table><tr><th>'.'Query'.
82+'&nbsp;&nbsp;&nbsp;&nbsp;(-&gt;<a href="javascript:Copy this query" onclick="
83+var t=$(\'QueryShown\').innerHTML+\'\';
84+$(\'ExecQuery\').value=t.replace(/^\s+|\s+$/g,\'\');
85+return false;
86+">Copy</a>)'.
87+ "</th></td><tr><td id=\"QueryShown\">\n".htmlspecialchars($query=requestVar('query'))."</td></tr></table><br />\n";
88+ if (requestVar('confirm')!='confirmed'){
89+ $infostr=$p->translated('Please check the "I am sure." checkbox to execute query').$infostr;
90+ break;
91+ }
92+ ob_start();
93+ $res=nucleus_mysql_query($query);
94+ $errorstr=ob_get_contents();
95+ ob_end_clean();
96+ if (!$res) {
97+ $infostr.=nucleus_mysql_error()."<br />\n";
98+ if (preg_match('/sqlite_query\(\):([^<]*)in <b>/i',$errorstr,$matches)) $infostr.=$matches[1];
99+ break;
100+ }
101+ if (preg_match('/ OFFSET ([0-9]+)$/i',$query,$matches)) $offset=$matches[1];
102+ else $offset=0;
103+
104+ // Get resut into an array
105+ $resulttable=array();
106+ $columnname=array();
107+ $columnnum=0;
108+ while ($a=nucleus_mysql_fetch_array($res,SQLITE_ASSOC)) {
109+ if ($columnnum<count($a)) {
110+ $i=0;
111+ foreach ($a as $key=>$value) $columnname[$i++]=$key;
112+ $columnnum=count($a);
113+ }
114+ $templine=array();
115+ foreach ($a as $key=>$value) $templine[$key]=$value;
116+ array_push($resulttable,$templine);
117+ }
118+
119+ // Create table HTML from the array
120+ $infostr.="<table><tr>";
121+ for ($i=0;$i<$columnnum;$i++) $infostr.="<th>".$columnname[$i]."</th>";
122+ $infostr.="</tr>\n";
123+ foreach ($resulttable as $templine) {
124+ $infostr.="<tr>";
125+ for ($i=0;$i<$columnnum;$i++) {
126+ $value=(string)$templine[$columnname[$i]];
127+ if (50<strlen($value)) {
128+ $value='<span id="sqliteobj'.$idnum.'"><a href="" title="'.'Click this to show all'.'" onclick="'.
129+ '$(\'sqliteobj'.$idnum.'\').innerHTML='.
130+ '$(\'sqliteobj'.$idnum.'-2\').innerHTML;'.
131+ 'return false;">'.htmlspecialchars(substr($value,0,50)).".....</a></span>\n".
132+ '<span style="DISPLAY:none;" id="sqliteobj'.$idnum.'-2">'.htmlspecialchars($value)."</span>\n";
133+ $idnum++;
134+ } else $value=htmlspecialchars($value);
135+ switch(requestVar('option')){
136+ case 'showalltables':
137+ if ($columnname[$i]!='name') break;
138+ $query="SELECT * FROM '$value' LIMIT 10";
139+ $value='<a href="'.htmlspecialchars($pluginUrl).
140+ '?SQLiteCommand=QUERY&confirm=confirmed&option=showtable&ticket='.$ticket.
141+ '&query='.htmlspecialchars($query).'">'.
142+ $value.'</a>';
143+ break;
144+ default:
145+ }
146+ $value=preg_replace('/\\n$/','',$value);
147+ $value=str_replace("\n","<br />\n",$value);
148+ $infostr.="<td>".$value."</td>";
149+ }
150+ $infostr.="</tr>\n";
151+ $offset++;
152+ }
153+ $infostr.="</table>\n";
154+ switch(requestVar('option')){
155+ case 'showtable':
156+ $query=requestVar('query');
157+ $offset=(int)$offset;
158+ $query=preg_replace('/ OFFSET ([0-9]+)$/i','',$query)." OFFSET $offset";
159+ $res=nucleus_mysql_query($query);
160+ if (!nucleus_mysql_fetch_array($res)) break;
161+ $infostr.='
162+<form method="POST" action="'.htmlspecialchars($pluginUrl).'">
163+<input type="hidden" name="SQLiteCommand" value="QUERY">
164+<input type="hidden" name="confirm" value="confirmed">
165+<input type="hidden" name="ticket" value="'.$ticket.'">
166+<input type="hidden" name="query" value="'.htmlspecialchars($query).'">
167+<input type="hidden" name="option" value="showtable">
168+<input type="submit" value="More">
169+</form>';
170+ break;
171+ default:
172+ }
173+ break;
174+ default:
175+ }
176+
177+ echo $p->translated('PHP version: ').phpversion()."<br />\n";
178+ if ($res = nucleus_mysql_query('SELECT sqlite_version();')) $ret = nucleus_mysql_fetch_array($res);
179+ if (!$ret) $SQLiteVersion='?.?.?';
180+ else if (!($SQLiteVersion=$ret[0])) $SQLiteVersion='?.?.?';
181+ echo $p->translated('SQLite DB version: ').$SQLiteVersion."<br />\n";;
182+ echo $p->translated('SQLite wrapper version: ').$SQLITECONF['VERSION']."<br />\n";
183+ echo $p->translated('SQLite DB file size: ').filesize($SQLITECONF['DBFILENAME'])." bytes<br />\n";
184+ echo "<hr />\n";
185+
186+?><table><tr><th><?php echo $p->translated('Tools'); ?></th><th><?php echo $p->translated('Execute SQL Query'); ?></th></tr>
187+<tr><td>
188+<form method="POST" action="<?php echo htmlspecialchars($pluginUrl);?>">
189+<input type="hidden" name="SQLiteCommand" value="VACUUM">
190+<input type="hidden" name="ticket" value="<?php echo $ticket; ?>">
191+<input type="submit" value="<?php echo $p->translated('VACUUM'); ?>">
192+</form>
193+<form method="POST" action="<?php echo htmlspecialchars($pluginUrl);?>">
194+<input type="hidden" name="SQLiteCommand" value="integrity_check">
195+<input type="hidden" name="ticket" value="<?php echo $ticket; ?>">
196+<input type="submit" value="<?php echo $p->translated('Integrity Check'); ?>">
197+</form>
198+<form method="POST" action="<?php echo htmlspecialchars($pluginUrl);?>">
199+<select name="plugin">
200+<?php
201+ $res=nucleus_mysql_query('SELECT pfile FROM `'.sql_table('plugin').'`');
202+ while($result=nucleus_mysql_fetch_row($res)) {
203+ if (requestVar('plugin')==$result[0]) echo '<option selected value="'.$result[0].'">'.$result[0]."</option>\n";
204+ else echo '<option value="'.$result[0].'">'.$result[0]."</option>\n";
205+ }
206+?>
207+</select>
208+<input type="hidden" name="SQLiteCommand" value="plugin_check">
209+<input type="hidden" name="ticket" value="<?php echo $ticket; ?>">
210+<input type="submit" value="<?php echo $p->translated('Check plugin'); ?>">
211+</form>
212+<?php
213+ if ('yes'==$p->getOption('allowsql')) {
214+?><form method="POST" action="<?php echo htmlspecialchars($pluginUrl);?>">
215+<input type="hidden" name="SQLiteCommand" value="QUERY">
216+<input type="hidden" name="ticket" value="<?php echo $ticket; ?>">
217+<input type="hidden" name="confirm" value="confirmed">
218+<input type="hidden" name="query" value="SELECT name, sqlite_table_structure(name) as table_structure FROM sqlite_master WHERE type='table'">
219+<input type="hidden" name="option" value="showalltables">
220+<input type="submit" value="<?php echo $p->translated('Show all tables'); ?>">
221+</form><?php
222+ }
223+?>
224+</td><td><?php
225+ if ('yes'!=$p->getOption('allowsql')) echo $p->translated('Query not allowed. To use it, change the plugin option.');
226+ else {
227+?><form method="POST" action="<?php echo htmlspecialchars($pluginUrl);?>">
228+<input type="hidden" name="SQLiteCommand" value="QUERY">
229+<input type="hidden" name="ticket" value="<?php echo $ticket; ?>">
230+<textarea name="query" id="ExecQuery" cols="50" rows="10"></textarea><br />
231+<input type="submit" value="<?php echo $p->translated('Execute'); ?>">
232+<input type="checkbox" name="confirm" value="confirmed"><?php echo $p->translated('I am sure.'); ?>
233+</form>
234+<?php }
235+?></td>
236+</table>
237+<br /><?php
238+
239+ if ($infostr) echo "<hr />\n".$infostr;
240+ $pa->end();
241+?>
\ No newline at end of file
--- /dev/null
+++ b/tags/sqlite0903/sqlite/nucleus/plugins/sqlite/language/japanese-euc.php
@@ -0,0 +1,26 @@
1+<?php
2+$this->langArray['Allow SQL query during the management?']='管理の際、SQL クエリを使用しますか?';
3+$this->langArray['Number of SQL queries at once when DB restore.']='データベース復元の際、一回あたり何個の SQL クエリを実行しますか?';
4+$this->langArray['Wating tile (seconds) when DB restore.']='データベース復元の際、接続の待ち時間は何秒にしますか?';
5+$this->langArray['NP_SQLite plugin. Filesize of DB is now ']='NP_SQLite プラグイン. 現在のデータベースファイルサイズは';
6+$this->langArray['SQLite management']='SQLite 管理';
7+$this->langArray['Pluing was installed sucessfully']='プラグインは正常にインストールされました';
8+$this->langArray['I am sure.']='確かに実行します';
9+$this->langArray['Please check the "I am sure." checkbox to execute query']='クエリを実行するには"確かに実行します"をチェックしてください';
10+$this->langArray['Click this to show all']='全文を表示するにはクリックしてください';
11+$this->langArray['PHP version: ']='PHP のバージョン: ';
12+$this->langArray['SQLite DB version: ']='SQLite データベースのバージョン: ';
13+$this->langArray['SQLite wrapper version: ']='SQLite ラッパのバージョン: ';
14+$this->langArray['SQLite DB file size: ']='データベースのファイルサイズ: ';
15+$this->langArray['Query not allowed. To use it, change the plugin option.']='クエリーは使えません。使用するには、プラグインオプションを変更してください。';
16+$this->langArray['Tools']='ツール';
17+$this->langArray['Execute SQL Query']='SQL クエリの実行';
18+$this->langArray['VACUUM']='バキューム';
19+$this->langArray['Integrity Check']='整合性チェック';
20+$this->langArray['Show all tables']='全テーブルの表示';
21+$this->langArray['Execute']='実行';
22+$this->langArray['The plugin, ']='プラグイン ';
23+$this->langArray[' was checked and modified (if modification required)']=' の調査(必要な場合はその変更)が完了しました。';
24+$this->langArray['Please modify the PHP files']='次のように PHP ファイルを変更してください';
25+$this->langArray['Check plugin']='プラグインのチェック';
26+?>
\ No newline at end of file
--- /dev/null
+++ b/tags/sqlite0903/sqlite/nucleus/plugins/sqlite/language/japanese-utf8.php
@@ -0,0 +1,26 @@
1+<?php
2+$this->langArray['Allow SQL query during the management?']='管理の際、SQL クエリを使用しますか?';
3+$this->langArray['Number of SQL queries at once when DB restore.']='データベース復元の際、一回あたり何個の SQL クエリを実行しますか?';
4+$this->langArray['Wating tile (seconds) when DB restore.']='データベース復元の際、接続の待ち時間は何秒にしますか?';
5+$this->langArray['NP_SQLite plugin. Filesize of DB is now ']='NP_SQLite プラグイン. 現在のデータベースファイルサイズは';
6+$this->langArray['SQLite management']='SQLite 管理';
7+$this->langArray['Pluing was installed sucessfully']='プラグインは正常にインストールされました';
8+$this->langArray['I am sure.']='確かに実行します';
9+$this->langArray['Please check the "I am sure." checkbox to execute query']='クエリを実行するには"確かに実行します"をチェックしてください';
10+$this->langArray['Click this to show all']='全文を表示するにはクリックしてください';
11+$this->langArray['PHP version: ']='PHP のバージョン: ';
12+$this->langArray['SQLite DB version: ']='SQLite データベースのバージョン: ';
13+$this->langArray['SQLite wrapper version: ']='SQLite ラッパのバージョン: ';
14+$this->langArray['SQLite DB file size: ']='データベースのファイルサイズ: ';
15+$this->langArray['Query not allowed. To use it, change the plugin option.']='クエリーは使えません。使用するには、プラグインオプションを変更してください。';
16+$this->langArray['Tools']='ツール';
17+$this->langArray['Execute SQL Query']='SQL クエリの実行';
18+$this->langArray['VACUUM']='バキューム';
19+$this->langArray['Integrity Check']='整合性チェック';
20+$this->langArray['Show all tables']='全テーブルの表示';
21+$this->langArray['Execute']='実行';
22+$this->langArray['The plugin, ']='プラグイン ';
23+$this->langArray[' was checked and modified (if modification required)']=' の調査(必要な場合はその変更)が完了しました。';
24+$this->langArray['Please modify the PHP files']='次のように PHP ファイルを変更してください';
25+$this->langArray['Check plugin']='プラグインのチェック';
26+?>
\ No newline at end of file
--- /dev/null
+++ b/tags/sqlite0903/sqlite/nucleus/plugins/sqlite/restore.php
@@ -0,0 +1,120 @@
1+<?php
2+ /***************************************
3+ * SQLite-MySQL database transfer tool *
4+ * ver 0.8.0 *
5+ * Written by Katsumi *
6+ ***************************************/
7+
8+// This library is GPL.
9+
10+error_reporting(E_ERROR | E_WARNING);
11+chdir('../../../');
12+if (!file_exists('./nucleus/sqlite/sqlite.php')) exit;
13+
14+if (!isset($_GET['dbfile'])) exit;
15+
16+$dbfile=str_replace(array('\\','/'),array('',''),$_GET['dbfile']);
17+if (isset($_GET['numatonce'])) $numatonce=(int)$_GET['numatonce'];
18+else $numatonce=20;
19+if (isset($_GET['refreshwait'])) $refreshwait=(int)$_GET['refreshwait'];
20+else $refreshwait=1;
21+
22+// Check $dbfile
23+if (substr($dbfile,0,1)=='.') exit;
24+if (preg_match('/\.php$/i',$dbfile)) exit;
25+if (preg_match('/\.htm$/i',$dbfile)) exit;
26+if (preg_match('/\.html$/i',$dbfile)) exit;
27+if (!file_exists('./nucleus/sqlite/'.$dbfile)) exit;
28+
29+include ('./nucleus/sqlite/sqlite.php');
30+
31+$dbarray=file('./nucleus/sqlite/'.$dbfile);
32+if (isset($_GET['dbpoint'])) $dbpoint=(int)$_GET['dbpoint'];
33+else $dbpoint=0;
34+$ret='';
35+$err=false;
36+
37+while ($numatonce--) {
38+ $query='';
39+ $instring=false;
40+ $cont=true;
41+
42+ //Remove comment
43+ while (@is_string(($t=$dbarray[$dbpoint]))) {
44+ if (trim($t)!='' && substr($t,0,1)!='#' && substr($t,0,2)!='--') break;
45+ $dbpoint++;
46+ }
47+
48+ //Get query string from array
49+ while ($cont && @is_string($dbarray[$dbpoint])) {
50+ $t=$dbarray[$dbpoint++];
51+ while ($t) {
52+ if ($instring) {
53+ for ($i=0;$i<strlen($t);$i++) {
54+ $query.=($c=$t[0]);
55+ $t=substr($t,1);
56+ if ($c=="'") {
57+ $instring=false;
58+ break;
59+ } else if ($c=="\\") {
60+ $query.=$t[0];
61+ $t=substr($t,1);
62+ }
63+ }
64+ continue;
65+ }
66+ if (($c=$t[0])==';') {
67+ $cont=false;
68+ break;
69+ }
70+ $query.=$c;
71+ $t=substr($t,1);
72+ if ($c=="'") $instring=true;
73+ }
74+ }
75+ if ($query) {
76+ if (nucleus_mysql_query($query)) $ret.="OK<br/>".htmlspecialchars(substr($query,0,200)).".....<hr />\n";
77+ else $err=true;
78+ }
79+}
80+nucleus_mysql_close();
81+
82+//Set 'dbtotal'
83+$dbtotal=$dbpoint;
84+while (@is_string(($dbarray[$dbtotal]))) $dbtotal++;
85+
86+if ($dbtotal==$dbpoint) { // All done.
87+ unlink('./nucleus/sqlite/'.$dbfile);
88+ if (@include('./nucleus/language/japanese-utf8.php')) $lng='UTF-8';
89+ else if (@include('./nucleus/language/japanese-euc.php')) $lng='EUC-JP';
90+ else $lng='';
91+ echo "<html><head><title>Restore Complete</title>\n";
92+ if ($lng) echo "<meta http-equiv=\"content-type\" content=\"text/html; charset=$lng\" />\n";
93+ echo "</head><body>\n";
94+ if ($lng) {
95+ echo '<p>'._RESTORE_COMPLETE.'</p>';
96+ echo '<p><a href="../../">'._BACKTOMANAGE.'</a></p>';
97+ } else {
98+ echo '<p>Restore Complete</p>';
99+ echo '<p><a href="../../">Back to Nucleus management</a></p>';
100+ }
101+ echo "\n</body></html>";
102+ exit;
103+}
104+
105+$f=(int)((float)100*$dbpoint/$dbtotal);
106+$ret="$f % done.<hr>\n".$ret;
107+
108+if (isset($_GET['numatonce'])) $numatonce=$_GET['numatonce'];
109+else $numatonce=20;
110+$url="?dbfile=$dbfile&amp;numatonce=$numatonce&amp;refreshwait=$refreshwait&amp;dbpoint=$dbpoint";
111+if ($err) $refresh='';
112+else $refresh="<meta http-equiv=\"refresh\" content=\"$refreshwait; url=$url\">";
113+
114+?><html><head>
115+<title>Creating database file</title>
116+<?php echo $refresh; ?>
117+</head><body>
118+<a href="<?php echo $url; ?>">Continue</a><hr />
119+<?php echo $ret;
120+?></body></html>
\ No newline at end of file
--- /dev/null
+++ b/tags/sqlite0903/sqlite/nucleus/sqlite/.htaccess
@@ -0,0 +1,2 @@
1+order deny,allow
2+deny from all
--- /dev/null
+++ b/tags/sqlite0903/sqlite/nucleus/sqlite/convert.php
@@ -0,0 +1,151 @@
1+<?php
2+/*******************************************
3+* mysql_xxx => nucleus_mysql_xxx converter *
4+* for Nucleus *
5+* ver 0.8.5 Written by Katsumi *
6+*******************************************/
7+
8+// The license of this script is GPL
9+
10+function modifyConfigInstall(){
11+ // Modify config.php
12+ $pattern=array();
13+ $replace=array();
14+ array_push($pattern,'/^([\s\S]*?)include([^\(]*?)\(([\s\S]*?)\$([\s\S]+)\'globalfunctions.php\'([\s\S]*?)$/');
15+ array_push($replace,'$1include$2($3\$DIR_NUCLEUS.\'sqlite/sqlite.php\'$5'.'$1include$2($3\$$4\'globalfunctions.php\'$5');
16+ if (file_exists('./config.php')) {
17+ $before=read_from_file('./config.php');
18+ if (strpos($before,'sqlite.php')===false) {
19+ $before=file('./config.php');
20+ $after='';
21+ foreach($before as $line) $after.=preg_replace($pattern,$replace,$line);
22+ if (!write_to_file(realpath('./config.php'),$after)) ExitWithError();
23+ }
24+ }
25+
26+ // Modify install.php
27+ if (file_exists('./install.php')) {
28+ $before=read_from_file('./install.php');
29+ if (strpos($before,'sqlite.php')===false) {
30+
31+ // The same pattern/replce is also used for install.php
32+ array_push($pattern,'/aConfPlugsToInstall([\s\S]+)\'NP_SkinFiles\'/i');
33+ array_push($replace,'aConfPlugsToInstall$1\'NP_SkinFiles\',\'NP_SQLite\'');
34+ array_push($pattern,'/<input[^>]+name="mySQL_host"([^\/]+)\/>/i');
35+ array_push($replace,'<input name="mySQL_host" type="hidden" value="dummy" />Not needed for SQLite');
36+ array_push($pattern,'/<input[^>]+name="mySQL_user"([^\/]+)\/>/i');
37+ array_push($replace,'<input name="mySQL_user" type="hidden" value="dummy" />Not needed for SQLite');
38+ array_push($pattern,'/<input[^>]+name="mySQL_password"([^\/]+)\/>/i');
39+ array_push($replace,'<input name="mySQL_password" type="hidden" value="dummy" />Not needed for SQLite');
40+ array_push($pattern,'/<input[^>]+name="mySQL_database"([^\/]+)\/>/i');
41+ array_push($replace,'<input name="mySQL_database" type="hidden" value="dummy" />Not needed for SQLite');
42+ array_push($pattern,'/<input[^>]+name="mySQL_create"([^\)]+)<\/label>/i');
43+ array_push($replace,'Database will be created if not exist.');
44+ $before=file('./install.php');
45+ $after='<?php include("nucleus/sqlite/sqlite.php"); ?>';
46+ foreach($before as $line) $after.=preg_replace($pattern,$replace,$line);
47+ if (!write_to_file(realpath('./install.php'),$after)) ExitWithError();
48+ }
49+ }
50+
51+ // Modify backup.php
52+ if (!modifyBackup('./nucleus/libs/backup.php')) // less than version 3.3
53+ modifyBackup('./nucleus/plugins/backup/NP_BackupAdmin.php','class'); // more than version 3.4 (??)
54+
55+ // Modify install.sql
56+ if (file_exists('./install.sql')) {
57+ $before=file('./install.sql');
58+ $pluginoptiontable=false;
59+ $after='';
60+ foreach($before as $line){
61+ if ($pluginoptiontable) {
62+ if (preg_match('/TYPE\=MyISAM;/i',$line)) $pluginoptiontable=false;
63+ else if (preg_match('/`oid`[\s]+int\(11\)[\s]+NOT[\s]+NULL[\s]+auto_increment/i',$line))
64+ $line=preg_replace('/[\s]+auto_increment/i'," default '0'",$line);
65+ } else {
66+ if (preg_match('/CREATE[\s]+TABLE[\s]+`nucleus_plugin_option`/i',$line)) $pluginoptiontable=true;
67+ }
68+ if (strlen($after)==0) {
69+ $replace='PRAGMA synchronous = off;';
70+ if (!strstr($line,$replace)) $after=preg_replace('/^[^\r\n]*([\r\n]*)$/',$replace.'$1$1',$line);
71+ }
72+ $after.=$line;
73+ }
74+ if ($after!=$before) {
75+ if (!write_to_file(realpath('./install.sql'),$after)) ExitWithError();
76+ }
77+ }
78+}
79+
80+function modifyBackup($file,$type='global'){
81+ if (!file_exists($file)) return false;
82+ $before=read_from_file($file);
83+ if (strpos($before,'sqlite_restore_execute_queries')===false) {
84+ $pattern='/_execute_queries[\s]*\(([^\)]+)\)[\s]*;/i';
85+ if ($type=='class') $pattern='/\$this->_execute_queries[\s]*\(([^\)]+)\)[\s]*;/i';
86+ $replace='sqlite_restore_execute_queries($1);';
87+ $after=preg_replace($pattern,$replace,$before);
88+ if (!write_to_file(realpath($file),$after)) ExitWithError();
89+ }
90+ return true;
91+}
92+
93+function seekPhpFiles($dir,&$phpfiles,$myself){
94+ if (!is_dir($dir)) return;
95+ $d = dir($dir);
96+ $dirpath=realpath($d->path);
97+ $dirs=array();
98+ if (substr($dirpath,-1)!='/' && substr($dirpath,-1)!="\\") $dirpath.='/';
99+ while (false !== ($entry = $d->read())) {
100+ if ($entry=='.' || $entry=='..') continue;
101+ if (is_file($dirpath.$entry) && substr($entry,-4)=='.php' && $entry!==$myself) array_push($phpfiles,realpath($dirpath.$entry));
102+ if (is_dir($dirpath.$entry) && $entry!='language' && $entry!='sqlite' ) array_push($dirs,realpath($dirpath.$entry));
103+ }
104+ $d->close();
105+ foreach($dirs as $dir) seekPhpFiles($dir,$phpfiles,$myself);
106+}
107+function changeFunctions($file){
108+ if (!is_file($file=realpath($file))) return false;
109+ if (!is_readable($file)) {
110+ echo "Cannot read: $file<br />\n";
111+ return false;
112+ }
113+ $before=read_from_file($file);
114+ $after=do_replace($before);
115+ if ($before!=$after) return write_to_file($file,$after);
116+ return true;
117+}
118+function do_replace(&$text) {
119+ // Do this process until change does not occur any more...
120+ // Otherwise, sometime file is not completely modified.
121+ // This is indeed the case for BLOG.php.
122+ $after=$text;
123+ do $after=preg_replace('/([^_])mysql_([_a-z]+)([\s]*?)\(/','$1nucleus_mysql_$2(',($before=$after));
124+ while ($before!=$after);
125+ return $after;
126+}
127+function read_from_file($file) {
128+ if (function_exists('file_get_contents') ) $ret=file_get_contents($file);
129+ else {
130+ ob_start();
131+ readfile($file);
132+ $ret=ob_get_contents();
133+ ob_end_clean();
134+ }
135+ return $ret;
136+}
137+function write_to_file($file,&$text){
138+ if (!$handle = @fopen($file, 'w')) {
139+ echo "Cannot change: $file<br />\n";
140+ return false;
141+ }
142+ fwrite($handle,$text);
143+ fclose($handle);
144+ echo "Changed: $file<br />\n";
145+ return true;
146+}
147+function ExitWithError($text='Error occured.') {
148+ echo "$text</body></html>";
149+ exit;
150+}
151+?>
\ No newline at end of file
--- /dev/null
+++ b/tags/sqlite0903/sqlite/nucleus/sqlite/index.html
@@ -0,0 +1 @@
1+<html><body></body></html>
\ No newline at end of file
--- /dev/null
+++ b/tags/sqlite0903/sqlite/nucleus/sqlite/note.txt
@@ -0,0 +1,82 @@
1+
2+ The licence of this script is GPL
3+
4+ ACKOWLEDGMENT
5+
6+ I thank all the people of Nucleus JP forum
7+ who discussed this project. Especially, I
8+ thank kosugiatkips, mekyo, and nakahara21
9+ for ideas of some part of code.
10+ I also thank Jon Jensen for his generous
11+ acceptance for using his PHP code in the
12+ earlier version of this library.
13+
14+ The features that are supported by this library but not
15+ generally by SQLite are as follows:
16+
17+ CREATE TABLE IF NOT EXISTS, auto_increment,
18+ DROP TABLE IF EXISTS, ALTER TABLE,
19+ RENAME TABLE, DESC,
20+ INSERT INTO ... SET xx=xx, xx=xx,
21+ REPLACE INTO ... SET xx=xx, xx=xx,
22+ SHOW KEYS FROM, SHOW INDEX FROM,
23+ SHOW FIELDS FROM, SHOW COLUMNS FROM,
24+ CREATE TABLE ... KEYS xxx (xxx,xxx)
25+ SHOW TABLES LIKE, TRUNCATE TABLE
26+ SHOW TABLES
27+
28+
29+ Following functions are available in SQL query.
30+
31+ CONCAT, IF, IFNULL, NULLIF, SUBSTRING,
32+ match() against(),
33+ replace, UNIX_TIMESTAMP, REGEXP, DAYOFMONTH, MONTH, YEAR,
34+ ADDDATE, DATE_ADD, SUBDATE, DATE_SUB, FIND_IN_SET,
35+ CURDATE, CURRENT_DATE, CURTIME, CURRENT_TIME, CURRENT_TIMESTAMP,
36+ LOCALTIME, LOCALTIMESTAMP, SYSDATE, DATE_FORMAT, TIME_FORMAT,
37+ DAYNAME, DAYOFWEEK, DAYOFYEAR, EXTRACT, FROM_DAYS, FROM_UNIXTIME,
38+ HOUR, MINUTE, MONTH, MONTHNAME, PERIOD_ADD, PERIOD_DIFF, QUARTER,
39+ SECOND, SEC_TO_TIME, SECOND, WEEK, WEEKDAY, YEAR, YEARWEEK,
40+ FORMAT, INET_ATON, INET_NTOA, MD5,
41+ ACOS, ASIN, ATAN, CEIL, CEILING, COS, COT, CRC32, DEGREES,
42+ EXP, FLOOR, GREATEST, MAX, LEAST, MIN, ln, log, log2, log10,
43+ MOD, PI, POW, POWER, RADIANS, RAND, SIGN, SIN, SQRT, TAN,
44+ ASCII, BIN, BIT_LENGTH, CHAR, CHAR_LENGTH, CONCAT_WS,
45+ CONV, ELT, EXPORT_SET, FIELD, HEX, INSERT, LOCATE,
46+ INSTR, LCASE, LOWER, LEFT, LENGTH, OCTET_LENGTH,
47+ LOAD_FILE, LPAD, LTRIM, MAKE_SET, MID, SUBSTRING,
48+ OCT, ORD, QUOTE, REPEAT, REVERSE, RIGHT, RPAD,
49+ RTRIM, SOUNDEX, SPACE, SUBSTRING_INDEX, TRIM,
50+ UCASE, UPPER,
51+
52+
53+ Release note:
54+ Version 0.8.0
55+ -This is the first established version and
56+ exactly the same as ver 0.7.8b.
57+
58+ Version 0.8.1
59+ -Execute "PRAGMA short_column_names=1" first.
60+ -Avoid executing outside php file in some very specfic environment.
61+ -Avoid executing multiple queries using ";" as delimer.
62+ -Add check routine for the installed SQLite
63+
64+ Version 0.8.5
65+ -Use SQLite_Functions class
66+ -'PRAGMA synchronous = off;' when installing
67+
68+ Version 0.8.5.5
69+ - ALTER TABLE syntaxes updated, bugs fixed
70+
71+ Version 0.8.6.0
72+ - ALTER TABLE almost completery re-written
73+ - DESC 'table' 'field' supported
74+ - The function 'php' is unregestered from SQL query.
75+
76+ Version 0.9.0.1
77+ - Support RENAME TABLE
78+ - Some tunings are done to improve the speed.
79+
80+ Version 0.9.0.2
81+ - Debug of CREATE TABLE routine.
82+ - NP_SQLite: trim the query when 'Copy' is used.
--- /dev/null
+++ b/tags/sqlite0903/sqlite/nucleus/sqlite/sqlite.php
@@ -0,0 +1,557 @@
1+<?php
2+ /****************************************
3+ * SQLite-MySQL wrapper for Nucleus *
4+ * ver 0.9.0.3 *
5+ * Written by Katsumi *
6+ ****************************************/
7+
8+// Check SQLite installed
9+
10+if (!function_exists('sqlite_open')) exit('Sorry, SQLite is not available from PHP (maybe, not installed in the server).');
11+
12+// Initializiation stuff
13+require_once dirname(__FILE__) . '/sqliteconfig.php';
14+$SQLITE_DBHANDLE=sqlite_open($SQLITECONF['DBFILENAME']);
15+require_once dirname(__FILE__) . '/sqlitequeryfunctions.php';
16+$SQLITECONF['VERSION']='0.9.0.3';
17+
18+//Following thing may work if MySQL is NOT installed in server.
19+if (!function_exists('mysql_query')) {
20+ define ("MYSQL_ASSOC", SQLITE_ASSOC);
21+ define ("MYSQL_BOTH", SQLITE_BOTH);
22+ define ("MYSQL_NUM", SQLITE_NUM);
23+ function mysql_connect(){
24+ global $SQLITECONF;
25+ $SQLITECONF['OVERRIDEMODE']=true;
26+ $args=func_get_args();
27+ return call_user_func_array('nucleus_mysql_connect',$args);
28+ }
29+ foreach (array('mysql_affected_rows','mysql_change_user','mysql_client_encoding','mysql_close',
30+ 'mysql_create_db','mysql_data_seek','mysql_db_name','mysql_db_query','mysql_drop_db','mysql_errno',
31+ 'mysql_error','mysql_escape_string','mysql_fetch_array','mysql_fetch_assoc','mysql_fetch_field','mysql_fetch_lengths',
32+ 'mysql_fetch_object','mysql_fetch_row','mysql_field_flags','mysql_field_len','mysql_field_name','mysql_field_seek',
33+ 'mysql_field_table','mysql_field_type','mysql_free_result','mysql_get_client_info','mysql_get_host_info',
34+ 'mysql_get_proto_info','mysql_get_server_info','mysql_info','mysql_insert_id','mysql_list_dbs',
35+ 'mysql_list_fields','mysql_list_processes','mysql_list_tables','mysql_num_fields','mysql_num_rows','mysql_numrows',
36+ 'mysql_pconnect','mysql_ping','mysql_query','mysql_real_escape_string','mysql_result','mysql_select_db',
37+ 'mysql_stat','mysql_tablename','mysql_thread_id','mysql_unbuffered_query')
38+ as $value) eval(
39+ "function $value(){\n".
40+ " \$args=func_get_args();\n".
41+ " return call_user_func_array('nucleus_$value',\$args);\n".
42+ "}\n");
43+}
44+
45+// Empty object for mysql_fetch_object().
46+class SQLITE_OBJECT {}
47+
48+function sqlite_ReturnWithError($text='Not supported',$more=''){
49+ // Show warning when error_reporting() is set.
50+ if (!(error_reporting() & E_WARNING)) return false;
51+
52+ // Seek the file and line that originally called sql function.
53+ $a=debug_backtrace();
54+ foreach($a as $key=>$btrace) {
55+ if (!($templine=$btrace['line'])) continue;
56+ if (!($tempfile=$btrace['file'])) continue;
57+ $file=str_replace('\\','/',$file);
58+ if (!$line && !$file && strpos($tempfile,'/sqlite.php')===false && strpos($tempfile,'/sqlitequeryfunctions.php')===false) {
59+ $line=$templine;
60+ $file=$tempfile;
61+ }
62+ echo "\n<!--$tempfile line:$templine-->\n";
63+ }
64+ echo "Warning from SQLite-MySQL wrapper: $text<br />\n";
65+ if ($line && $file) echo "in <b>$file</b> on line <b>$line</b><br />\n";
66+ echo $more;
67+ return false;
68+}
69+function sqlite_DebugMessage($text=''){
70+ global $SQLITECONF;
71+ if (!$SQLITECONF['DEBUGREPORT']) return;
72+ if ($text) $SQLITECONF['DEBUGMESSAGE'].="\n".$text."\n";
73+ if (headers_sent()) {
74+ echo '<!--sqlite_DebugMessage'.$SQLITECONF['DEBUGMESSAGE'].'sqlite_DebugMessage-->';
75+ unset($SQLITECONF['DEBUGMESSAGE']);
76+ }
77+}
78+
79+// nucleus_mysql_XXXX() functions follow.
80+
81+function nucleus_mysql_connect($p1=null,$p2=null,$p3=null,$p4=null,$p5=null){
82+ // All prameters are ignored.
83+ global $SQLITE_DBHANDLE,$SQLITECONF;
84+ if (!$SQLITE_DBHANDLE) $SQLITE_DBHANDLE=sqlite_open($SQLITECONF['DBFILENAME']);
85+ // Initialization queries.
86+ foreach($SQLITECONF['INITIALIZE'] as $value) nucleus_mysql_query($value);
87+ // Unregister the function 'php' in sql query.
88+ sqlite_create_function($SQLITE_DBHANDLE,'php','pi');
89+ return $SQLITE_DBHANDLE;
90+}
91+
92+function nucleus_mysql_close($p1=null){
93+ global $SQLITE_DBHANDLE;
94+ if (!($dbhandle=$p1)) $dbhandle=$SQLITE_DBHANDLE;
95+ $SQLITE_DBHANDLE='';
96+ return sqlite_close ($dbhandle);
97+}
98+
99+function nucleus_mysql_select_db($p1,$p2=null){
100+ // SQLite does not support multiple databases in a file.
101+ // So this function do nothing and always returns true.
102+ // Note: mysql_select_db() function returns true/false,
103+ // not link-ID.
104+ return true;
105+}
106+
107+function nucleus_mysql_query($p1,$p2=null,$unbuffered=false){//echo htmlspecialchars($p1)."<br />\n";
108+ global $SQLITE_DBHANDLE,$SQLITECONF;
109+ if (!($dbhandle=$p2)) $dbhandle=$SQLITE_DBHANDLE;
110+ $query=trim($p1);
111+ if (strpos($query,"\xEF\xBB\xBF")===0) $query=substr($query,3);// UTF-8 stuff
112+ if (substr($query,-1)==';') $query=substr($query,0,strlen($query)-1);
113+
114+ // Escape style is changed from MySQL type to SQLite type here.
115+ // This is important to avoid possible SQL-injection.
116+ $strpositions=array();// contains the data show where the strings are (startposition => endposition)
117+ if (strpos($query,'`')!==false || strpos($query,'"')!==false || strpos($query,"'")!==false)
118+ $strpositions=sqlite_changeQuote($query);
119+ //echo "<br />".htmlspecialchars($p1)."<br /><br />\n".htmlspecialchars($query)."<hr />\n";
120+
121+ // Debug mode
122+ if ($SQLITECONF['DEBUGMODE']) $query=sqlite_mysql_query_debug($query);
123+
124+ // Anyway try it.
125+ if ($unbuffered) {
126+ if ($ret=@sqlite_unbuffered_query($dbhandle,$query)) return $ret;
127+ } else {
128+ if ($ret=@sqlite_query($dbhandle,$query)) return $ret;
129+ }
130+
131+ // Error occured. Query must be translated.
132+ return sqlite_mysql_query_sub($dbhandle,$query,$strpositions,$p1,$unbuffered);
133+}
134+function sqlite_mysql_query_sub($dbhandle,$query,$strpositions=array(),$p1=null,$unbuffered=false){//echo htmlspecialchars($p1)."<br />\n";
135+ // Query translation is needed, especially when changing the data in database.
136+ // So far, this routine is written for 'CREATE TABLE','DROP TABLE', 'INSERT INTO',
137+ // 'SHOW TABLES LIKE', 'SHOW KEYS FROM', 'SHOW INDEX FROM'
138+ // and several functions used in query.
139+ // How about 'UPDATE' ???
140+ global $SQLITE_DBHANDLE,$SQLITECONF;
141+ $beforetrans=time()+microtime();
142+ if (!$p1) $p1=$query;
143+ $morequeries=array();
144+ $temptable=false;
145+ $uquery=strtoupper($query);
146+ if (strpos($uquery,'CREATE TABLE')===0 || ($temptable=(strpos($uquery,'CREATE TEMPORARY TABLE')===0))) {
147+ if (!($i=strpos($query,'('))) return sqlite_ReturnWithError('nucleus_mysql_query: '.$p1);
148+ //check if the command is 'CREATE TABLE IF NOT EXISTS'
149+ if (strpos(strtoupper($uquery),'CREATE TABLE IF NOT EXISTS')===0) {
150+ $tablename=trim(substr($query,26,$i-26));
151+ if (substr($tablename,0,1)!="'") $tablename="'$tablename'";
152+ $res=sqlite_query($dbhandle,"SELECT tbl_name FROM sqlite_master WHERE tbl_name=$tablename LIMIT 1");
153+ if (nucleus_mysql_num_rows($res)) return true;
154+ } else {
155+ $tablename=trim(substr($query,12,$i-12));
156+ if (substr($tablename,0,1)!="'") $tablename="'$tablename'";
157+ }
158+ $query=trim(substr($query,$i+1));
159+ for ($i=strlen($query);0<$i;$i--) if ($query[$i]==')') break;
160+ $query=substr($query,0,$i);
161+ $commands=_sqlite_divideByChar(',',$query);
162+ require_once(dirname(__FILE__) . '/sqlitealtertable.php');
163+ $query=sqlite_createtable_query($commands,$tablename,$temptable,$morequeries);
164+ } else if (strpos($uquery,'DROP TABLE IF EXISTS')===0) {
165+ if (!($i=strpos($query,';'))) $i=strlen($query);
166+ $tablename=trim(substr($query,20,$i-20));
167+ if (substr($tablename,0,1)!="'") $tablename="'$tablename'";
168+ $res=sqlite_query($dbhandle,"SELECT tbl_name FROM sqlite_master WHERE tbl_name=$tablename LIMIT 1");
169+ if (!nucleus_mysql_num_rows($res)) return true;
170+ $query='DROP TABLE '.$tablename;
171+ } else if (strpos($uquery,'ALTER TABLE ')===0) {
172+ $query=trim(substr($query,11));
173+ if ($i=strpos($query,' ')) {
174+ $tablename=trim(substr($query,0,$i));
175+ $query=trim(substr($query,$i));
176+ require_once(dirname(__FILE__) . '/sqlitealtertable.php');
177+ $ret =sqlite_altertable($tablename,$query,$dbhandle);
178+ if (!$ret) sqlite_ReturnWithError('SQL error',"<br /><i>".nucleus_mysql_error()."</i><br />".htmlspecialchars($p1)."<br /><br />\n".htmlspecialchars("ALTER TABLE $tablename $query")."<hr />\n");
179+ return $ret;
180+ }
181+ // Else, syntax error
182+ } else if (strpos($uquery,'RENAME TABLE ')===0) {
183+ require_once(dirname(__FILE__) . '/sqlitealtertable.php');
184+ return sqlite_renametable(_sqlite_divideByChar(',',substr($query,13)),$dbhandle);
185+ } else if (strpos($uquery,'INSERT INTO ')===0 || strpos($uquery,'REPLACE INTO ')===0 ||
186+ strpos($uquery,'INSERT IGNORE INTO ')===0 || strpos($uquery,'REPLACE IGNORE INTO ')===0) {
187+ $buff=str_replace(' IGNORE ',' OR IGNORE ',substr($uquery,0,($i=strpos($uquery,' INTO ')+6)));
188+ $query=trim(substr($query,$i));
189+ if ($i=strpos($query,' ')) {
190+ $buff.=trim(substr($query,0,$i+1));
191+ $query=trim(substr($query,$i));
192+ }
193+ if ($i=strpos($query,' ')) {
194+ if (strpos(strtoupper($query),'SET')===0) {
195+ $query=trim(substr($query,3));
196+ $commands=_sqlite_divideByChar(',',$query);
197+ $query=' VALUES(';
198+ $buff.=' (';
199+ foreach($commands as $key=>$value){
200+ //echo "[".htmlspecialchars($value)."]";
201+ if (0<$key) {
202+ $buff.=', ';
203+ $query.=', ';
204+ }
205+ if ($i=strpos($value,'=')) {
206+ $buff.=trim(substr($value,0,$i));
207+ $query.=substr($value,$i+1);
208+ }
209+ }
210+ $buff.=')';
211+ $query.=')';
212+ } else {
213+ $beforevalues='';
214+ $commands=_sqlite_divideByChar(',',$query);
215+ $query='';
216+ foreach($commands as $key=>$value){
217+ if ($beforevalues=='' && preg_match('/^(.*)\)\s+VALUES\s+\(/i',$value,$matches)) {
218+ $beforevalues=$buff.' '.$query.$matches[1].')';
219+ }
220+ if (0<$key) $query.=$beforevalues.' VALUES ';// supports multiple insertion
221+ $query.=$value.';';
222+ }
223+ }
224+ }
225+ $query=$buff.' '.$query;
226+ } else if (strpos($uquery,'SHOW TABLES LIKE ')===0) {
227+ $query='SELECT name FROM sqlite_master WHERE type=\'table\' AND name LIKE '.substr($query,17);
228+ } else if (strpos($uquery,'SHOW TABLES')===0) {
229+ $query='SELECT name FROM sqlite_master WHERE type=\'table\'';
230+ } else if (strpos($uquery,'SHOW KEYS FROM ')===0) {
231+ require_once(dirname(__FILE__) . '/sqlitealtertable.php');
232+ $query=sqlite_showKeysFrom(trim(substr($query,15)),$dbhandle);
233+ } else if (strpos($uquery,'SHOW INDEX FROM ')===0) {
234+ require_once(dirname(__FILE__) . '/sqlitealtertable.php');
235+ $query=sqlite_showKeysFrom(trim(substr($query,16)),$dbhandle);
236+ } else if (strpos($uquery,'SHOW FIELDS FROM ')===0) {
237+ require_once(dirname(__FILE__) . '/sqlitealtertable.php');
238+ $query=sqlite_showFieldsFrom(trim(substr($query,17)),$dbhandle);
239+ } else if (strpos($uquery,'SHOW COLUMNS FROM ')===0) {
240+ require_once(dirname(__FILE__) . '/sqlitealtertable.php');
241+ $query=sqlite_showFieldsFrom(trim(substr($query,18)),$dbhandle);
242+ } else if (strpos($uquery,'TRUNCATE TABLE ')===0) {
243+ $query='DELETE FROM '.substr($query,15);
244+ } else if (preg_match('/^DESC \'([^\']+)\' \'([^\']+)\'$/',$query,$m)) {
245+ return nucleus_mysql_query("SHOW FIELDS FROM '$m[1]' LIKE '$m[2]'");
246+ } else if (preg_match('/^DESC ([^\s]+) ([^\s]+)$/',$query,$m)) {
247+ return nucleus_mysql_query("SHOW FIELDS FROM '$m[1]' LIKE '$m[2]'");
248+ } else SQLite_Functions::sqlite_modifyQueryForUserFunc($query,$strpositions);
249+
250+ //Throw query again.
251+ $aftertrans=time()+microtime();
252+ if ($unbuffered) {
253+ $ret=sqlite_unbuffered_query($dbhandle,$query);
254+ } else {
255+ $ret=sqlite_query($dbhandle,$query);
256+ }
257+
258+ $afterquery=time()+microtime();
259+ if ($SQLITECONF['MEASURESPEED']) sqlite_DebugMessage("translated query:$query\n".
260+ 'translation: '.($aftertrans-$beforetrans).'sec, query: '.($afterquery-$aftertrans).'sec');
261+ if (!$ret) sqlite_ReturnWithError('SQL error',"<br /><i>".nucleus_mysql_error()."</i><br />".htmlspecialchars($p1)."<br /><br />\n".htmlspecialchars($query)."<hr />\n");
262+ foreach ($morequeries as $value) if ($value) @sqlite_query($dbhandle,$value);
263+ return $ret;
264+}
265+function sqlite_changeQuote(&$query){
266+ // This function is most important.
267+ // When you modify this function, do it very carefully.
268+ // Otherwise, you may allow crackers to do SQL-injection.
269+ // This function returns array that shows where the strings are.
270+ $sarray=array();
271+ $ret='';
272+ $qlen=strlen($query);
273+ for ($i=0;$i<$qlen;$i++) {
274+ // Go to next quote
275+ if (($i1=strpos($query,'"',$i))===false) $i1=$qlen;
276+ if (($i2=strpos($query,"'",$i))===false) $i2=$qlen;
277+ if (($i3=strpos($query,'`',$i))===false) $i3=$qlen;
278+ if ($i1==$qlen && $i2==$qlen && $i3==$qlen) {
279+ $temp=preg_replace('/[\s]+/',' ',substr($query,$i)); // Change all spacying to ' '.
280+ $ret.=($temp);
281+ if (strstr($temp,';')) exit('Warning: try to use more than two queries?');
282+ break;
283+ }
284+ if ($i2<($j=$i1)) $j=$i2;
285+ if ($i3<$j) $j=$i3;
286+ $temp=preg_replace('/[\s]+/',' ',substr($query,$i,$j-$i)); // Change all spacying to ' '.
287+ $ret.=($temp);
288+ $c=$query[($i=$j)]; // $c keeps the type of quote.
289+ if (strstr($temp,';')) exit('Warning: try to use more than two queries?');
290+
291+ // Check between quotes.
292+ // $j shows the begging positioin.
293+ // $i will show the ending position.
294+ $j=(++$i);
295+ while ($i<$qlen) {
296+ if (($i1=strpos($query,$c,$i))===false) $i1=$qlen;
297+ if (($i2=strpos($query,"\\",$i))===false) $i2=$qlen;
298+ if ($i2<$i1) {
299+ // \something. Skip two characters.
300+ $i=$i2+2;
301+ continue;
302+ } if ($i1<($qlen-1) && $query[$i1+1]==$c) {
303+ // "", '' or ``. Skip two characters.
304+ $i=$i1+2;
305+ continue;
306+ } else {// OK. Reached the end position
307+ $i=$i1;
308+ break;
309+ }
310+ }
311+ $i1=strlen($ret);
312+ $ret.="'".sqlite_changeslashes(substr($query,$j,$i-$j));
313+ if ($i<$qlen) $ret.="'"; //else Syntax error in query.
314+ $i2=strlen($ret);
315+ $sarray[$i1]=$i2;
316+ }//echo htmlspecialchars($query).'<br />'.htmlspecialchars($ret).'<br />';
317+ $query=$ret;
318+ return $sarray;
319+}
320+function sqlite_changeslashes(&$text){
321+ // By SQLite, "''" is used in the quoted string instead of "\'".
322+ // In addition, only "'" seems to be allowed for perfect quotation of string.
323+ // This routine is used for the conversion from MySQL type to SQL type.
324+ // Do NOT use stripslashes() but use stripcslashes(). Otherwise, "\r\n" is not converted.
325+ if ($text==='') return '';
326+ return (sqlite_escape_string (stripcslashes((string)$text)));
327+}
328+function _sqlite_divideByChar($char,$query,$limit=-1){
329+ if (!is_array($char)) $char=array($char);
330+ $ret=array();
331+ $query=trim($query);
332+ $buff='';
333+ while (strlen($query)){
334+ $i=strlen($query);
335+ foreach($char as $value){
336+ if (($j=strpos($query,$value))!==false) {
337+ if ($j<$i) $i=$j;
338+ }
339+ }
340+ if (($j=strpos($query,'('))===false) $j=strlen($query);
341+ if (($k=strpos($query,"'"))===false) $k=strlen($query);
342+ if ($i<$j && $i<$k) {// ',' found
343+ $buff.=substr($query,0,$i);
344+ if (strlen($buff)) $ret[]=$buff;
345+ $query=trim(substr($query,$i+1));
346+ $buff='';
347+ $limit--;
348+ if ($limit==0) exit;
349+ } else if ($j<$i && $j<$k) {// '(' found
350+ if (($i=strpos($query,')',$j))===false) {
351+ $buff.=$query;
352+ if (strlen($buff)) $ret[]=$buff;
353+ $query=$buff='';
354+ } else {
355+ $buff.=substr($query,0,$i+1);
356+ $query=substr($query,$i+1);
357+ }
358+ } else if ($k<$i && $k<$j) {// "'" found
359+ if (($i=strpos($query,"'",$k+1))===false) {
360+ $buff.=$query;
361+ if (strlen($buff)) $ret[]=$buff;
362+ $query=$buff='';
363+ } else {
364+ $buff.=substr($query,0,$i+1);
365+ $query=substr($query,$i+1);
366+ }
367+ } else {// last column
368+ $buff.=$query;
369+ if (strlen($buff)) $ret[]=$buff;
370+ $query=$buff='';
371+ }
372+ }
373+ if (strlen($buff)) $ret[]=$buff;
374+ return $ret;
375+}
376+function sqlite_mysql_query_debug(&$query){
377+ // There is nothing to do here in this version.
378+ return $query;
379+}
380+
381+function nucleus_mysql_list_tables($p1=null,$p2=null) {
382+ global $SQLITE_DBHANDLE,$MYSQL_DATABASE;
383+ return sqlite_query($SQLITE_DBHANDLE,"SELECT name as Tables_in_$MYSQL_DATABASE FROM sqlite_master WHERE type='table'");
384+}
385+function nucleus_mysql_listtables($p1=null,$p2=null) { return nucleus_mysql_list_tables($p1,$p2);}
386+
387+function nucleus_mysql_affected_rows($p1=null){
388+ global $SQLITE_DBHANDLE;
389+ if (!($dbhandle=$p1)) $dbhandle=$SQLITE_DBHANDLE;
390+ return sqlite_changes($dbhandle);
391+}
392+
393+function nucleus_mysql_error($p1=null){
394+ global $SQLITE_DBHANDLE;
395+ if (!($dbhandle=$p1)) $dbhandle=$SQLITE_DBHANDLE;
396+ return sqlite_error_string ( sqlite_last_error ($dbhandle) );
397+}
398+
399+function nucleus_mysql_fetch_array($p1,$p2=SQLITE_BOTH){
400+ return sqlite_fetch_array ($p1,$p2);
401+}
402+
403+function nucleus_mysql_fetch_assoc($p1){
404+ return sqlite_fetch_array($p1,SQLITE_ASSOC);
405+}
406+
407+function nucleus_mysql_fetch_object($p1,$p2=SQLITE_BOTH){
408+ if (is_array($ret=sqlite_fetch_array ($p1,$p2))) {
409+ $o=new SQLITE_OBJECT;
410+ foreach ($ret as $key=>$value) {
411+ if (strstr($key,'.')) {// Remove table name.
412+ $key=preg_replace('/^(.+)\."(.+)"$/','"$2"',$key);
413+ $key=preg_replace('/^(.+)\.([^.^"]+)$/','$2',$key);
414+ }
415+ $o->$key=$value;
416+ }
417+ return $o;
418+ } else return false;
419+}
420+
421+function nucleus_mysql_fetch_row($p1){
422+ return sqlite_fetch_array($p1,SQLITE_NUM);
423+}
424+
425+function nucleus_mysql_field_name($p1,$p2){
426+ return sqlite_field_name ($p1,$p2);
427+}
428+
429+function nucleus_mysql_free_result($p1){
430+ // ???? Cannot find corresponding function of SQLite.
431+ // Maybe SQLite is NOT used for the high spec server
432+ // that need mysql_free_result() function because of
433+ // many SQL-queries in a script.
434+ return true;
435+}
436+
437+function nucleus_mysql_insert_id($p1=null){
438+ global $SQLITE_DBHANDLE;
439+ if (!($dbhandle=$p1)) $dbhandle=$SQLITE_DBHANDLE;
440+ return sqlite_last_insert_rowid ($dbhandle);
441+}
442+
443+function nucleus_mysql_num_fields($p1){
444+ return sqlite_num_fields ($p1);
445+}
446+
447+function nucleus_mysql_num_rows($p1){
448+ return sqlite_num_rows ($p1);
449+}
450+function nucleus_mysql_numrows($p1){
451+ return sqlite_num_rows ($p1);
452+}
453+
454+function nucleus_mysql_result($p1,$p2,$p3=null){
455+ if ($p3) return sqlite_ReturnWithError('nucleus_mysql_result');
456+ if (!$p2) return sqlite_fetch_single ($p1);
457+ $a=sqlite_fetch_array ($p1);
458+ return $a[$p2];
459+}
460+
461+function nucleus_mysql_unbuffered_query($p1,$p2=null){
462+ return nucleus_mysql_query($p1,$p2,true);
463+}
464+
465+function nucleus_mysql_client_encoding($p1=null){
466+ return sqlite_libencoding();
467+}
468+
469+function nucleus_mysql_data_seek($p1,$p2) {
470+ return sqlite_seek($p1,$p2);
471+}
472+
473+function nucleus_mysql_errno ($p1=null){
474+ global $SQLITE_DBHANDLE;
475+ if (!($dbhandle=$p1)) $dbhandle=$SQLITE_DBHANDLE;
476+ return sqlite_last_error($dbhandle);
477+}
478+
479+function nucleus_mysql_escape_string ($p1){
480+ // The "'" will be changed to "''".
481+ // This way works for both MySQL and SQLite when single quotes are used for string.
482+ // Note that single quote is always used in this wrapper.
483+ // If a plugin is made on SQLite-Nucleus and such plugin will be used for MySQL-Nucleus,
484+ // nucleus_mysql_escape_string() will be changed to mysql_escape_string() and
485+ // this routine won't be used, so this way won't be problem.
486+ return sqlite_escape_string($p1);
487+}
488+
489+function nucleus_mysql_real_escape_string ($p1,$p2=null){
490+ //addslashes used here.
491+ return addslashes($p1);
492+}
493+
494+function nucleus_mysql_create_db ($p1,$p2=null){
495+ // All prameters are ignored.
496+ // Returns always true;
497+ return true;
498+}
499+
500+function nucleus_mysql_pconnect($p1=null,$p2=null,$p3=null,$p4=null,$p5=null){
501+ global $SQLITE_DBHANDLE,$SQLITECONF;
502+ sqlite_close ($SQLITE_DBHANDLE);
503+ $SQLITE_DBHANDLE=sqlite_popen($SQLITECONF['DBFILENAME']);
504+ return ($SQLITE['DBHANDLE']=$SQLITE_DBHANDLE);
505+}
506+
507+function nucleus_mysql_fetch_field($p1,$p2=null){
508+ if ($p2) return sqlite_ReturnWithError('nucleus_mysql_fetch_field');
509+ // Only 'name' is supported.
510+ $o=new SQLITE_OBJECT;
511+ $o->name=array();
512+ if(is_array($ret=sqlite_fetch_array ($p1,SQLITE_ASSOC )))
513+ foreach ($ret as $key=>$value) {
514+ if (is_string($key)) array_push($o->name,$key);
515+ }
516+ return $o;
517+
518+}
519+
520+// This function is called instead of _execute_queries() in backp.php
521+function sqlite_restore_execute_queries(&$query){
522+ global $DIR_NUCLEUS,$DIR_LIBS,$DIR_PLUGINS,$CONF;
523+
524+ // Skip until the first "#" or "--"
525+ if (($i=strpos($query,"\n#"))===false) $i=strlen($query);
526+ if (($j=strpos($query,"\n--"))===false) $j=strlen($query);
527+ if ($i<$j) $query=substr($query,$i+1);
528+ else $query=substr($query,$j+1);
529+
530+ // Save the query to temporary file in sqlite directory.
531+ if (function_exists('microtime')) {
532+ $prefix=preg_replace('/[^0-9]/','',microtime());
533+ } else {
534+ srand(time());
535+ $prefix=(string)rand(0,999999);
536+ }
537+ $tmpname=tempnam($DIR_NUCLEUS.'sqlite/',"tmp$prefix");
538+ if (!($handle=@fopen($tmpname,'w'))) return 'Cannot save temporary DB file.';
539+ fwrite($handle,$query);
540+ fclose($handle);
541+ $tmpname=preg_replace('/[\s\S]*?[\/\\\\]([^\/\\\\]+)$/','$1',$tmpname);
542+
543+ // Read the option from NP_SQLite
544+ if (!class_exists('NucleusPlugin')) { include($DIR_LIBS.'PLUGIN.php');}
545+ if (!class_exists('NP_SQLite')) { include($DIR_PLUGINS.'NP_SQLite.php'); }
546+ $p=new NP_SQLite();
547+ if (!($numatonce=@$p->getOption('numatonce'))) $numatonce=20;
548+ if (!($refreshwait=@$p->getOption('refreshwait'))) $refreshwait=1;
549+
550+ // Start process.
551+ $url="plugins/sqlite/restore.php?dbfile=$tmpname&numatonce=$numatonce&refreshwait=$refreshwait";
552+ header('HTTP/1.0 301 Moved Permanently');
553+ header('Location: '.$url);
554+ exit('<html><body>Moved Permanently</body></html>');
555+}
556+
557+?>
\ No newline at end of file
--- /dev/null
+++ b/tags/sqlite0903/sqlite/nucleus/sqlite/sqlitealtertable.php
@@ -0,0 +1,391 @@
1+<?php
2+ /****************************************
3+ * SQLite-MySQL wrapper for Nucleus *
4+ * ver 0.9.0.2 *
5+ * Written by Katsumi License: GPL *
6+ ****************************************/
7+
8+function sqlite_createtable_query($commands,$tablename,$temptable,&$morequeries){
9+ if ($temptable) $query="CREATE TEMPORARY TABLE $tablename (";
10+ else $query="CREATE TABLE $tablename (";
11+ $auto_increment=$first=true;
12+ foreach($commands as $key => $value) {
13+ if (strpos(strtolower($value),'auto_increment')==strlen($value)-14) $auto_increment=true;
14+ $isint=preg_match('/int\(([0-9]*?)\)/i',$value);
15+ $isint=$isint | preg_match('/tinyint\(([0-9]*?)\)/i',$value);
16+ $value=preg_replace('/int\(([0-9]*?)\)[\s]+unsigned/i','int($1)',$value);
17+ $value=preg_replace('/int\([0-9]*?\)[\s]+NOT NULL[\s]+auto_increment$/i',' INTEGER NOT NULL PRIMARY KEY',$value);
18+ $value=preg_replace('/int\([0-9]*?\)[\s]+auto_increment$/i',' INTEGER PRIMARY KEY',$value);
19+ if ($auto_increment) $value=preg_replace('/^PRIMARY KEY(.*?)$/i','',$value);
20+ while (preg_match('/PRIMARY KEY[\s]*\((.*)\([0-9]+\)(.*)\)/i',$value)) // Remove '(100)' from 'PRIMARY KEY (`xxx` (100))'
21+ $value=preg_replace('/PRIMARY KEY[\s]*\((.*)\([0-9]+\)(.*)\)/i','PRIMARY KEY ($1 $2)',$value);
22+
23+ // CREATE KEY queries for SQLite (corresponds to KEY 'xxxx'('xxxx', ...) of MySQL
24+ if (preg_match('/^FULLTEXT KEY(.*?)$/i',$value,$matches)) {
25+ array_push($morequeries,'CREATE INDEX '.str_replace('('," ON $tablename (",$matches[1]));
26+ $value='';
27+ } else if (preg_match('/^UNIQUE KEY(.*?)$/i',$value,$matches)) {
28+ array_push($morequeries,'CREATE UNIQUE INDEX '.str_replace('('," ON $tablename (",$matches[1]));
29+ $value='';
30+ } else if (preg_match('/^KEY(.*?)$/i',$value,$matches)) {
31+ array_push($morequeries,'CREATE INDEX '.str_replace('('," ON $tablename (",$matches[1]));
32+ $value='';
33+ }
34+
35+ // Check if 'DEFAULT' is set when 'NOT NULL'
36+ $uvalue=strtoupper($value);
37+ if (strpos($uvalue,'NOT NULL')!==false &&
38+ strpos($uvalue,'DEFAULT')===false &&
39+ strpos($uvalue,'INTEGER NOT NULL PRIMARY KEY')===false) {
40+ if ($isint) $value.=" DEFAULT 0";
41+ else $value.=" DEFAULT ''";
42+ }
43+
44+ if ($value) {
45+ if ($first) $first=false;
46+ else $query.=',';
47+ $query.=' '.$value;
48+ }
49+ }
50+ $query.=' )';
51+ return $query;
52+}
53+
54+function sqlite_renametable($commands,$dbhandle){
55+ $carray=array();
56+ foreach($commands as $command){
57+ $command=_sqlite_divideByChar(array(' ',"\t","\r","\n"),$command);
58+ if (count($command)!=3) return sqlite_ReturnWithError(htmlspecialchars("near '$command[0]': syntax error"));
59+ if (strtoupper($command[1])!='TO') return sqlite_ReturnWithError(htmlspecialchars("near '$command[1]': syntax error"));
60+ $carray[str_replace("'",'',$command[0])]=str_replace("'",'',$command[2]);
61+ }
62+ foreach($carray as $old=>$new){
63+ if (!sqlite_copytable($old,$new,$dbhandle)) return false;
64+ if (!sqlite_query($dbhandle,"DROP TABLE $old")) return sqlite_ReturnWithError(htmlspecialchars("fail to remove table, '$old'"));
65+ }
66+ sqlite_query($dbhandle,'VACUUM');
67+ return true;
68+}
69+
70+function sqlite_copytable($table,$newname,$dbhandle,$newtablearray=array()){
71+ // Getting information from original table and create new table
72+ $res = sqlite_query($dbhandle,"SELECT sql,name,type FROM sqlite_master WHERE tbl_name = '".$table."' ORDER BY type DESC");
73+ if(!sqlite_num_rows($res)) return sqlite_ReturnWithError('no such table: '.$table);
74+ if (count($newtablearray)) {
75+ $query="CREATE TABLE $newname (".implode(',',$newtablearray).')';
76+ if (!sqlite_query($dbhandle,$query)) return sqlite_ReturnWithError('Table could not be created.');
77+ } else {
78+ while($row=sqlite_fetch_array($res,SQLITE_ASSOC)){
79+ if (!preg_match('/^([^\(]*)[\s]([^\(\']+)[\s]*\(([\s\S]*)$/',$row['sql'],$m) &&
80+ !preg_match('/^([^\(]*)[\s]\'([^\(]+)\'[\s]*\(([\s\S]*)$/',$row['sql'],$m)) return sqlite_ReturnWithError('unknown error');
81+ if (!sqlite_query($dbhandle,$m[1]." '$newname' (".$m[3])) return sqlite_ReturnWithError('Table could not be created.');
82+ }
83+ }
84+ // Copy the items
85+ sqlite_query($dbhandle,'BEGIN');
86+ $res=sqlite_unbuffered_query($dbhandle,"SELECT * FROM $table");
87+ while($row=sqlite_fetch_array($res,SQLITE_ASSOC)){
88+ $keys=$values=array();
89+ foreach($row as $key=>$value) {
90+ if (count($newtablearray) && !isset($newtablearray[strtolower($key)])) continue;
91+ $keys[]="'$key'";
92+ $values[]="'".sqlite_escape_string($value)."'";
93+ }
94+ if (!sqlite_query($dbhandle,"INSERT INTO '$newname'(".implode(', ',$keys).') VALUES ('.implode(', ',$values).')')) {
95+ sqlite_query($dbhandle,'COMMIT');
96+ return false;
97+ }
98+ }
99+ sqlite_query($dbhandle,'COMMIT');
100+ $orgnum=sqlite_array_query($dbhandle,"SELECT COUNT(*) FROM $table");
101+ $newnum=sqlite_array_query($dbhandle,"SELECT COUNT(*) FROM $newname");
102+ if ($orgnum[0][0]!=$newnum[0][0]) return sqlite_ReturnWithError('Data transfer failed.');
103+ return true;
104+}
105+function sqlite_altertable($table,$alterdefs,$dbhandle){
106+ // Almost completely re-written in February 2008.
107+ $table=str_replace("'",'',$table);
108+
109+ // Getting information from original table
110+ $res = sqlite_query($dbhandle,"SELECT sql,name,type FROM sqlite_master WHERE tbl_name = '".$table."' ORDER BY type DESC");
111+ if(!sqlite_num_rows($res)) return sqlite_ReturnWithError('no such table: '.$table);
112+ $orgindex=array();
113+ $row=sqlite_fetch_array($res,SQLITE_ASSOC); //table sql
114+ $orgsql=$row['sql'];
115+ while($row=sqlite_fetch_array($res,SQLITE_ASSOC)) $orgindex[strtolower($row['name'])]=$row['sql'];
116+ if (!preg_match('/^[^\(]+\((.*)\);*$/',$orgsql,$m)) return sqlite_ReturnWithError('unknown error');
117+ $orgtablearray=array();
118+ foreach(_sqlite_divideByChar(',',$orgtable=$m[1]) as $value){
119+ if (!preg_match('/^([^\s\']+)[\s]+([\s\S]*)$/',$value,$m) &&
120+ !preg_match('/^\'([^\']+)\'[\s]+([\s\S]*)$/',$value,$m)) return sqlite_ReturnWithError('unknown error');
121+ $orgtablearray[strtolower($m[1])]="'$m[1]' $m[2]";
122+ }
123+ $desttablearray=$orgtablearray;
124+ $destindex=$orgindex;
125+
126+ // Convert table
127+ foreach(_sqlite_divideByChar(',',$alterdefs) as $def){
128+ $def=_sqlite_divideByChar(array(' ',"\t","\r","\n"),trim($def));
129+ if (($c=count($def))<2) return sqlite_ReturnWithError('near "'.htmlspecialchars($def[0]).'": syntax error');
130+ // Check if FIRST/AFTER is used.
131+ $first=$after=false;
132+ if (strtoupper($def[$c-1])=='FIRST') {
133+ $first=true;
134+ array_pop($def);
135+ } elseif (strtoupper($def[$c-2])=='AFTER') {
136+ $after=strtolower(str_replace("'",'',array_pop($def)));
137+ array_pop($def);
138+ }
139+ // Ignore CONSTRAINT and COLUMN
140+ $method=strtoupper(array_shift($def));
141+ switch(strtoupper($def[0])){
142+ case 'CONSTRAINT': // delete two
143+ array_shift($def);
144+ case 'COLUMN': // delete one
145+ array_shift($def);
146+ default:
147+ break;
148+ }
149+ // The main routine of this function follow.
150+ switch($method){
151+ case 'MODIFY':
152+ case 'ALTER':
153+ if (error_reporting() & E_NOTICE) sqlite_ReturnWithError('ALTER/MODIFY is not supported');
154+ break;
155+ case 'DROP':
156+ case 'CHANGE':
157+ if (strtoupper($def[0])=='INDEX') {
158+ // delete index
159+ unset($destindex[strtolower($def[1])]);
160+ } else {
161+ // delete field
162+ unset($desttablearray[strtolower(str_replace("'",'',$def[0]))]);
163+ }
164+ if ($method!='CHANGE') break;
165+ case 'ADD':
166+ $field=array_shift($def);
167+ switch($submedthod=strtoupper($field)){
168+ case 'UNIQUE':
169+ case 'PRIMARY':
170+ case 'FOREIGN':
171+ case 'INDEX':
172+ case 'FULLTEXT':
173+ // add index
174+ if (strtoupper($index=array_shift($def))=='KEY') $index=array_shift($def);
175+ $def=implode(' ',$def);
176+ $destindex[strtolower(str_replace("'",'',$index))]=
177+ ($submedthod=='UNIQUE'?'CREATE UNIQUE INDEX ':'CREATE INDEX ').
178+ "$index ON '$table' $def";
179+ break;
180+ default:
181+ // add field
182+ $field=str_replace("'",'',$field);
183+ if ($first) {
184+ $desttablearray=array_merge(
185+ array(strtolower($field)=>"'$field' ".implode(' ',$def)),
186+ $desttablearray);
187+ } elseif($after) {
188+ $temp=$desttablearray;
189+ $desttablearray=array();
190+ $ok=false;
191+ foreach($temp as $key=>$value) {
192+ $desttablearray[$key]=$value;
193+ if ($ok || $key!=$after) continue;
194+ $ok=true;
195+ $desttablearray[strtolower($field)]="'$field' ".implode(' ',$def);
196+ }
197+ if (!$ok) {
198+ $desttablearray[strtolower($field)]="'$field' ".implode(' ',$def);
199+ if (error_reporting() & E_NOTICE) sqlite_ReturnWithError(htmlspecialchars("Field '$after' not found."));
200+ }
201+ } else {
202+ $desttablearray[strtolower($field)]="'$field' ".implode(' ',$def);
203+ }
204+ }
205+ break;
206+ default:
207+ return sqlite_ReturnWithError('near "'.htmlspecialchars($method).'": syntax error');
208+ }
209+ }
210+
211+ // Create temporary table that has the modified field and copy the items into it.
212+ if (function_exists('microtime')) $tmptable='t'.str_replace(array(' ','.'),'',microtime());
213+ else $tmptable = 't'.rand(0,999999).time();
214+ if (!sqlite_copytable($table,$tmptable,$dbhandle,$desttablearray)) return false;
215+
216+ // New temporary table sccusfully made.
217+ // So, delete the original table and copy back the temporary table to one with original name.
218+ sqlite_query("DROP TABLE $table",$dbhandle);
219+ if (sqlite_copytable($tmptable,$table,$dbhandle)) sqlite_query("DROP TABLE $tmptable",$dbhandle);
220+
221+ // Add the indexes, finally.
222+ foreach($destindex as $index) sqlite_query($index,$dbhandle);
223+ sqlite_query($dbhandle,'VACUUM');
224+ return true;
225+}
226+function sqlite_showKeysFrom($tname,$dbhandle) {
227+ // This function is for supporing 'SHOW KEYS FROM' and 'SHOW INDEX FROM'.
228+ // For making the same result as obtained by MySQL, temporary table is made.
229+ if (preg_match('/^([^\s]+)\s+LIKE\s+\'([^\']+)\'$/i',$tname,$m)) list($m,$tname,$like)=$m;
230+ $tname=str_replace("'",'',$tname);
231+
232+ // Create a temporary table for making result
233+ if (function_exists('microtime')) $tmpname='t'.str_replace('.','',str_replace(' ','',microtime()));
234+ else $tmpname = 't'.rand(0,999999).time();
235+ sqlite_query($dbhandle,"CREATE TEMPORARY TABLE $tmpname ('Table', 'Non_unique', 'Key_name', 'Seq_in_index',".
236+ " 'Column_name', 'Collation', 'Cardinality', 'Sub_part', 'Packed', 'Null', 'Index_type', 'Comment')");
237+
238+ // First, get the sql query when the table created
239+ $res=sqlite_query($dbhandle,"SELECT sql FROM sqlite_master WHERE tbl_name = '$tname' ORDER BY type DESC");
240+ $a=nucleus_mysql_fetch_assoc($res);
241+ $tablesql=$a['sql'];
242+
243+ // Check if each columns are unique
244+ $notnull=array();
245+ foreach(_sqlite_divideByChar(',',substr($tablesql,strpos($tablesql,'(')+1)) as $value) {
246+ $name=str_replace("'",'',substr($value,0,strpos($value,' ')));
247+ if (strpos(strtoupper($value),'NOT NULL')!==false) $notnull[$name]='';
248+ else $notnull[$name]='YES';
249+ }
250+
251+ // Get the primary key (and check if it is unique???).
252+ if (preg_match('/[^a-zA-Z_\']([\S]+)[^a-zA-Z_\']+INTEGER NOT NULL PRIMARY KEY/i',$tablesql,$matches)) {
253+ $pkey=str_replace("'",'',$matches[1]);
254+ $pkeynull='';
255+ } else if (preg_match('/[^a-zA-Z_\']([\S]+)[^a-zA-Z_\']+INTEGER PRIMARY KEY/i',$tablesql,$matches)) {
256+ $pkey=str_replace("'",'',$matches[1]);
257+ $pkeynull='YES';
258+ } else if (preg_match('/PRIMARY KEY[\s]*?\(([^\)]+)\)/i',$tablesql,$matches)) {
259+ $pkey=null;// PRIMARY KEY ('xxx'[,'xxx'])
260+ foreach(explode(',',$matches[1]) as $key=>$value) {
261+ $value=str_replace("'",'',trim($value));
262+ $key++;
263+ $cardinality=nucleus_mysql_num_rows(sqlite_query($dbhandle,"SELECT '$value' FROM '$tname'"));
264+ sqlite_query($dbhandle,"INSERT INTO $tmpname ('Table', 'Non_unique', 'Key_name', 'Seq_in_index',".
265+ " 'Column_name', 'Collation', 'Cardinality', 'Sub_part', 'Packed', 'Null', 'Index_type', 'Comment')".
266+ " VALUES ('$tname', '0', 'PRIMARY', '$key',".
267+ " '$value', 'A', '$cardinality', null, null, '', 'BTREE', '')");
268+ }
269+ } else $pkey=null;
270+
271+ // Check the index.
272+ $res=sqlite_query($dbhandle,"SELECT sql,name FROM sqlite_master WHERE type = 'index' and tbl_name = '$tname' ORDER BY type DESC");
273+ while ($a=nucleus_mysql_fetch_assoc($res)) {
274+ if (!($sql=$a['sql'])) {// Primary key
275+ if ($pkey && strpos(strtolower($a['name']),'autoindex')) {
276+ $cardinality=nucleus_mysql_num_rows(sqlite_query($dbhandle,"SELECT $pkey FROM '$tname'"));
277+ sqlite_query($dbhandle,"INSERT INTO $tmpname ('Table', 'Non_unique', 'Key_name', 'Seq_in_index',".
278+ " 'Column_name', 'Collation', 'Cardinality', 'Sub_part', 'Packed', 'Null', 'Index_type', 'Comment')".
279+ " VALUES ('$tname', '0', 'PRIMARY', '1',".
280+ " '$pkey', 'A', '$cardinality', null, null, '$pkeynull', 'BTREE', '')");
281+ $pkey=null;
282+ }
283+ } else {// Non-primary key
284+ if (($name=str_replace("'",'',$a['name'])) && preg_match('/\(([\s\S]+)\)/',$sql,$matches)) {
285+ if (isset($like) && $name!=$like) continue;
286+ foreach(explode(',',$matches[1]) as $key=>$value) {
287+ $columnname=str_replace("'",'',$value);
288+ if (strpos(strtoupper($sql),'CREATE UNIQUE ')===0) $nonunique='0';
289+ else $nonunique='1';
290+ $cardinality=nucleus_mysql_num_rows(sqlite_query($dbhandle,"SELECT $columnname FROM '$tname'"));
291+ sqlite_query($dbhandle,"INSERT INTO $tmpname ('Table', 'Non_unique', 'Key_name', 'Seq_in_index',".
292+ " 'Column_name', 'Collation', 'Cardinality', 'Sub_part', 'Packed', 'Null', 'Index_type', 'Comment')".
293+ " VALUES ('$tname', '$nonunique', '$name', '".(string)($key+1)."',".
294+ " '$columnname', 'A', '$cardinality', null, null, '$notnull[$columnname]', 'BTREE', '')");
295+ }
296+ }
297+ }
298+ }
299+ if ($pkey) { // The case that the key (index) is not defined.
300+ $cardinality=nucleus_mysql_num_rows(sqlite_query($dbhandle,"SELECT $pkey FROM '$tname'"));
301+ sqlite_query($dbhandle,"INSERT INTO $tmpname ('Table', 'Non_unique', 'Key_name', 'Seq_in_index',".
302+ " 'Column_name', 'Collation', 'Cardinality', 'Sub_part', 'Packed', 'Null', 'Index_type', 'Comment')".
303+ " VALUES ('$tname', '0', 'PRIMARY', '1',".
304+ " '$pkey', 'A', '$cardinality', null, null, '$pkeynull', 'BTREE', '')");
305+ $pkey=null;
306+ }
307+
308+ // return the final query to show the keys in MySQL style (using temporary table).
309+ return "SELECT * FROM $tmpname";
310+}
311+function sqlite_showFieldsFrom($tname,$dbhandle){
312+ // This function is for supporing 'SHOW FIELDS FROM' and 'SHOW COLUMNS FROM'.
313+ // For making the same result as obtained by MySQL, temporary table is made.
314+ if (preg_match('/^([^\s]+)\s+LIKE\s+\'([^\']+)\'$/i',$tname,$m)) list($m,$tname,$like)=$m;
315+ $tname=str_replace("'",'',$tname);
316+
317+ // First, get the sql query when the table created
318+ $res=sqlite_query($dbhandle,"SELECT sql FROM sqlite_master WHERE tbl_name = '$tname' ORDER BY type DESC");
319+ $a=nucleus_mysql_fetch_assoc($res);
320+ $tablesql=trim($a['sql']);
321+ if (preg_match('/^[^\(]+\(([\s\S]*?)\)$/',$tablesql,$matches)) $tablesql=$matches[1];
322+ $tablearray=array();
323+ foreach(_sqlite_divideByChar(',',$tablesql) as $value) {
324+ $value=trim($value);
325+ if ($i=strpos($value,' ')) {
326+ $name=str_replace("'",'',substr($value,0,$i));
327+ $value=trim(substr($value,$i));
328+ if (substr($value,-1)==',') $value=substr($value,strlen($value)-1);
329+ $tablearray[$name]=$value;
330+ }
331+ }
332+
333+ // Check if INDEX has been made for the parameter 'MUL' in 'KEY' column
334+ $multi=array();
335+ $res=sqlite_query($dbhandle,"SELECT name FROM sqlite_master WHERE type = 'index' and tbl_name = '$tname' ORDER BY type DESC");
336+ while ($a=nucleus_mysql_fetch_assoc($res)) $multi[str_replace("'",'',$a['name'])]='MUL';
337+
338+ // Create a temporary table for making result
339+ if (function_exists('microtime')) $tmpname='t'.str_replace('.','',str_replace(' ','',microtime()));
340+ else $tmpname = 't'.rand(0,999999).time();
341+ sqlite_query($dbhandle,"CREATE TEMPORARY TABLE $tmpname ('Field', 'Type', 'Null', 'Key', 'Default', 'Extra')");
342+
343+ // Check the table
344+ foreach($tablearray as $field=>$value) {
345+ if (strtoupper($field)=='PRIMARY') continue;//PRIMARY KEY('xx'[,'xx'])
346+ if (isset($like) && $field!=$like) continue;
347+ $uvalue=strtoupper($value.' ');
348+ $key=(string)$multi[$field];
349+ if ($uvalue=='INTEGER NOT NULL PRIMARY KEY ' || $uvalue=='INTEGER PRIMARY KEY ') {
350+ $key='PRI';
351+ $extra='auto_increment';
352+ } else $extra='';
353+ if ($i=strpos($uvalue,' ')) {
354+ $type=substr($value,0,$i);
355+ if (strpos($type,'(') && ($i=strpos($value,')')))
356+ $type=substr($value,0,$i+1);
357+ } else $type='';
358+ if (strtoupper($type)=='INTEGER') $type='int(11)';
359+ if (strpos($uvalue,'NOT NULL')===false) $null='YES';
360+ else {
361+ $null='';
362+ $value=preg_replace('/NOT NULL/i','',$value);
363+ $uvalue=strtoupper($value);
364+ }
365+ if ($i=strpos($uvalue,'DEFAULT')) {
366+ $default=trim(substr($value,$i+7));
367+ if (strtoupper($default)=='NULL') {
368+ $default="";
369+ $setdefault="";
370+ } else {
371+ if (substr($default,0,1)=="'") $default=substr($default,1,strlen($default)-2);
372+ $default="'".$default."',";
373+ $setdefault="'Default',";
374+ }
375+ } else if ($null!='YES' && $extra!='auto_increment') {
376+ if (strpos(strtolower($type),'int')===false) $default="'',";
377+ else $default="'0',";
378+ $setdefault="'Default',";
379+ } else {
380+ $default="";
381+ $setdefault="";
382+ }
383+ sqlite_query($dbhandle,"INSERT INTO '$tmpname' ('Field', 'Type', 'Null', 'Key', $setdefault 'Extra')".
384+ " VALUES ('$field', '$type', '$null', '$key', $default '$extra')");
385+ }
386+
387+ // return the final query to show the keys in MySQL style (using temporary table).
388+ return "SELECT * FROM $tmpname";
389+}
390+
391+?>
\ No newline at end of file
--- /dev/null
+++ b/tags/sqlite0903/sqlite/nucleus/sqlite/sqliteconfig.php
@@ -0,0 +1,14 @@
1+<?php
2+$SQLITECONF=array();
3+
4+// Detabase definition.
5+// Modify here if you use another file for database.
6+$SQLITECONF['DBFILENAME']=dirname(__FILE__).'/.dbsqlite';
7+
8+// Options
9+$SQLITECONF['DEBUGMODE']=false;
10+$SQLITECONF['DEBUGREPORT']=false;
11+$SQLITECONF['MEASURESPEED']=false;
12+$SQLITECONF['INITIALIZE']=array('PRAGMA short_column_names=1;');
13+
14+?>
\ No newline at end of file
--- /dev/null
+++ b/tags/sqlite0903/sqlite/nucleus/sqlite/sqlitequeryfunctions.php
@@ -0,0 +1,890 @@
1+<?php
2+ /****************************************
3+ * SQLite-MySQL wrapper for Nucleus *
4+ * ver 0.9.0.1 *
5+ * Written by Katsumi License: GPL *
6+ ****************************************/
7+
8+// Register user-defined functions used in SQL query.
9+// The SQLite_QueryFunctions object is created to register SQLite queries.
10+$SQLITECONF['object']=new SQLite_Functions;
11+// After the registration, the object is not required any more.
12+unset($SQLITECONF['object']);
13+
14+
15+// The class for SQLite user functions
16+class SQLite_Functions {
17+
18+// Constructor is used for the registration of user-defined functions of SQLite
19+function SQLite_Functions(){
20+ global $SQLITE_DBHANDLE;
21+ foreach($this as $key=>$value){
22+ $key=strtoupper($key);
23+ if (substr($key,0,7)!='DEFINE_') continue;
24+ $key=substr($key,7);
25+ if (substr($value,0,7)=='sqlite_') $value=array('SQLite_Functions',$value);
26+ @sqlite_create_function($SQLITE_DBHANDLE,$key,$value);
27+ }
28+}
29+
30+var $define_ASCII='ord';
31+
32+var $define_BIN='decbin';
33+
34+var $define_BIT_LENGTH='sqlite_userfunc_BIT_LENGTH';
35+function sqlite_userfunc_BIT_LENGTH($p1){
36+ return strlen($p1)*8;
37+}
38+
39+var $define_CHAR='sqlite_userfunc_CHAR';
40+function sqlite_userfunc_CHAR(){
41+ if (!($lastnum=func_num_args())) return null;
42+ $args=&func_get_args();
43+ $ret='';
44+ for ($i=0;$i<$lastnum;$i++) {
45+ if ($args[$i]!==null) $ret.=chr($args[$i]);
46+ }
47+ return $ret;
48+}
49+
50+var $define_CHAR_LENGTH='sqlite_userfunc_CHAR_LENGTH';
51+function sqlite_userfunc_CHAR_LENGTH($str){
52+ if (function_exists('mb_strlen')) return mb_strlen($str);
53+ return strlen($str);
54+}
55+
56+var $define_CONCAT_WS='sqlite_userfunc_CONCAT_WS';
57+function sqlite_userfunc_CONCAT_WS(){
58+ if (($lastnum=func_num_args())<2) return null;
59+ $args=&func_get_args();
60+ if ($args[0]===null) return null;
61+ $ret='';
62+ for ($i=1;$i<$lastnum;$i++) {
63+ if ($args[$i]===null) continue;
64+ if ($ret) $ret.=$args[0];
65+ $ret.=(string)($args[$i]);
66+ }
67+ return $ret;
68+}
69+
70+var $define_CONV='sqlite_userfunc_CONV';
71+function sqlite_userfunc_CONV($p1,$p2,$p3){
72+ $t36='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
73+ $p1=strtoupper(trim((string)$p1));
74+ if ($p3<0 && substr($p1,0,1)=='-') {
75+ $sign='-';
76+ $p1=substr($p1,1);
77+ } else $sign='';
78+ $p3=abs($p3);
79+ $v=0;
80+ for ($i=0;$i<strlen($p1);$i++) $v=$v*$p2+strpos($t36,$p1[$i]);
81+ if (!$v) return '0';
82+ $ret='';
83+ while ($v) {
84+ $i=$v % $p3;
85+ $ret=$t36[$i].$ret;
86+ $v=($v-$i)/$p3;
87+ }
88+ return $sign.$ret;
89+}
90+
91+var $define_ELT='sqlite_userfunc_ELT';
92+function sqlite_userfunc_ELT(){
93+ if (($lastnum=func_num_args())<2) return null;
94+ $args=&func_get_args();
95+ if ($args[0]<1 || $lastnum<$args[0]) return null;
96+ return $args[$args[0]];
97+}
98+
99+var $define_EXPORT_SET='sqlite_userfunc_EXPORT_SET';
100+function sqlite_userfunc_EXPORT_SET($p1,$p2,$p3,$p4=',',$p5=64){
101+ if ($p1<2147483648) $p1=decbin($p1);
102+ else $p1=decbin($p1/2147483648).decbin($p1 % 2147483648);
103+ $p1=substr(decbin($p1).str_repeat('0',$p5),0,$p5);
104+ $p1=str_replace(array('1','0'),array($p2.$p4,$p3.$p4),$p1);
105+ return substr($p1,0,strlen($p1)-strlen($p4));
106+}
107+
108+var $define_FIELD='sqlite_userfunc_FIELD';
109+function sqlite_userfunc_FIELD(){
110+ if (($lastnum=func_num_args())<2) return null;
111+ $args=&func_get_args();
112+ for ($i=1;$i<$lastnum;$i++) if ($args[0]==$args[$i]) return $i;
113+ return 0;
114+}
115+
116+var $define_HEX='sqlite_userfunc_HEX';
117+function sqlite_userfunc_HEX($p1){
118+ if (is_numeric($p1)) return dechex ($p1);
119+ $p1=(string)$p1;
120+ $ret='';
121+ for($i=0;$i<strlen($p1);$i++) $ret.=substr('0'.dechex($p1[$i]),-2);
122+ return $ret;
123+}
124+
125+var $define_INSERT='sqlite_userfunc_INSERT';
126+function sqlite_userfunc_INSERT($p1,$p2,$p3,$p4){
127+ if (function_exists('mb_substr')) return mb_substr($p1,0,$p2-1).$p4.mb_substr($p1,$p2+$p3-1);
128+ return substr($p1,0,$p2-1).$p4.substr($p1,$p2+$p3-1);
129+}
130+
131+var $define_LOCATE='sqlite_userfunc_LOCATE';
132+function sqlite_userfunc_LOCATE($p1,$p2,$p3=1){
133+ if (substr($p1,1)=='_') $p2='-'.$p2;
134+ else $p2='_'.$p2;
135+ if (function_exists('mb_strpos')) return (int)mb_strpos($p2,$p1,$p3);
136+ if (($p=strpos(substr($p2,$p3),$p1))===false) return 0;
137+ return $p+$p3;
138+}
139+
140+var $define_INSTR='sqlite_userfunc_INSTR';
141+function sqlite_userfunc_INSTR($p1,$p2){
142+ return SQLite_Functions::sqlite_userfunc_LOCATE($p2,$p1);
143+}
144+
145+var $define_LCASE='sqlite_userfunc_LOWER';
146+var $define_LOWER='sqlite_userfunc_LOWER';
147+function sqlite_userfunc_LOWER($p1){
148+ if (function_exists('mb_strtolower')) return mb_strtolower($p1);
149+ return strtolower($p1);
150+}
151+
152+var $define_LEFT='sqlite_userfunc_LEFT';
153+function sqlite_userfunc_LEFT($p1,$p2){
154+ if (function_exists('mb_substr')) return mb_substr($p1,0,$p2);
155+ return substr($p1,0,$p2);
156+}
157+
158+var $define_LENGTH='strlen';
159+var $define_OCTET_LENGTH='strlen';
160+
161+var $define_LOAD_FILE='sqlite_userfunc_LOAD_FILE';
162+function sqlite_userfunc_LOAD_FILE($p1){
163+ if (!file_exists($p1)) return null;
164+ if (!is_array($a=@file($p1))) return null;
165+ $ret='';
166+ foreach($a as $value) $ret.=$value;
167+ return $ret;
168+}
169+
170+var $define_LPAD='sqlite_userfunc_LPAD';
171+function sqlite_userfunc_LPAD($p1,$p2,$p3){
172+ return substr(str_repeat($p3,$p2/strlen($p3)).$p1,0-$p2);
173+}
174+
175+var $define_LTRIM='ltrim';
176+
177+var $define_MAKE_SET='sqlite_userfunc_MAKE_SET';
178+function sqlite_userfunc_MAKE_SET($p1,$p2,$p3){
179+ if (($lastnum=func_num_args())<2) return null;
180+ $args=&func_get_args();
181+ $ret='';
182+ if ($args[0]<2147483648) $bits=decbin($args[0]);
183+ else $bits=decbin($args[0]/2147483648).decbin($args[0] % 2147483648);
184+ for ($i=1;$i<$lastnum;$i++) {
185+ if ($bits[strlen($bits)-$i]=='1' && $args[$i]) {
186+ if ($ret) $ret.=',';
187+ $ret.=$args[$i];
188+ }
189+ }
190+ return 0;
191+}
192+
193+var $define_MID='sqlite_userfunc_SUBSTRING';
194+var $define_SUBSTRING='sqlite_userfunc_SUBSTRING';
195+function sqlite_userfunc_SUBSTRING($p1,$p2,$p3=null){
196+ $p2--;
197+ if (function_exists('mb_substr')) {
198+ if ($p3) return mb_substr($p1,$p2,$p3);
199+ return mb_substr($p1,$p2);
200+ }
201+ if ($p3) return substr($p1,$p2,$p3);
202+ return substr($p1,$p2);
203+}
204+
205+var $define_OCT='sqlite_userfunc_OCT';
206+function sqlite_userfunc_OCT($p1){
207+ if ($p1===null) return null;
208+ return SQLite_Functions::sqlite_userfunc_CONV($p1,10,8);
209+}
210+
211+var $define_ORD='sqlite_userfunc_ORD';
212+function sqlite_userfunc_ORD($p1){
213+ if (function_exists('mb_substr')) $p1=mb_substr($p1,0,1);
214+ else $p1=substr($p1,0,1);
215+ $ret=0;
216+ for ($i=0;$i<strlen($p1);$i++) $ret=$ret*256+ord($p1[$i]);
217+ return $ret;
218+}
219+
220+var $define_QUOTE='sqlite_userfunc_QUOTE';
221+function sqlite_userfunc_QUOTE($p1){
222+ if ($p1===null) return 'NULL';
223+ return str_replace(array("'","\\","\x1A"),array("\\'","\\\\","\\z"),$p1);
224+}
225+
226+var $define_REPEAT='str_repeat';
227+
228+var $define_REVERSE='sqlite_userfunc_REVERSE';
229+function sqlite_userfunc_REVERSE($p1){
230+ if (function_exists('mb_strlen')) {
231+ $ret='';
232+ for ($i=mb_strlen($p1)-1;0<=$i;$i++) $ret.=mb_substr($p1,$i,1);
233+ return $ret;
234+ }
235+ return strrev($p1);
236+}
237+
238+var $define_RIGHT='sqlite_userfunc_RIGHT';
239+function sqlite_userfunc_RIGHT($p1){
240+ if (function_exists('mb_substr')) return mb_substr($p1,0-$p2);
241+ return substr($p1,0-$p2);
242+}
243+
244+var $define_RPAD='sqlite_userfunc_RPAD';
245+function sqlite_userfunc_RPAD($p1,$p2,$p3){
246+ return substr($p1.str_repeat($p3,$p2/strlen($p3)),0,$p2);
247+}
248+
249+var $define_RTRIM='rtrim';
250+var $define_SOUNDEX='soundex';
251+
252+var $define_SPACE='sqlite_userfunc_SPACE';
253+function sqlite_userfunc_SPACE($p1){
254+ return str_repeat(' ',$p1);
255+}
256+
257+var $define_SUBSTRING_INDEX='sqlite_userfunc_SUBSTRING_INDEX';
258+function sqlite_userfunc_SUBSTRING_INDEX($p1,$p2,$p3){
259+ if (!is_array($a=explode($p2,$p1))) return null;
260+ $ret='';
261+ if (0<$p3) {
262+ for ($i=0;$i<$p3;$i++) {
263+ if ($ret) $ret.=$p2;
264+ $ret.=$a[$i];
265+ }
266+ } else {
267+ for ($i=0;$i<0-$p3;$i++) {
268+ if ($ret) $ret.=$p2;
269+ $ret.=$a[count($a)-1-$i];
270+ }
271+ }
272+ return $ret;
273+}
274+
275+var $define_TRIM='sqlite_userfunc_TRIM';
276+function sqlite_userfunc_TRIM($p1,$p2=null,$p3=null){
277+ if (!$p2 && !$p3) return trim($p1);
278+ if (!$p2) $p2=' ';
279+ switch(strtoupper($p1)){
280+ case 'BOTH':
281+ while (strpos($p3,$p2)===0) $p3=substr($p3,strlen($p2));
282+ case 'TRAILING':
283+ while (strrpos($p3,$p2)===strlen($p3)-strlen($p2)-1) $p3=substr($p3,0,strlen($p3)-strlen($p2));
284+ break;
285+ case 'LEADING':
286+ while (strpos($p3,$p2)===0) $p3=substr($p3,strlen($p2));
287+ break;
288+ }
289+ return $p2;
290+}
291+
292+var $define_UCASE='sqlite_userfunc_UPPER';
293+var $define_UPPER='sqlite_userfunc_UPPER';
294+function sqlite_userfunc_UPPER($p1){
295+ if (function_exists('mb_strtoupper')) return mb_strtoupper($p1);
296+ return strtoupper($p1);
297+}
298+
299+var $define_ACOS='acos';
300+var $define_ASIN='asin';
301+
302+var $define_ATAN='sqlite_userfunc_ATAN';
303+function sqlite_userfunc_ATAN($p1,$p2=null){
304+ if (!$p2) return atan($p1);
305+ if ($p1>0 && $p2>0) return atan($p1/$p2);
306+ else if ($p1>0 && $p2<0) return pi-atan(-$p1/$p2);
307+ else if ($p1<0 && $p2<0) return pi+atan($p1/$p2);
308+ else if ($p1<0 && $p2>0) return 2*pi-atan(-$p1/$p2);
309+ else return 0;
310+}
311+
312+var $define_CEIL='ceil';
313+var $define_CEILING='ceil';
314+var $define_COS='cos';
315+
316+var $define_COT='sqlite_userfunc_COT';
317+function sqlite_userfunc_COT($p1){
318+ return 1/tan($p1);
319+}
320+
321+var $define_CRC32='crc32';
322+
323+var $define_DEGREES='sqlite_userfunc_DEGREES';
324+function sqlite_userfunc_DEGREES($p1){
325+ return ($p1/pi)*180;
326+}
327+
328+var $define_EXP='exp';
329+var $define_FLOOR='floor';
330+var $define_GREATEST='max';
331+var $define_MAX='max';
332+var $define_LEAST='min';
333+var $define_MIN='min';
334+var $define_ln='log';
335+
336+var $define_log='sqlite_userfunc_LOG';
337+function sqlite_userfunc_LOG($p1,$p2=null){
338+ if ($p2) return log($p1)/log($p2);
339+ return log($p1);
340+}
341+
342+var $define_log2='sqlite_userfunc_LOG2';
343+function sqlite_userfunc_LOG2($p1){
344+ return log($p1)/log(2);
345+}
346+
347+var $define_log10='log10';
348+
349+var $define_MOD='sqlite_userfunc_MOD';
350+function sqlite_userfunc_MOD($p1,$p2){
351+ return $p1 % $p2;
352+}
353+
354+var $define_PI='sqlite_userfunc_PI';
355+function sqlite_userfunc_PI(){
356+ return pi;
357+}
358+
359+var $define_POW='sqlite_userfunc_POW';
360+var $define_POWER='sqlite_userfunc_POW';
361+function sqlite_userfunc_POW($p1,$p2){
362+ return pow($p1,$p2);
363+}
364+
365+var $define_RADIANS='sqlite_userfunc_RADIANS';
366+function sqlite_userfunc_RADIANS($p1){
367+ return ($p1/180)*pi;
368+}
369+
370+var $define_RAND='sqlite_userfunc_RAND';
371+function sqlite_userfunc_RAND($p1=null){
372+ if ($p1) srand($p1);
373+ return rand(0,1073741823)/1073741824;
374+}
375+
376+var $define_SIGN='sqlite_userfunc_SIGN';
377+function sqlite_userfunc_SIGN($p1){
378+ if ($p1>0) return 1;
379+ else if ($p1<0) return -1;
380+ return 0;
381+}
382+
383+var $define_SIN='sin';
384+var $define_SQRT='sqrt';
385+var $define_TAN='tan';
386+
387+var $define_TRUNCATE='sqlite_userfunc_TRUNCATE';
388+function sqlite_userfunc_TRUNCATE($p1,$p2){
389+ $p2=pow(10,$p2);
390+ return ((int)($p1*$p2))/$p2;
391+}
392+
393+var $define_FORMAT='sqlite_userfunc_FORMAT';
394+function sqlite_userfunc_FORMAT($p1,$p2){
395+ return number_format($p1, $p2, '.', ',');
396+}
397+
398+var $define_INET_ATON='sqlite_userfunc_INET_ATON';
399+function sqlite_userfunc_INET_ATON($p1){
400+ $a=explode('.',$p1);
401+ return (($a[0]*256+$a[1])*256+$a[2])*256+$a[3];
402+}
403+
404+var $define_INET_NTOA='sqlite_userfunc_INET_NTOA';
405+function sqlite_userfunc_INET_NTOA($p1){
406+ $a=array();
407+ for ($i=0;$i<4;$i++){
408+ $a[$i]=(string)($p1 % 256);
409+ $p1=(int)($p1/256);
410+ }
411+ return $a[3].'.'.$a[2].'.'.$a[1].'.'.$a[0];
412+}
413+
414+var $define_MD5='md5';
415+
416+
417+var $define_CURDATE='sqlite_userfunc_CURDATE';
418+var $define_CURRENT_DATE='sqlite_userfunc_CURDATE';
419+function sqlite_userfunc_CURDATE(){
420+ return date('Y-m-d');
421+}
422+
423+var $define_CURTIME='sqlite_userfunc_CURTIME';
424+var $define_CURRENT_TIME='sqlite_userfunc_CURTIME';
425+function sqlite_userfunc_CURTIME(){
426+ return date('H:i:s');
427+}
428+
429+var $define_CURRENT_TIMESTAMP='sqlite_userfunc_NOW';
430+var $define_LOCALTIME='sqlite_userfunc_NOW';
431+var $define_LOCALTIMESTAMP='sqlite_userfunc_NOW';
432+var $define_SYSDATE='sqlite_userfunc_NOW';
433+function sqlite_userfunc_NOW(){
434+ return date('Y-m-d H:i:s');
435+}
436+
437+var $define_DATE_FORMAT='sqlite_userfunc_DATE_FORMAT';
438+var $define_TIME_FORMAT='sqlite_userfunc_DATE_FORMAT';
439+function sqlite_userfunc_DATE_FORMAT($p1,$p2){
440+ $t=SQLite_Functions::sqlite_resolvedatetime($p1,$yr,$mt,$dy,$hr,$mn,$sc);
441+ $func='if ($matches=="%") return "%";';
442+ $func='return date($matches,'.$t.');';
443+ return preg_replace_callback ('/%([%a-zA-Z])/',create_function('$matches',$func), $p2);
444+}
445+
446+var $define_DAYNAME='sqlite_userfunc_DAYNAME';
447+function sqlite_userfunc_DAYNAME($p1){
448+ $t=SQLite_Functions::sqlite_resolvedatetime($p1,$yr,$mt,$dy,$hr,$mn,$sc);
449+ return date('l',$t);
450+}
451+
452+var $define_DAYOFWEEK='sqlite_userfunc_DAYOFWEEK';
453+function sqlite_userfunc_DAYOFWEEK($p1){
454+ $t=SQLite_Functions::sqlite_resolvedatetime($p1,$yr,$mt,$dy,$hr,$mn,$sc);
455+ return date('w',$t)+1;
456+}
457+
458+var $define_DAYOFYEAR='sqlite_userfunc_DAYOFYEAR';
459+function sqlite_userfunc_DAYOFYEAR($p1){
460+ $t=SQLite_Functions::sqlite_resolvedatetime($p1,$yr,$mt,$dy,$hr,$mn,$sc);
461+ return date('z',$t);
462+}
463+
464+var $define_EXTRACT='sqlite_userfunc_EXTRACT';
465+function sqlite_userfunc_EXTRACT($p1,$p2){
466+ $t=SQLite_Functions::sqlite_resolvedatetime($p2,$yr,$mt,$dy,$hr,$mn,$sc);
467+ switch(strtoupper($p1)) {
468+ case'SECOND': // SECONDS
469+ return $sc;
470+ case'MINUTE': // MINUTES
471+ return $m;
472+ case'HOUR': // HOURS
473+ return $hr;
474+ case'MONTH': // MONTHS
475+ return $mt;
476+ case'YEAR': // YEARS
477+ return $y;
478+ case'MINUTE_SECOND': // 'MINUTES:SECONDS'
479+ return date('is',$t);
480+ case'HOUR_MINUTE': // 'HOURS:MINUTES'
481+ return date('Hi',$t);
482+ case'DAY_HOUR': // 'DAYS HOURS'
483+ return date('dH',$t);
484+ case'YEAR_MONTH': // 'YEARS-MONTHS'
485+ return date('Ym',$t);
486+ case'HOUR_SECOND': // 'HOURS:MINUTES:SECONDS'
487+ return date('Hs',$t);
488+ case'DAY_MINUTE': // 'DAYS HOURS:MINUTES'
489+ return date('di',$t);
490+ case'DAY_SECOND': // 'DAYS HOURS:MINUTES:SECONDS'
491+ return date('ds',$t);
492+ case'DAY': // DAYS
493+ default:
494+ return $dy;
495+ }
496+}
497+
498+var $define_FROM_DAYS='sqlite_userfunc_FROM_DAYS';
499+function sqlite_userfunc_FROM_DAYS($p1){
500+ return date('Y-m-d',($p1-719528)*86400);
501+}
502+
503+var $define_FROM_UNIXTIME='sqlite_userfunc_FROM_UNIXTIME';
504+function sqlite_userfunc_FROM_UNIXTIME($p1,$p2=null){
505+ if ($p2) return sqlite_userfunc_DATE_FORMAT($p1,$p2);
506+ return date('Y-m-d H:i:s',$p1);
507+}
508+
509+var $define_HOUR='sqlite_userfunc_HOUR';
510+function sqlite_userfunc_HOUR($p1){
511+ SQLite_Functions::sqlite_resolvedatetime($p1,$yr,$mt,$dy,$hr,$mn,$sc);
512+ return $hr;
513+}
514+
515+var $define_MINUTE='sqlite_userfunc_MINUTE';
516+function sqlite_userfunc_MINUTE($p1){
517+ SQLite_Functions::sqlite_resolvedatetime($p1,$yr,$mt,$dy,$hr,$mn,$sc);
518+ return $mn;
519+}
520+
521+var $define_MONTHNAME='sqlite_userfunc_MONTHNAME';
522+function sqlite_userfunc_MONTHNAME($p1){
523+ $t=SQLite_Functions::sqlite_resolvedatetime($p1,$yr,$mt,$dy,$hr,$mn,$sc);
524+ return date('F',$t);
525+}
526+
527+
528+var $define_PERIOD_ADD='sqlite_userfunc_PERIOD_ADD';
529+function sqlite_userfunc_PERIOD_ADD($p1,$p2){
530+ $y=(int)($p1/100);
531+ $m=$p1-$y*100;
532+ $t=mktime(0,0,0,$m+$p2,1,$y, -1);
533+ return date('Ym',$t);
534+}
535+
536+var $define_PERIOD_DIFF='sqlite_userfunc_PERIOD_DIFF';
537+function sqlite_userfunc_PERIOD_DIFF($p1,$p2){
538+ $y1=(int)($p1/100);
539+ $m1=$p1-$y1*100;
540+ $y2=(int)($p2/100);
541+ $m2=$p1-$y2*100;
542+ $t1=mktime(0,0,0,$m1,1,$y1, -1);
543+ $t2=mktime(0,0,0,$m2,1,$y2, -1);
544+ $y1=date('Y',$t1);
545+ $y2=date('Y',$t2);
546+ return (int)(mktime(0,0,0,$m1-$m2,1,1970+$y1-$y2, -1)/60/60/24/28);
547+}
548+
549+var $define_QUARTER='sqlite_userfunc_QUARTER';
550+function sqlite_userfunc_QUARTER($p1){
551+ SQLite_Functions::sqlite_resolvedatetime($p1,$yr,$mt,$dy,$hr,$mn,$sc);
552+ switch($mt){
553+ case 1: case 2: case 3: return 1;
554+ case 4: case 5: case 6: return 2;
555+ case 7: case 8: case 9: return 3;
556+ default: return 4;
557+ }
558+}
559+
560+var $define_SECOND='sqlite_userfunc_SECOND';
561+function sqlite_userfunc_SECOND($p1){
562+ SQLite_Functions::sqlite_resolvedatetime($p1,$yr,$mt,$dy,$hr,$mn,$sc);
563+ return $sc;
564+}
565+
566+var $define_SEC_TO_TIME='sqlite_userfunc_SEC_TO_TIME';
567+function sqlite_userfunc_SEC_TO_TIME($p1){
568+ return date('H:i:s',$p1);
569+}
570+
571+var $define_WEEK='sqlite_userfunc_WEEK';
572+function sqlite_userfunc_WEEK($p1){
573+ $t=SQLite_Functions::sqlite_resolvedatetime($p1,$yr,$mt,$dy,$hr,$mn,$sc);
574+ return date('W',$t);
575+}
576+
577+var $define_WEEKDAY='sqlite_userfunc_WEEKDAY';
578+function sqlite_userfunc_WEEKDAY($p1){
579+ $t=SQLite_Functions::sqlite_resolvedatetime($p1,$yr,$mt,$dy,$hr,$mn,$sc);
580+ if (0<($w=date('w',$t))) return $w-1;
581+ return 6;
582+}
583+
584+var $define_YEAR='sqlite_userfunc_YEAR';
585+function sqlite_userfunc_YEAR($p1){
586+ $t=SQLite_Functions::sqlite_resolvedatetime($p1,$yr,$mt,$dy,$hr,$mn,$sc);
587+ return date('Y',$t);
588+}
589+
590+var $define_YEARWEEK='sqlite_userfunc_YEARWEEK';
591+function sqlite_userfunc_YEARWEEK($p1){
592+ $t=SQLite_Functions::sqlite_resolvedatetime($p1,$yr,$mt,$dy,$hr,$mn,$sc);
593+ return date('YW',$t);
594+}
595+
596+
597+var $define_FIND_IN_SET='sqlite_userfunc_FIND_IN_SET';
598+function sqlite_userfunc_FIND_IN_SET($p1,$p2){
599+ if ($p1==null && $p2==null) return null;
600+ if (!$p2) return 0;
601+ foreach (explode(',',$p2) as $key=>$value) if ($value==$p1) return ($key+1);
602+ return 0;
603+}
604+
605+
606+var $define_ADDDATE='sqlite_userfunc_ADDDATE';
607+function sqlite_userfunc_ADDDATE($p1,$p2,$p3='DAY'){
608+ return date("Y-m-d",sqlite_ADDDATE($p1,$p2,$p3));
609+}
610+
611+var $define_SUBDATE='sqlite_userfunc_SUBDATE';
612+function sqlite_userfunc_SUBDATE($p1,$p2,$p3='DAY'){
613+ return date("Y-m-d",sqlite_ADDDATE($p1,0-$p2,$p3));
614+}
615+
616+var $define_CONCAT='sqlite_userfunc_CONCAT';
617+function sqlite_userfunc_CONCAT(){
618+ if (!($lastnum=func_num_args())) return null;
619+ $args=&func_get_args();
620+ $ret='';
621+ for ($i=0;$i<$lastnum;$i++) {
622+ if ($args[$i]===null) return null;
623+ $ret.=(string)($args[$i]);
624+ }
625+ return $ret;
626+}
627+
628+var $define_IF='sqlite_userfunc_IF';
629+function sqlite_userfunc_IF($p1,$p2,$p3){
630+ if ((int)$p1) return $p2;
631+ return $p3;
632+}
633+
634+var $define_IFNULL='sqlite_userfunc_IFNULL';
635+function sqlite_userfunc_IFNULL($p1,$p2){
636+ if ($p1!=null) return $p1;
637+ return $p2;
638+}
639+
640+var $define_NULLIF='sqlite_userfunc_NULLIF';
641+function sqlite_userfunc_NULLIF($p1,$p2){
642+ if ($p1==$p2) return null;
643+ return $p1;
644+}
645+
646+
647+var $define_match_against='sqlite_userfunc_match_against';
648+function sqlite_userfunc_match_against(){
649+ if (!($lastnum=func_num_args())) return 0;
650+ if (!(--$lastnum)) return 0;
651+ $args=&func_get_args();
652+ if (!$args[$lastnum]) return 0;
653+ $pattern='/'.quotemeta($args[$lastnum]).'/i';
654+ $ret=0;
655+ for($i=0;$i<$lastnum;$i++) $ret=$ret+preg_match_all ($pattern,$args[$i],$matches);
656+ return $ret;
657+}
658+
659+var $define_replace='sqlite_userfunc_replace';
660+function sqlite_userfunc_replace($p1,$p2,$p3){
661+ return str_replace($p3,$p1,$p2);
662+}
663+
664+var $define_UNIX_TIMESTAMP='sqlite_userfunc_UNIX_TIMESTAMP';
665+function sqlite_userfunc_UNIX_TIMESTAMP($p1=null){
666+ if (!$p1) return time();
667+ SQLite_Functions::sqlite_resolvedatetime($p1,$yr,$mt,$dy,$hr,$mn,$sc);
668+ if ($yr) return mktime($hr,$mn,$sc,$mt,$dy,$yr, -1);
669+ return $p1;//TIMESTAMP
670+}
671+
672+var $define_REGEXP='sqlite_userfunc_REGEXP';
673+function sqlite_userfunc_REGEXP($p1,$p2){
674+ return preg_match ("/$p2/",$p1);
675+}
676+
677+var $define_DAYOFMONTH='sqlite_userfunc_DAYOFMONTH';
678+function sqlite_userfunc_DAYOFMONTH($p1){
679+ SQLite_Functions::sqlite_resolvedatetime($p1,$yr,$mt,$dy,$hr,$mn,$sc);
680+ return $dy;
681+}
682+
683+var $define_MONTH='sqlite_userfunc_MONTH';
684+function sqlite_userfunc_MONTH($p1){
685+ SQLite_Functions::sqlite_resolvedatetime($p1,$yr,$mt,$dy,$hr,$mn,$sc);
686+ return $mt;
687+}
688+
689+
690+function sqlite_resolvedatetime($p1,&$yr,&$mt,&$dy,&$hr,&$mn,&$sc){
691+ $t=trim($p1);
692+ if (preg_match('/^([0-9]{4})-([0-9]{2})-([0-9]{2}) ([0-9]{2}):([0-9]{2}):([0-9]{2})$/', $t,$matches)) {
693+ //DATETIME
694+ $yr=(int)$matches[1];
695+ $mt=(int)$matches[2];
696+ $dy=(int)$matches[3];
697+ $hr=(int)$matches[4];
698+ $mn=(int)$matches[5];
699+ $sc=(int)$matches[6];
700+ } else if (preg_match('/^([0-9]{4})-([0-9]{2})-([0-9]{2})$/', $t,$matches)) {
701+ //DATE
702+ $yr=(int)$matches[1];
703+ $mt=(int)$matches[2];
704+ $dy=(int)$matches[3];
705+ $hr=$mn=$sc=0;
706+ } else if (preg_match('/^([0-9]{4})([0-9]{2})([0-9]{2})$/', $t,$matches)) {
707+ //YYYYMMDD
708+ $yr=(int)$matches[1];
709+ $mt=(int)$matches[2];
710+ $dy=(int)$matches[3];
711+ $hr=$mn=$sc=0;
712+ } else if (preg_match('/^([0-9]{2})([0-9]{2})([0-9]{2})$/', $t,$matches)) {
713+ //YYMMDD
714+ $yr=(int)$matches[1];
715+ $mt=(int)$matches[2];
716+ $dy=(int)$matches[3];
717+ $hr=$mn=$sc=0;
718+ if ($yr<70) $yr=$yr+2000;
719+ else $yr=$yr+1900;
720+ }
721+ return mktime($hr,$mn,$sc,$mt,$dy,$yr, -1);
722+}
723+
724+function sqlite_ADDDATE($p1,$p2,$p3){
725+ SQLite_Functions::sqlite_resolvedatetime($p1,$yr,$mt,$dy,$hr,$mn,$sc);
726+ $a=explode(' ',preg_replace('/[^0-9]/',' ',trim((string)$p2)));
727+ switch(strtoupper($p3)) {
728+ case'SECOND': // SECONDS
729+ $sc += (int)$p2;
730+ break;
731+ case'MINUTE': // MINUTES
732+ $mn += (int)$p2;
733+ break;
734+ case'HOUR': // HOURS
735+ $hr += (int)$p2;
736+ break;
737+ case'MONTH': // MONTHS
738+ $mt += (int)$p2;
739+ break;
740+ case'YEAR': // YEARS
741+ $yr += (int)$p2;
742+ break;
743+ case'MINUTE_SECOND': // 'MINUTES:SECONDS'
744+ $mn += (int)$a[0];
745+ $sc += (int)$a[1];
746+ break;
747+ case'HOUR_MINUTE': // 'HOURS:MINUTES'
748+ $hr += (int)$a[0];
749+ $mn += (int)$a[1];
750+ break;
751+ case'DAY_HOUR': // 'DAYS HOURS'
752+ $dy += (int)$a[0];
753+ $hr += (int)$a[1];
754+ break;
755+ case'YEAR_MONTH': // 'YEARS-MONTHS'
756+ $yr += (int)$a[0];
757+ $mt += (int)$a[1];
758+ break;
759+ case'HOUR_SECOND': // 'HOURS:MINUTES:SECONDS'
760+ $hr += (int)$a[0];
761+ $mn += (int)$a[1];
762+ $sc += (int)$a[2];
763+ break;
764+ case'DAY_MINUTE': // 'DAYS HOURS:MINUTES'
765+ $dy += (int)$a[0];
766+ $hr += (int)$a[1];
767+ $mn += (int)$a[2];
768+ break;
769+ case'DAY_SECOND': // 'DAYS HOURS:MINUTES:SECONDS'
770+ $dy += (int)$a[0];
771+ $hr += (int)$a[1];
772+ $mn += (int)$a[2];
773+ $sc += (int)$a[3];
774+ break;
775+ case'DAY': // DAYS
776+ default:
777+ $dy += (int)$p2;
778+ break;
779+ }
780+ return mktime($hr,$mn,$sc,$mt,$dy,$yr, -1);
781+}
782+
783+// For creating table structure (table and index/indeces)
784+var $define_sqlite_table_structure='sqlite_userfunc_sqlite_table_structure';
785+function sqlite_userfunc_sqlite_table_structure($p1){
786+ global $SQLITE_DBHANDLE;
787+ $ret='';
788+ if ($res=sqlite_query($SQLITE_DBHANDLE,"SELECT sql FROM sqlite_master WHERE tbl_name='$p1'")) {
789+ while ($array=sqlite_fetch_array($res,SQLITE_NUM)) $ret.=$array[0].";\n";
790+ }
791+ return $ret;
792+}
793+
794+
795+// Modification of query for some functions.
796+function sqlite_modifyQueryForUserFunc(&$query,$strpositions,$pattern=null,$replacement=null){
797+ // Write this part very carefully. Otherwise, you may allow crackers to do SQL-injection.
798+ global $SQLITE_MQFUFCB_OK,$SQLITE_MQFUFCB_COUNT,$SQLITE_MQFUFCB_REPLACE;
799+
800+ // Store the previous string
801+ $orgstrings=array();
802+ foreach ($strpositions as $start => $end) array_push($orgstrings, trim(substr($query,$start,$end-$start)));
803+
804+ $lquery=strtolower($query);
805+ if (!$pattern) $pattern=array();
806+ if (!$replacement) $replacement=array();
807+
808+ // match() against() support. Following way does NOT accept SQL-injection. Note that the string is always quoted by "'".
809+ array_push($pattern,'/match \(([^\']*?)\) against \(/i');
810+ array_push($replacement,'match_against ($1,');
811+ // REGEXP support
812+ if (strpos($lquery,'regexp')!==false) {
813+ array_push($pattern,'/([^a-z_\.])([a-z_\.]+)[\s]+REGEXP[\s]+\'([^\']*?)\'([^\']?)/i');
814+ array_push($replacement,'$1regexp($2,\'$3\')$4');
815+ }
816+ // ADDDATE/SUBDATE support (INTERVAL support)
817+ array_push($pattern,'/([^a-zA-Z_])ADDDATE[\s]*?\(([^,]+),[\s]*?INTERVAL[\s]+([\S]+)[\s]+([^\)]+)\)/i');
818+ array_push($replacement,'$1adddate($2,$3,\'$4\')');
819+ array_push($pattern,'/([^a-zA-Z_])DATE_ADD[\s]*?\(([^,]+),[\s]*?INTERVAL[\s]+([\S]+)[\s]+([^\)]+)\)/i');
820+ array_push($replacement,'$1adddate($2,$3,\'$4\')');
821+ array_push($pattern,'/([^a-zA-Z_])SUBDATE[\s]*?\(([^,]+),[\s]*?INTERVAL[\s]+([\S]+)[\s]+([^\)]+)\)/i');
822+ array_push($replacement,'$1subdate($2,$3,\'$4\')');
823+ array_push($pattern,'/([^a-zA-Z_])DATE_SUB[\s]*?\(([^,]+),[\s]*?INTERVAL[\s]+([\S]+)[\s]+([^\)]+)\)/i');
824+ array_push($replacement,'$1subdate($2,$3,\'$4\')');
825+
826+ // EXTRACT support
827+ array_push($pattern,'/([^a-zA-Z_])EXTRACT[\s]*?\(([a-zA-Z_]+)[\s]+FROM/i');
828+ array_push($replacement,'$1extract(\'$2\',');
829+
830+ // TRIM support:
831+ array_push($pattern,'/([^a-zA-Z_])TRIM[\s]*?\((BOTH|LEADING|TRAILING)[\s]+FROM/i');
832+ array_push($replacement,'$1extract(\'$2\',\' \',');
833+ array_push($pattern,'/([^a-zA-Z_])TRIM[\s]*?\((BOTH|LEADING|TRAILING)[\s]+([\s\S]+)[\s]+FROM/i');
834+ array_push($replacement,'$1extract(\'$2\',$3,');
835+
836+ // Change it.
837+ $temp=preg_replace ($pattern,$replacement,$query);
838+
839+ // Comfirm if strings did not change.
840+ $ok=true;
841+ foreach ($orgstrings as $key=>$value) if ($value) {
842+ if (strpos($temp,$value)!==false) {
843+ // This string is OK, therefore will be ignored in the next "step by step" step.
844+ $orgstrings[$key]='';
845+ continue;
846+ }
847+ $ok=false;
848+ }
849+ if ($ok) { // return if everything is OK.
850+ $query=$temp;
851+ return;
852+ }
853+
854+ // At least one of string changed. Need to do step by step.
855+ foreach ($pattern as $key=>$pat) {
856+ // Replace is done step by step for each RegExp replace statement.
857+ $SQLITE_MQFUFCB_REPLACE=$replace[$key];// Set the grobal var.
858+ $num=preg_match_all($pat,$query,$matches);
859+ // First, check if OK.
860+ $replaceOK=array();
861+ for ($i=1;$i<=$num;$i++) {
862+ $SQLITE_MQFUFCB_OK=array();
863+ $SQLITE_MQFUFCB_OK[$i]=true; // Set the grobal var.
864+ $SQLITE_MQFUFCB_COUNT=0; // Set the grobal var.
865+ // Only $i-st replacement will be done in the next line.
866+ $temp=preg_replace_callback($pat,array('SQLite_Functions','sqlite_modifyQueryForUserFuncCallBack'), $query, $i);
867+ $ok=true;
868+ foreach ($orgstrings as $value) if ($value) {
869+ if (strpos($temp,$value)!==false) continue;
870+ $ok=false;
871+ break;
872+ }
873+ if ($ok) $replaceOK[$i]=true;
874+ }
875+ // Replace
876+ $SQLITE_MQFUFCB_OK=$replaceOK;// Copy the OK array
877+ $SQLITE_MQFUFCB_COUNT=0;
878+ $query=preg_replace_callback($pat,array('SQLite_Functions','sqlite_modifyQueryForUserFuncCallBack'), $query);
879+ }
880+}
881+
882+function sqlite_modifyQueryForUserFuncCallBack($mathces){
883+ global $SQLITE_MQFUFCB_OK,$SQLITE_MQFUFCB_COUNT,$SQLITE_MQFUFCB_REPLACE;
884+ if ($SQLITE_MQFUFCB_OK[++$SQLITE_MQFUFCB_COUNT]) return $SQLITE_MQFUFCB_REPLACE;
885+ else return $mathces[0];
886+}
887+
888+}//class SQLite_QueryFunctions
889+
890+?>
\ No newline at end of file
--- /dev/null
+++ b/tags/sqlite0903/sqlite/readme-en.txt
@@ -0,0 +1,39 @@
1+*************************************************
2+* MySQL-SQLite wrapper for Nucleus ver 0.8 *
3+*************************************************
4+
5+Copyright (C) 2006-2007 Katsumi
6+
7+This program is free software; you can redistribute it and/or
8+modify it under the terms of the GNU General Public License
9+as published by the Free Software Foundation; either version 2
10+of the License, or (at your option) any later version.
11+
12+This program is distributed in the hope that it will be useful,
13+but WITHOUT ANY WARRANTY; without even the implied warranty of
14+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+GNU General Public License for more details.
16+
17+You should have received a copy of the GNU General Public License
18+along with this program; if not, write to the Free Software
19+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20+
21+----------------------------------------------------------------------
22+
23+This tool is needed when using Nucleus with SQLite as database engine.
24+
25+
26+****************************** How to use ******************************
27+
28+ When installing Nucleus, the access-ID and password are not required. SQLite
29+uses normal file as database. This is fixed to "nucleus/sqlite/.dbsqlite"
30+(if you would like another file name, please set it in "sqlite.php" file).
31+Set the permission of "nucleus/sqlite/" directory to 777 or something like this.
32+Then execute install.php. That's it! If you see the install-complete message,
33+probably the install is succeded. NP_SkinFiles as well as NP_SQLite are
34+automatically installed. If not, install it manually.
35+
36+ The usage of Nucleus is almost (99%) the same as that of normal Nucleus. When
37+installing plugins, NP_SQLite will convert the plugin files automatically if the
38+permission of these files is set to be writable.
39+
--- /dev/null
+++ b/tags/sqlite0903/sqlite/readme-ja.txt
@@ -0,0 +1,45 @@
1+**********************************************
2+* MySQL-SQLite wrapper for Nucleus ver 0.8 *
3+**********************************************
4+
5+Copyright (C) 2006-2007年、Katsumi
6+
7+このプログラムはフリーソフトウェアです。あなたはこれを、フリーソフトウェ
8+ア財団によって発行された GNU 一般公衆利用許諾契約書(バージョン2か、希
9+望によってはそれ以降のバージョンのうちどれか)の定める条件の下で再頒布
10+または改変することができます。
11+
12+このプログラムは有用であることを願って頒布されますが、*全くの無保証*
13+です。商業可能性の保証や特定の目的への適合性は、言外に示されたものも含
14+め全く存在しません。詳しくはGNU 一般公衆利用許諾契約書をご覧ください。
15+
16+あなたはこのプログラムと共に、GNU 一般公衆利用許諾契約書の複製物を一部
17+受け取ったはずです。もし受け取っていなければ、フリーソフトウェア財団ま
18+で請求してください(宛先は the Free Software Foundation, Inc., 59
19+Temple Place, Suite 330, Boston, MA 02111-1307 USA)。
20+
21+----------------------------------------------------------------------
22+
23+このツールは、Nucleus でデータベースとして、SQLite を用いるための物です。
24+
25+*************** 使用方法 ***************
26+
27+ Nucleus のインストールの際は、データベースのアクセスIDやパスワードなどは
28+指定する必要はありません。SQLite はデータベースとして通常ファイルを用います。
29+これは、『nucleus/sqlite/.dbsqlite』固定です。インストール前に『nucleus/sqlite/』
30+フォルダのパーミッションを、読み書き可能な形(777とか)にしてください。別の
31+ファイル名を使用したい場合は、『nucleus/sqlite/sqlite.php』を書き換えてください。
32+
33+ あとは、『install.php』を実行するだけです。オリジナル版のNucleusと同じよ
34+うなインストール完了画面が出れば、おそらくインストールが成功しています。
35+このとき、NP_SkinFiles に加えて、NP_SQLite もプラグインとしてデフォルトでインス
36+トールされるはずです。もしインストールされていない場合は、手動でインストール
37+してください。
38+
39+ あとの使い方は普通の Nucleus と 99% 同じです。プラグインをインストールする際は、
40+PHPファイルのパーミッションを読み書き可能な設定にしておけば、NP_SQLite が自動的に
41+SQLite用にプラグインのPHPファイルを書き換えてくれるはずです。
42+
43+ extra/sqlite/ フォルダには、Nucleus のバージョンアップがあった際の対処
44+ツールが置かれていますので、開発者の方はそちらも参照してください。
45+
Show on old repository browser