From: kmorimatsu Date: Tue, 17 Mar 2009 02:05:38 +0000 (+0000) Subject: tag: sqlite0904 X-Git-Url: http://git.osdn.net/view?p=nucleus-jp%2Fnucleus-plugins.git;a=commitdiff_plain;h=3008baa64341621fee4992fe248885d8fb25f6f7 tag: sqlite0904 git-svn-id: https://svn.sourceforge.jp/svnroot/nucleus-jp/plugin@981 1ca29b6e-896d-4ea0-84a5-967f57386b96 --- diff --git a/sqlite/tags/sqlite0904/extra/sqlite/installsqlite.php b/sqlite/tags/sqlite0904/extra/sqlite/installsqlite.php new file mode 100644 index 0000000..f0c4c9d --- /dev/null +++ b/sqlite/tags/sqlite0904/extra/sqlite/installsqlite.php @@ -0,0 +1,86 @@ + nucleus_mysql_xxx converter * +* for Nucleus * +* ver 0.6.1b Written by Katsumi * +*******************************************/ + +// The license of this script is GPL + +// Check lanuage +if (strpos(strtolower($_SERVER['HTTP_ACCEPT_LANGUAGE']),'ja')===0) { + $charset='EUC-JP'; +} else { + $charset='iso-8859-1'; +} +header("Content-Type: text/html; charset=$charset"); + +if (!file_exists('./nucleus/sqlite/convert.php')) exit; +include('./nucleus/sqlite/convert.php'); + +?>¤³¤Î¥Ú¡¼¥¸¤Ç¤Ï¡¢SQLite ¤Ç»ÈÍѤ¹¤ë¤¿¤á¤Î Nucleus ¤Î³Æ¥Õ¥¡¥¤¥ë¤ÎÊѹ¹¤ò¹Ô¤¤¤Þ¤¹¡£

+ ¤¹¤Ù¤Æ¤Î "mysql_xxx" ´Ø¿ô¸Æ¤Ó½Ð¤·¤Îɽµ­¤¬ "nucleus_mysql_xxx"¤ËÊѹ¹¤µ¤ì¤Þ¤¹.

+ + ¤³¤ÎÊѹ¹¤Ï¡¢MySQL ´Ø¿ô¤¬ PHP ¤Ë¥¤¥ó¥¹¥È¡¼¥ë¤µ¤ì¤Æ¤¤¤Ê¤¤¾ì¹ç¤Ë¤Ï¡¢É¬¿Ü¤Ç¤Ï¤¢¤ê¤Þ¤»¤ó¡£
+ ¤³¤Î¾ì¹ç "install.php" ¤È "config.php" ¤À¤±¤ËÊѹ¹¤¬É¬ÍפǤ¹¡£
+ ¤â¤·MySQL ´Ø¿ô¤¬¥¤¥ó¥¹¥È¡¼¥ë¤µ¤ì¤Æ¤ª¤é¤º¡¢¾­ÍèŪ¤Ë¤â¥¤¥ó¥¹¥È¡¼¥ë¤µ¤ì¤Ê¤¤¤³¤È¤¬³Î¼Â¤Ê¾ì¹ç¡¢
+ ¤³¤³¤ò¥¯¥ê¥Ã¥¯¤·¤Æ¤¯¤À¤µ¤¤(install.php ¤È config.php ¤¬Êѹ¹¤µ¤ì¤Þ¤¹)¡£

+ ¤½¤¦¤Ç¤Ê¤±¤ì¤Ð¡¢²¼¤Î¥ê¥ó¥¯¤ò¥¯¥ê¥Ã¥¯¤·¤Æ¤¯¤À¤µ¤¤¡£

+ + Êѹ¹¤ò³«»Ï(¤³¤Î¥Ç¥£¥ì¥¯¥È¥ê¤Î¤¹¤Ù¤Æ¤Î PHP ¥Õ¥¡¥¤¥ë¤¬Êѹ¹¤µ¤ì¤Þ¤¹)¡£

+ »Ï¤á¤ëÁ°¤Ë¡¢Êѹ¹¤µ¤ì¤ë¤Ù¤­ PHP ¥Õ¥¡¥¤¥ë¤Î¥Ñ¡¼¥ß¥Ã¥·¥ç¥ó¤¬¡¢Æɤ߽ñ¤­²Äǽ¤Ë¤Ê¤Ã¤Æ¤¤¤ë¤³¤È¤ò³Îǧ¤·¤Æ¤¯¤À¤µ¤¤¡£ + This page is to modify Nucleus core files for using SQLite as database engine.

+ All the "mysql_xxx" functions will be converted to "nucleus_mysql_xxx".

+ + This modification is not required if MySQL functions of PHP are not installed in the server.
+ In this case, only the "install.php" and "config.php" must be modified.
+ If you are sure that the MySQL function is never (now and in future) installed,
+ please click here(install.php and config.php will be changed).

+ Otherwise, please click following link.

+ + Start modification(all the PHP files in this directory will be changed).

+ Please make sure that all PHP files to be modified are readable and writable. + ¤¹¤Ù¤Æ¤ÎÊѹ¹¤¬½ªÎ»¤·¤Þ¤·¤¿¡£
+ ¤³¤³¤ò¥¯¥ê¥Ã¥¯¤·¤Æ Nucleus w/SQLite ¤Î¥¤¥ó¥¹¥È¡¼¥ë¤ò³«»Ï¤·¤Æ¤¯¤À¤µ¤¤¡£
+ All modificatios are sccesfully done.
+ Click here to install Nucleus w/SQLite
+ \ No newline at end of file diff --git a/sqlite/tags/sqlite0904/extra/sqlite/readme-ja.txt b/sqlite/tags/sqlite0904/extra/sqlite/readme-ja.txt new file mode 100644 index 0000000..a955bb4 --- /dev/null +++ b/sqlite/tags/sqlite0904/extra/sqlite/readme-ja.txt @@ -0,0 +1,45 @@ +@‚±‚̃m[ƒg‚ł́ANucleus ‚̐V‚µ‚¢ƒo[ƒWƒ‡ƒ“‚ªŒöŠJ‚³‚ê +‚½Û‚ɁASQLite ”ł𐻍삷‚é•û–@‚ɂ‚¢‚ďq‚ׂ܂·B + + +–––––@installsqlite.php ‚ɂ‚¢‚āB@––––– + +@Žå‚ÈŽg—p–Ú“I‚́ANucleus ‚̃o[ƒWƒ‡ƒ“ƒAƒbƒv‚ª‚ ‚Á‚½Û +‚ɁASQLite ‘Ήž‚É‚·‚邽‚߂ɃRƒAƒtƒ@ƒCƒ‹‚ð‘‚«Š·‚¦‚邱 +‚Æ‚Å‚·BƒRƒA‚Ì PHP ƒtƒ@ƒCƒ‹‚Ì mysql_xxxx() ‚ª‚·‚ׂāA +nucleus_mysql_xxxx() ‚ɏ‘‚«Š·‚¦‚ç‚ê‚Ü‚·BŽg—p‚·‚éÛ‚́A +‚±‚̃tƒ@ƒCƒ‹‚ð Nucleus ‚̃‹[ƒgƒfƒBƒŒƒNƒgƒŠ(config.php +‚Ì‚ ‚éêŠ)‚Ɉړ®‚µAƒuƒ‰ƒEƒU‚ŃAƒNƒZƒX‚µ‚Ä‚­‚¾‚³‚¢B + +@‰Á‚¦‚āAinstall.php ‹y‚сAconfig.php ‚ɁA +winclude($DIR_NUCLEUS.'sqlite/sqlite.php');x‚ªŽ©“®“I‚É +‘‚«‘«‚³‚ê‚Ü‚·B + +@backup.php ‚́ASQLite ‚ł̃f[ƒ^ƒŠƒXƒgƒA‚ªÅ“K‰»‚³‚ê +‚é‚悤‚ɁA•ÏX‚³‚ê‚Ü‚·isqlite_restore_execute_queries() +‚ªŽg—p‚³‚ê‚é‚悤‚É‚È‚è‚Ü‚·jB + +@‚³‚ç‚ɁAinstall.php ‚ł̃Cƒ“ƒXƒg[ƒ‹‰æ–Ê‚ÌHTML‚ªŽáŠ± +C³‚³‚êAˆê•”‚ÌMySQL“ÁˆÙ“I‚ȃIƒvƒVƒ‡ƒ“‚Ɂwdummyx‚ªŽw +’肳‚ê‚é‚悤‚ɕύX‚³‚ê‚Ü‚·B + +@install.sql ‚Ì nucleus_plugin_option ƒe[ƒuƒ‹ì¬•”•ª‚Ì +ƒNƒGƒŠ[•¶‚ªˆÈ‰º‚̂悤‚ɕύX‚³‚ê‚Ü‚·iauto_increment‚ªíœ +‚³‚ê‚Ü‚·jB + +CREATE TABLE `nucleus_plugin_option` ( + `ovalue` text NOT NULL, + `oid` int(11) NOT NULL, + `ocontextid` int(11) NOT NULL default '0', + PRIMARY KEY (`oid`,`ocontextid`) +) TYPE=MyISAM; + + +–––––@Žè“®‚ŕύX‚µ‚È‚¢‚Æ‚¢‚¯‚È‚¢Ž–€@––––– + +@installsqlite.php ‚ÌŽÀs‚Å•K—v‚ȕύX‚Ì‚¤‚¿d—v‚È•¨‚É +‚‚¢‚Ä‚Í–w‚Ǎs‚í‚ê‚Ü‚·‚ªAˆê•”Žè“®‚ŕύX‚µ‚È‚¯‚ê‚΂Ȃç +‚È‚¢•”•ª‚ª‚ ‚é‰Â”\«‚ª‚ ‚è‚Ü‚·B + +@SQLite wrapper 0.81 ‚ł́ANucleus 3.2x‚ÆNucleus3.3‚ð +•ÏX‚·‚éã‚ŁAŽè“®‚ł̕ύX‚Í•K—v‚ ‚è‚Ü‚¹‚ñB diff --git a/sqlite/tags/sqlite0904/license.txt b/sqlite/tags/sqlite0904/license.txt new file mode 100644 index 0000000..dcfa4c2 --- /dev/null +++ b/sqlite/tags/sqlite0904/license.txt @@ -0,0 +1,340 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc. + 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Library General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Library General +Public License instead of this License. diff --git a/sqlite/tags/sqlite0904/nucleus/plugins/NP_SQLite.php b/sqlite/tags/sqlite0904/nucleus/plugins/NP_SQLite.php new file mode 100644 index 0000000..8eea475 --- /dev/null +++ b/sqlite/tags/sqlite0904/nucleus/plugins/NP_SQLite.php @@ -0,0 +1,185 @@ +install(); return 'Katsumi'; } + function getVersion() { global $SQLITECONF; return $SQLITECONF['VERSION']; } + function getURL() {return 'http://hp.vector.co.jp/authors/VA016157/';} + function getDescription() { return $this->showinfo(); } + function supportsFeature($what) { return (int)($what=='SqlTablePrefix'); } + function getEventList() { return array('PreAddPlugin','PreSkinParse','QuickMenu'); } + function hasAdminArea() { return 1; } + + function install(){ + if (!$this->getOption('allowsql')) { + $this->createOption('allowsql',$this->translated('Allow SQL query during the management?'),'yesno','no'); + } + if (!$this->getOption('numatonce')) { + $this->createOption('numatonce',$this->translated('Number of SQL queries at once when DB restore.'),'text','20','datatype=numerical'); + $this->createOption('refreshwait',$this->translated('Wating tile (seconds) when DB restore.'),'text','1','datatype=numerical'); + } + } + + var $infostr; + function showinfo() { + global $SQLITECONF; + if ($this->infostr) echo "".$this->infostr."
\n"; + return $this->translated('NP_SQLite plugin. Filesize of DB is now ').filesize($SQLITECONF['DBFILENAME']).' bytes.'; + } + + function init(){ + } + + function event_QuickMenu(&$data){ + global $member; + $this->_showDebugMessage(); + + // only show to admins + if (!($member->isLoggedIn() && $member->isAdmin())) return; + + array_push($data['options'], array( + 'title' => 'SQLite', + 'url' => $this->getAdminURL(), + 'tooltip' => $this->translated('SQLite management') + ) ); + } + function event_PreSkinParse(&$data){ + $this->_showDebugMessage(); + } + function _showDebugMessage(){ + global $SQLITECONF; + if (isset($SQLITECONF['DEBUGMESSAGE'])) sqlite_DebugMessage(); + unset($SQLITECONF['DEBUGMESSAGE']); + } + + function event_PreAddPlugin(&$data){ + // This event happens before loading "NP_XXXX.php" file. + // Therefore, modification is possible here. + $this->modify_plugin($data['file'],true); + } + function modify_plugin($pluginfile,$install=false){ + global $DIR_PLUGINS,$SQLITECONF; + if ($SQLITECONF['OVERRIDEMODE']) return true; + + $admindir=$DIR_PLUGINS.strtolower(substr($pluginfile,3)); + $pluginfile=$DIR_PLUGINS.$pluginfile; + + // List up all PHP files. + $phpfiles=array(); + array_push($phpfiles,$pluginfile.'.php'); + $this->seekPhpFiles($admindir,$phpfiles); + + // Modify the PHP files. + $allok=true; + foreach ($phpfiles as $file) { + if (!$this->changeFunctions($file)) { + $allok=false; + } + } + if ($allok) { + if ($install) $this->infostr=$this->translated('Pluing was installed sucessfully'); + return true; + } + + if (!$install) return false; + if ($this->is_japanese()) { + echo ''; + echo '

PHP ¥Õ¥¡¥¤¥ë¤ò¼êÆ°¤ÇÊѹ¹¤¹¤ëɬÍפ¬¤¢¤ê¤Þ¤¹¡£

'; + } else echo '

Need to modify PHP file(s) manually.

'; + foreach ($phpfiles as $file) echo $this->show_Lines($file); + exit (''); + } + + function seekPhpFiles($dir,&$phpfiles){ + if (!is_dir($dir)) return; + $d = dir($dir); + $dirpath=realpath($d->path); + $dirs=array(); + if (substr($dirpath,-1)!='/' && substr($dirpath,-1)!="\\") $dirpath.='/'; + while (false !== ($entry = $d->read())) { + if ($entry=='.' || $entry=='..') continue; + if (is_file($dirpath.$entry) && substr($entry,-4)=='.php') array_push($phpfiles,realpath($dirpath.$entry)); + if (is_dir($dirpath.$entry)) array_push($dirs,realpath($dirpath.$entry)); + } + $d->close(); + foreach($dirs as $dir) $this->seekPhpFiles($dir,$phpfiles); + } + function changeFunctions($file){ + if (!is_file($file=realpath($file))) return false; + if (!is_readable($file)) return false; + $before=$this->read_from_file($file); + // Do this process until change does not occur.. + // Otherwise, sometime file is not completely modified. + $after=$this->do_replace($before); + if ($before!=$after) return $this->write_to_file($file,$after); + return true; + } + function do_replace(&$text) { + // Do this process until change does not occur.. + // Otherwise, sometime file is not completely modified. + $after=$text; + do $after=preg_replace('/([^_])mysql_([_a-z]+)([\s]*?)\(/','$1nucleus_mysql_$2(',($before=$after)); + while ($before!=$after); + return $after; + } + function show_Lines($file){ + if (!is_file($file=realpath($file))) return ''; + if (!is_readable($file)) return ''; + $result=''; + $lines=file($file); + $firsttime=true; + foreach($lines as $num=>$before) { + $after=$this->do_replace($before); + if ($after!=$before) { + if ($firsttime) $result.="
\nFile: $file

\n"; + $firsttime=false; + $result.="Modify line ".($num+1)." like: "\n"; + $result.=str_replace('nucleus_mysql_','nucleus_mysql_',htmlspecialchars($after)).""

\n"; + } + } + return $result; + } + function read_from_file($file) { + if (function_exists('file_get_contents') ) $ret=file_get_contents($file); + else { + ob_start(); + readfile($file); + $ret=ob_get_contents(); + ob_end_clean(); + } + return $ret; + } + function write_to_file($file,&$text){ + if (!$handle = @fopen($file, 'w')) return false; + fwrite($handle,$text); + fclose($handle); + return true; + } + function is_japanese(){ + $language = str_replace( array('\\','/'), array('',''), getLanguageName()); + return (strpos($language,'japanese')===0); + } + + // Language stuff + var $langArray; + function translated($english){ + if (!is_array($this->langArray)) { + $this->langArray=array(); + $language=$this->getDirectory().'language/'.str_replace( array('\\','/'), array('',''), getLanguageName()).'.php'; + if (file_exists($language)) include($language); + } + if (!($ret=$this->langArray[$english])) $ret=$english; + return $ret; + } + +} +?> \ No newline at end of file diff --git a/sqlite/tags/sqlite0904/nucleus/plugins/sqlite/index.php b/sqlite/tags/sqlite0904/nucleus/plugins/sqlite/index.php new file mode 100644 index 0000000..a44f5b0 --- /dev/null +++ b/sqlite/tags/sqlite0904/nucleus/plugins/sqlite/index.php @@ -0,0 +1,241 @@ +start(); + $p=&$pa->plugin; + $pluginUrl=$p->getAdminURL(); + + + // check if superadmin is logged in + if (!($member->isLoggedIn() && $member->isAdmin())) + { + echo '

' . _ERROR_DISALLOWED . '

'; + $pa->end(); + exit; + } + + // Check ticket + if (requestVar('SQLiteCommand') && (!$manager->checkTicket())){ + echo '

' . _ERROR_BADTICKET . '

'; + $pa->end(); + exit; + } + $ticket=$manager->addTicketToUrl(''); + $ticket=substr($ticket,strpos($ticket,'ticket=')+7); + +?>'.$p->translated('SQLite management')."\n"; + + $infostr=''; + switch(requestVar('SQLiteCommand')){ + case 'VACUUM': + nucleus_mysql_query('VACUUM'); + $infostr='VACUUM was done.'; + break; + case 'integrity_check': + $res=nucleus_mysql_query('PRAGMA integrity_check'); + $infostr='Integrity check result:'."
\n"; + while ($a=nucleus_mysql_fetch_array($res)) $infostr.=$a[0]."
\n"; + break; + case 'plugin_check': + $pluginfile=requestVar('plugin'); + $query='SELECT COUNT(*) as result FROM `'.sql_table('plugin').'` WHERE pfile="'.addslashes($pluginfile).'"'; + if (!quickQuery($query)) { + $infostr="No such plugin!"; + break; + } + if ($p->modify_plugin($pluginfile)) { + $infostr=$p->translated('The plugin, ').$pluginfile.$p->translated(' was checked and modified (if modification required)'); + break; + } + + // Modification failed. Show the lines that must be modified + $phpfiles=array(); + array_push($phpfiles,$DIR_PLUGINS.$pluginfile.'.php'); + $admindir=$DIR_PLUGINS.strtolower(substr($pluginfile,3)); + $p->seekPhpFiles($admindir,$phpfiles); + $infostr=$p->translated('Please modify the PHP files').":
\n"; + foreach ($phpfiles as $file) $infostr.=$p->show_Lines($file); + break; + case "QUERY": + $infostr='
'.'Query'. +'    (->Copy)'. + "
\n".htmlspecialchars($query=requestVar('query'))."

\n"; + if (requestVar('confirm')!='confirmed'){ + $infostr=$p->translated('Please check the "I am sure." checkbox to execute query').$infostr; + break; + } + ob_start(); + $res=nucleus_mysql_query($query); + $errorstr=ob_get_contents(); + ob_end_clean(); + if (!$res) { + $infostr.=nucleus_mysql_error()."
\n"; + if (preg_match('/sqlite_query\(\):([^<]*)in /i',$errorstr,$matches)) $infostr.=$matches[1]; + break; + } + if (preg_match('/ OFFSET ([0-9]+)$/i',$query,$matches)) $offset=$matches[1]; + else $offset=0; + + // Get resut into an array + $resulttable=array(); + $columnname=array(); + $columnnum=0; + while ($a=nucleus_mysql_fetch_array($res,SQLITE_ASSOC)) { + if ($columnnum$value) $columnname[$i++]=$key; + $columnnum=count($a); + } + $templine=array(); + foreach ($a as $key=>$value) $templine[$key]=$value; + array_push($resulttable,$templine); + } + + // Create table HTML from the array + $infostr.=""; + for ($i=0;$i<$columnnum;$i++) $infostr.=""; + $infostr.="\n"; + foreach ($resulttable as $templine) { + $infostr.=""; + for ($i=0;$i<$columnnum;$i++) { + $value=(string)$templine[$columnname[$i]]; + if (50'.htmlspecialchars(substr($value,0,50)).".....\n". + '\n"; + $idnum++; + } else $value=htmlspecialchars($value); + switch(requestVar('option')){ + case 'showalltables': + if ($columnname[$i]!='name') break; + $query="SELECT * FROM '$value' LIMIT 10"; + $value=''. + $value.''; + break; + default: + } + $value=preg_replace('/\\n$/','',$value); + $value=str_replace("\n","
\n",$value); + $infostr.="
"; + } + $infostr.="\n"; + $offset++; + } + $infostr.="
".$columnname[$i]."
".$value."
\n"; + switch(requestVar('option')){ + case 'showtable': + $query=requestVar('query'); + $offset=(int)$offset; + $query=preg_replace('/ OFFSET ([0-9]+)$/i','',$query)." OFFSET $offset"; + $res=nucleus_mysql_query($query); + if (!nucleus_mysql_fetch_array($res)) break; + $infostr.=' +
+ + + + + + +
'; + break; + default: + } + break; + default: + } + + echo $p->translated('PHP version: ').phpversion()."
\n"; + if ($res = nucleus_mysql_query('SELECT sqlite_version();')) $ret = nucleus_mysql_fetch_array($res); + if (!$ret) $SQLiteVersion='?.?.?'; + else if (!($SQLiteVersion=$ret[0])) $SQLiteVersion='?.?.?'; + echo $p->translated('SQLite DB version: ').$SQLiteVersion."
\n";; + echo $p->translated('SQLite wrapper version: ').$SQLITECONF['VERSION']."
\n"; + echo $p->translated('SQLite DB file size: ').filesize($SQLITECONF['DBFILENAME'])." bytes
\n"; + echo "
\n"; + +?> + +
translated('Tools'); ?>translated('Execute SQL Query'); ?>
+
+ + + +
+
+ + + +
+
+ + + + +
+getOption('allowsql')) { +?>
+ + + + + + +
+
getOption('allowsql')) echo $p->translated('Query not allowed. To use it, change the plugin option.'); + else { +?>
+ + +
+ +translated('I am sure.'); ?> +
+
+
\n".$infostr; + $pa->end(); +?> \ No newline at end of file diff --git a/sqlite/tags/sqlite0904/nucleus/plugins/sqlite/language/japanese-euc.php b/sqlite/tags/sqlite0904/nucleus/plugins/sqlite/language/japanese-euc.php new file mode 100644 index 0000000..37fab4b --- /dev/null +++ b/sqlite/tags/sqlite0904/nucleus/plugins/sqlite/language/japanese-euc.php @@ -0,0 +1,26 @@ +langArray['Allow SQL query during the management?']='´ÉÍý¤ÎºÝ¡¢SQL ¥¯¥¨¥ê¤ò»ÈÍѤ·¤Þ¤¹¤«¡©'; +$this->langArray['Number of SQL queries at once when DB restore.']='¥Ç¡¼¥¿¥Ù¡¼¥¹Éü¸µ¤ÎºÝ¡¢°ì²ó¤¢¤¿¤ê²¿¸Ä¤Î SQL ¥¯¥¨¥ê¤ò¼Â¹Ô¤·¤Þ¤¹¤«¡©'; +$this->langArray['Wating tile (seconds) when DB restore.']='¥Ç¡¼¥¿¥Ù¡¼¥¹Éü¸µ¤ÎºÝ¡¢Àܳ¤ÎÂÔ¤Á»þ´Ö¤Ï²¿Éäˤ·¤Þ¤¹¤«¡©'; +$this->langArray['NP_SQLite plugin. Filesize of DB is now ']='NP_SQLite ¥×¥é¥°¥¤¥ó. ¸½ºß¤Î¥Ç¡¼¥¿¥Ù¡¼¥¹¥Õ¥¡¥¤¥ë¥µ¥¤¥º¤Ï'; +$this->langArray['SQLite management']='SQLite ´ÉÍý'; +$this->langArray['Pluing was installed sucessfully']='¥×¥é¥°¥¤¥ó¤ÏÀµ¾ï¤Ë¥¤¥ó¥¹¥È¡¼¥ë¤µ¤ì¤Þ¤·¤¿'; +$this->langArray['I am sure.']='³Î¤«¤Ë¼Â¹Ô¤·¤Þ¤¹'; +$this->langArray['Please check the "I am sure." checkbox to execute query']='¥¯¥¨¥ê¤ò¼Â¹Ô¤¹¤ë¤Ë¤Ï"³Î¤«¤Ë¼Â¹Ô¤·¤Þ¤¹"¤ò¥Á¥§¥Ã¥¯¤·¤Æ¤¯¤À¤µ¤¤'; +$this->langArray['Click this to show all']='Á´Ê¸¤òɽ¼¨¤¹¤ë¤Ë¤Ï¥¯¥ê¥Ã¥¯¤·¤Æ¤¯¤À¤µ¤¤'; +$this->langArray['PHP version: ']='PHP ¤Î¥Ð¡¼¥¸¥ç¥ó: '; +$this->langArray['SQLite DB version: ']='SQLite ¥Ç¡¼¥¿¥Ù¡¼¥¹¤Î¥Ð¡¼¥¸¥ç¥ó: '; +$this->langArray['SQLite wrapper version: ']='SQLite ¥é¥Ã¥Ñ¤Î¥Ð¡¼¥¸¥ç¥ó: '; +$this->langArray['SQLite DB file size: ']='¥Ç¡¼¥¿¥Ù¡¼¥¹¤Î¥Õ¥¡¥¤¥ë¥µ¥¤¥º: '; +$this->langArray['Query not allowed. To use it, change the plugin option.']='¥¯¥¨¥ê¡¼¤Ï»È¤¨¤Þ¤»¤ó¡£»ÈÍѤ¹¤ë¤Ë¤Ï¡¢¥×¥é¥°¥¤¥ó¥ª¥×¥·¥ç¥ó¤òÊѹ¹¤·¤Æ¤¯¤À¤µ¤¤¡£'; +$this->langArray['Tools']='¥Ä¡¼¥ë'; +$this->langArray['Execute SQL Query']='SQL ¥¯¥¨¥ê¤Î¼Â¹Ô'; +$this->langArray['VACUUM']='¥Ð¥­¥å¡¼¥à'; +$this->langArray['Integrity Check']='À°¹çÀ­¥Á¥§¥Ã¥¯'; +$this->langArray['Show all tables']='Á´¥Æ¡¼¥Ö¥ë¤Îɽ¼¨'; +$this->langArray['Execute']='¼Â¹Ô'; +$this->langArray['The plugin, ']='¥×¥é¥°¥¤¥ó '; +$this->langArray[' was checked and modified (if modification required)']=' ¤ÎÄ´ºº(ɬÍפʾì¹ç¤Ï¤½¤ÎÊѹ¹)¤¬´°Î»¤·¤Þ¤·¤¿¡£'; +$this->langArray['Please modify the PHP files']='¼¡¤Î¤è¤¦¤Ë PHP ¥Õ¥¡¥¤¥ë¤òÊѹ¹¤·¤Æ¤¯¤À¤µ¤¤'; +$this->langArray['Check plugin']='¥×¥é¥°¥¤¥ó¤Î¥Á¥§¥Ã¥¯'; +?> \ No newline at end of file diff --git a/sqlite/tags/sqlite0904/nucleus/plugins/sqlite/language/japanese-utf8.php b/sqlite/tags/sqlite0904/nucleus/plugins/sqlite/language/japanese-utf8.php new file mode 100644 index 0000000..0d76dfb --- /dev/null +++ b/sqlite/tags/sqlite0904/nucleus/plugins/sqlite/language/japanese-utf8.php @@ -0,0 +1,26 @@ +langArray['Allow SQL query during the management?']='管理の際、SQL クエリを使用しますか?'; +$this->langArray['Number of SQL queries at once when DB restore.']='データベース復元の際、一回あたり何個の SQL クエリを実行しますか?'; +$this->langArray['Wating tile (seconds) when DB restore.']='データベース復元の際、接続の待ち時間は何秒にしますか?'; +$this->langArray['NP_SQLite plugin. Filesize of DB is now ']='NP_SQLite プラグイン. 現在のデータベースファイルサイズは'; +$this->langArray['SQLite management']='SQLite 管理'; +$this->langArray['Pluing was installed sucessfully']='プラグインは正常にインストールされました'; +$this->langArray['I am sure.']='確かに実行します'; +$this->langArray['Please check the "I am sure." checkbox to execute query']='クエリを実行するには"確かに実行します"をチェックしてください'; +$this->langArray['Click this to show all']='全文を表示するにはクリックしてください'; +$this->langArray['PHP version: ']='PHP のバージョン: '; +$this->langArray['SQLite DB version: ']='SQLite データベースのバージョン: '; +$this->langArray['SQLite wrapper version: ']='SQLite ラッパのバージョン: '; +$this->langArray['SQLite DB file size: ']='データベースのファイルサイズ: '; +$this->langArray['Query not allowed. To use it, change the plugin option.']='クエリーは使えません。使用するには、プラグインオプションを変更してください。'; +$this->langArray['Tools']='ツール'; +$this->langArray['Execute SQL Query']='SQL クエリの実行'; +$this->langArray['VACUUM']='バキューム'; +$this->langArray['Integrity Check']='整合性チェック'; +$this->langArray['Show all tables']='全テーブルの表示'; +$this->langArray['Execute']='実行'; +$this->langArray['The plugin, ']='プラグイン '; +$this->langArray[' was checked and modified (if modification required)']=' の調査(必要な場合はその変更)が完了しました。'; +$this->langArray['Please modify the PHP files']='次のように PHP ファイルを変更してください'; +$this->langArray['Check plugin']='プラグインのチェック'; +?> \ No newline at end of file diff --git a/sqlite/tags/sqlite0904/nucleus/plugins/sqlite/restore.php b/sqlite/tags/sqlite0904/nucleus/plugins/sqlite/restore.php new file mode 100644 index 0000000..8bc07ae --- /dev/null +++ b/sqlite/tags/sqlite0904/nucleus/plugins/sqlite/restore.php @@ -0,0 +1,120 @@ +".htmlspecialchars(substr($query,0,200)).".....
\n"; + else $err=true; + } +} +nucleus_mysql_close(); + +//Set 'dbtotal' +$dbtotal=$dbpoint; +while (@is_string(($dbarray[$dbtotal]))) $dbtotal++; + +if ($dbtotal==$dbpoint) { // All done. + unlink('./nucleus/sqlite/'.$dbfile); + if (@include('./nucleus/language/japanese-utf8.php')) $lng='UTF-8'; + else if (@include('./nucleus/language/japanese-euc.php')) $lng='EUC-JP'; + else $lng=''; + echo "Restore Complete\n"; + if ($lng) echo "\n"; + echo "\n"; + if ($lng) { + echo '

'._RESTORE_COMPLETE.'

'; + echo '

'._BACKTOMANAGE.'

'; + } else { + echo '

Restore Complete

'; + echo '

Back to Nucleus management

'; + } + echo "\n"; + exit; +} + +$f=(int)((float)100*$dbpoint/$dbtotal); +$ret="$f % done.
\n".$ret; + +if (isset($_GET['numatonce'])) $numatonce=$_GET['numatonce']; +else $numatonce=20; +$url="?dbfile=$dbfile&numatonce=$numatonce&refreshwait=$refreshwait&dbpoint=$dbpoint"; +if ($err) $refresh=''; +else $refresh=""; + +?> +Creating database file + + +Continue
+ \ No newline at end of file diff --git a/sqlite/tags/sqlite0904/nucleus/sqlite/.htaccess b/sqlite/tags/sqlite0904/nucleus/sqlite/.htaccess new file mode 100644 index 0000000..ff2beb8 --- /dev/null +++ b/sqlite/tags/sqlite0904/nucleus/sqlite/.htaccess @@ -0,0 +1,2 @@ +order deny,allow +deny from all diff --git a/sqlite/tags/sqlite0904/nucleus/sqlite/convert.php b/sqlite/tags/sqlite0904/nucleus/sqlite/convert.php new file mode 100644 index 0000000..a1c7d9e --- /dev/null +++ b/sqlite/tags/sqlite0904/nucleus/sqlite/convert.php @@ -0,0 +1,151 @@ + nucleus_mysql_xxx converter * +* for Nucleus * +* ver 0.8.5 Written by Katsumi * +*******************************************/ + +// The license of this script is GPL + +function modifyConfigInstall(){ + // Modify config.php + $pattern=array(); + $replace=array(); + array_push($pattern,'/^([\s\S]*?)include([^\(]*?)\(([\s\S]*?)\$([\s\S]+)\'globalfunctions.php\'([\s\S]*?)$/'); + array_push($replace,'$1include$2($3\$DIR_NUCLEUS.\'sqlite/sqlite.php\'$5'.'$1include$2($3\$$4\'globalfunctions.php\'$5'); + if (file_exists('./config.php')) { + $before=read_from_file('./config.php'); + if (strpos($before,'sqlite.php')===false) { + $before=file('./config.php'); + $after=''; + foreach($before as $line) $after.=preg_replace($pattern,$replace,$line); + if (!write_to_file(realpath('./config.php'),$after)) ExitWithError(); + } + } + + // Modify install.php + if (file_exists('./install.php')) { + $before=read_from_file('./install.php'); + if (strpos($before,'sqlite.php')===false) { + + // The same pattern/replce is also used for install.php + array_push($pattern,'/aConfPlugsToInstall([\s\S]+)\'NP_SkinFiles\'/i'); + array_push($replace,'aConfPlugsToInstall$1\'NP_SkinFiles\',\'NP_SQLite\''); + array_push($pattern,'/]+name="mySQL_host"([^\/]+)\/>/i'); + array_push($replace,'Not needed for SQLite'); + array_push($pattern,'/]+name="mySQL_user"([^\/]+)\/>/i'); + array_push($replace,'Not needed for SQLite'); + array_push($pattern,'/]+name="mySQL_password"([^\/]+)\/>/i'); + array_push($replace,'Not needed for SQLite'); + array_push($pattern,'/]+name="mySQL_database"([^\/]+)\/>/i'); + array_push($replace,'Not needed for SQLite'); + array_push($pattern,'/]+name="mySQL_create"([^\)]+)<\/label>/i'); + array_push($replace,'Database will be created if not exist.'); + $before=file('./install.php'); + $after=''; + foreach($before as $line) $after.=preg_replace($pattern,$replace,$line); + if (!write_to_file(realpath('./install.php'),$after)) ExitWithError(); + } + } + + // Modify backup.php + if (!modifyBackup('./nucleus/libs/backup.php')) // less than version 3.3 + modifyBackup('./nucleus/plugins/backup/NP_BackupAdmin.php','class'); // more than version 3.4 (??) + + // Modify install.sql + if (file_exists('./install.sql')) { + $before=file('./install.sql'); + $pluginoptiontable=false; + $after=''; + foreach($before as $line){ + if ($pluginoptiontable) { + if (preg_match('/TYPE\=MyISAM;/i',$line)) $pluginoptiontable=false; + else if (preg_match('/`oid`[\s]+int\(11\)[\s]+NOT[\s]+NULL[\s]+auto_increment/i',$line)) + $line=preg_replace('/[\s]+auto_increment/i'," default '0'",$line); + } else { + if (preg_match('/CREATE[\s]+TABLE[\s]+`nucleus_plugin_option`/i',$line)) $pluginoptiontable=true; + } + if (strlen($after)==0) { + $replace='PRAGMA synchronous = off;'; + if (!strstr($line,$replace)) $after=preg_replace('/^[^\r\n]*([\r\n]*)$/',$replace.'$1$1',$line); + } + $after.=$line; + } + if ($after!=$before) { + if (!write_to_file(realpath('./install.sql'),$after)) ExitWithError(); + } + } +} + +function modifyBackup($file,$type='global'){ + if (!file_exists($file)) return false; + $before=read_from_file($file); + if (strpos($before,'sqlite_restore_execute_queries')===false) { + $pattern='/_execute_queries[\s]*\(([^\)]+)\)[\s]*;/i'; + if ($type=='class') $pattern='/\$this->_execute_queries[\s]*\(([^\)]+)\)[\s]*;/i'; + $replace='sqlite_restore_execute_queries($1);'; + $after=preg_replace($pattern,$replace,$before); + if (!write_to_file(realpath($file),$after)) ExitWithError(); + } + return true; +} + +function seekPhpFiles($dir,&$phpfiles,$myself){ + if (!is_dir($dir)) return; + $d = dir($dir); + $dirpath=realpath($d->path); + $dirs=array(); + if (substr($dirpath,-1)!='/' && substr($dirpath,-1)!="\\") $dirpath.='/'; + while (false !== ($entry = $d->read())) { + if ($entry=='.' || $entry=='..') continue; + if (is_file($dirpath.$entry) && substr($entry,-4)=='.php' && $entry!==$myself) array_push($phpfiles,realpath($dirpath.$entry)); + if (is_dir($dirpath.$entry) && $entry!='language' && $entry!='sqlite' ) array_push($dirs,realpath($dirpath.$entry)); + } + $d->close(); + foreach($dirs as $dir) seekPhpFiles($dir,$phpfiles,$myself); +} +function changeFunctions($file){ + if (!is_file($file=realpath($file))) return false; + if (!is_readable($file)) { + echo "Cannot read: $file
\n"; + return false; + } + $before=read_from_file($file); + $after=do_replace($before); + if ($before!=$after) return write_to_file($file,$after); + return true; +} +function do_replace(&$text) { + // Do this process until change does not occur any more... + // Otherwise, sometime file is not completely modified. + // This is indeed the case for BLOG.php. + $after=$text; + do $after=preg_replace('/([^_])mysql_([_a-z]+)([\s]*?)\(/','$1nucleus_mysql_$2(',($before=$after)); + while ($before!=$after); + return $after; +} +function read_from_file($file) { + if (function_exists('file_get_contents') ) $ret=file_get_contents($file); + else { + ob_start(); + readfile($file); + $ret=ob_get_contents(); + ob_end_clean(); + } + return $ret; +} +function write_to_file($file,&$text){ + if (!$handle = @fopen($file, 'w')) { + echo "Cannot change: $file
\n"; + return false; + } + fwrite($handle,$text); + fclose($handle); + echo "Changed: $file
\n"; + return true; +} +function ExitWithError($text='Error occured.') { + echo "$text"; + exit; +} +?> \ No newline at end of file diff --git a/sqlite/tags/sqlite0904/nucleus/sqlite/index.html b/sqlite/tags/sqlite0904/nucleus/sqlite/index.html new file mode 100644 index 0000000..42682b4 --- /dev/null +++ b/sqlite/tags/sqlite0904/nucleus/sqlite/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/sqlite/tags/sqlite0904/nucleus/sqlite/note.txt b/sqlite/tags/sqlite0904/nucleus/sqlite/note.txt new file mode 100644 index 0000000..1517224 --- /dev/null +++ b/sqlite/tags/sqlite0904/nucleus/sqlite/note.txt @@ -0,0 +1,86 @@ + + The licence of this script is GPL + + ACKOWLEDGMENT + + I thank all the people of Nucleus JP forum + who discussed this project. Especially, I + thank kosugiatkips, mekyo, and nakahara21 + for ideas of some part of code. + I also thank Jon Jensen for his generous + acceptance for using his PHP code in the + earlier version of this library. + + The features that are supported by this library but not + generally by SQLite are as follows: + + CREATE TABLE IF NOT EXISTS, auto_increment, + DROP TABLE IF EXISTS, ALTER TABLE, + RENAME TABLE, DESC, + INSERT INTO ... SET xx=xx, xx=xx, + REPLACE INTO ... SET xx=xx, xx=xx, + SHOW KEYS FROM, SHOW INDEX FROM, + SHOW FIELDS FROM, SHOW COLUMNS FROM, + CREATE TABLE ... KEYS xxx (xxx,xxx) + SHOW TABLES LIKE, TRUNCATE TABLE + SHOW TABLES + + + Following functions are available in SQL query. + + CONCAT, IF, IFNULL, NULLIF, SUBSTRING, + match() against(), + replace, UNIX_TIMESTAMP, REGEXP, DAYOFMONTH, MONTH, YEAR, + ADDDATE, DATE_ADD, SUBDATE, DATE_SUB, FIND_IN_SET, + CURDATE, CURRENT_DATE, CURTIME, CURRENT_TIME, CURRENT_TIMESTAMP, + LOCALTIME, LOCALTIMESTAMP, SYSDATE, DATE_FORMAT, TIME_FORMAT, + DAYNAME, DAYOFWEEK, DAYOFYEAR, EXTRACT, FROM_DAYS, FROM_UNIXTIME, + HOUR, MINUTE, MONTH, MONTHNAME, PERIOD_ADD, PERIOD_DIFF, QUARTER, + SECOND, SEC_TO_TIME, SECOND, WEEK, WEEKDAY, YEAR, YEARWEEK, + FORMAT, INET_ATON, INET_NTOA, MD5, + ACOS, ASIN, ATAN, CEIL, CEILING, COS, COT, CRC32, DEGREES, + EXP, FLOOR, GREATEST, MAX, LEAST, MIN, ln, log, log2, log10, + MOD, PI, POW, POWER, RADIANS, RAND, SIGN, SIN, SQRT, TAN, + ASCII, BIN, BIT_LENGTH, CHAR, CHAR_LENGTH, CONCAT_WS, + CONV, ELT, EXPORT_SET, FIELD, HEX, INSERT, LOCATE, + INSTR, LCASE, LOWER, LEFT, LENGTH, OCTET_LENGTH, + LOAD_FILE, LPAD, LTRIM, MAKE_SET, MID, SUBSTRING, + OCT, ORD, QUOTE, REPEAT, REVERSE, RIGHT, RPAD, + RTRIM, SOUNDEX, SPACE, SUBSTRING_INDEX, TRIM, + UCASE, UPPER, + + + Release note: + Version 0.8.0 + -This is the first established version and + exactly the same as ver 0.7.8b. + + Version 0.8.1 + -Execute "PRAGMA short_column_names=1" first. + -Avoid executing outside php file in some very specfic environment. + -Avoid executing multiple queries using ";" as delimer. + -Add check routine for the installed SQLite + + Version 0.8.5 + -Use SQLite_Functions class + -'PRAGMA synchronous = off;' when installing + + Version 0.8.5.5 + - ALTER TABLE syntaxes updated, bugs fixed + + Version 0.8.6.0 + - ALTER TABLE almost completery re-written + - DESC 'table' 'field' supported + - The function 'php' is unregestered from SQL query. + + Version 0.9.0.1 + - Support RENAME TABLE + - Some tunings are done to improve the speed. + + Version 0.9.0.2 + - Debug of CREATE TABLE routine. + - NP_SQLite: trim the query when 'Copy' is used. + + Version 0.9.0.4 + - Debug of REGEX function + - Add mysql_server_info() and mysql_client_info() functions. diff --git a/sqlite/tags/sqlite0904/nucleus/sqlite/sqlite.php b/sqlite/tags/sqlite0904/nucleus/sqlite/sqlite.php new file mode 100644 index 0000000..271bdb9 --- /dev/null +++ b/sqlite/tags/sqlite0904/nucleus/sqlite/sqlite.php @@ -0,0 +1,567 @@ +$btrace) { + if (!($templine=$btrace['line'])) continue; + if (!($tempfile=$btrace['file'])) continue; + $file=str_replace('\\','/',$file); + if (!$line && !$file && strpos($tempfile,'/sqlite.php')===false && strpos($tempfile,'/sqlitequeryfunctions.php')===false) { + $line=$templine; + $file=$tempfile; + } + echo "\n\n"; + } + echo "Warning from SQLite-MySQL wrapper: $text
\n"; + if ($line && $file) echo "in $file on line $line
\n"; + echo $more; + return false; +} +function sqlite_DebugMessage($text=''){ + global $SQLITECONF; + if (!$SQLITECONF['DEBUGREPORT']) return; + if ($text) $SQLITECONF['DEBUGMESSAGE'].="\n".$text."\n"; + if (headers_sent()) { + echo ''; + unset($SQLITECONF['DEBUGMESSAGE']); + } +} + +// nucleus_mysql_XXXX() functions follow. + +function nucleus_mysql_connect($p1=null,$p2=null,$p3=null,$p4=null,$p5=null){ + // All prameters are ignored. + global $SQLITE_DBHANDLE,$SQLITECONF; + if (!$SQLITE_DBHANDLE) $SQLITE_DBHANDLE=sqlite_open($SQLITECONF['DBFILENAME']); + // Initialization queries. + foreach($SQLITECONF['INITIALIZE'] as $value) nucleus_mysql_query($value); + // Unregister the function 'php' in sql query. + sqlite_create_function($SQLITE_DBHANDLE,'php','pi'); + return $SQLITE_DBHANDLE; +} + +function nucleus_mysql_close($p1=null){ + global $SQLITE_DBHANDLE; + if (!($dbhandle=$p1)) $dbhandle=$SQLITE_DBHANDLE; + $SQLITE_DBHANDLE=''; + return sqlite_close ($dbhandle); +} + +function nucleus_mysql_select_db($p1,$p2=null){ + // SQLite does not support multiple databases in a file. + // So this function do nothing and always returns true. + // Note: mysql_select_db() function returns true/false, + // not link-ID. + return true; +} + +function nucleus_mysql_query($p1,$p2=null,$unbuffered=false){//echo htmlspecialchars($p1)."
\n"; + global $SQLITE_DBHANDLE,$SQLITECONF; + if (!($dbhandle=$p2)) $dbhandle=$SQLITE_DBHANDLE; + $query=trim($p1); + if (strpos($query,"\xEF\xBB\xBF")===0) $query=substr($query,3);// UTF-8 stuff + if (substr($query,-1)==';') $query=substr($query,0,strlen($query)-1); + + // Escape style is changed from MySQL type to SQLite type here. + // This is important to avoid possible SQL-injection. + $strpositions=array();// contains the data show where the strings are (startposition => endposition) + if (strpos($query,'`')!==false || strpos($query,'"')!==false || strpos($query,"'")!==false) + $strpositions=sqlite_changeQuote($query); + //echo "
".htmlspecialchars($p1)."

\n".htmlspecialchars($query)."
\n"; + + // Debug mode + if ($SQLITECONF['DEBUGMODE']) $query=sqlite_mysql_query_debug($query); + + // Anyway try it. + if ($unbuffered) { + if ($ret=@sqlite_unbuffered_query($dbhandle,$query)) return $ret; + } else { + if ($ret=@sqlite_query($dbhandle,$query)) return $ret; + } + + // Error occured. Query must be translated. + return sqlite_mysql_query_sub($dbhandle,$query,$strpositions,$p1,$unbuffered); +} +function sqlite_mysql_query_sub($dbhandle,$query,$strpositions=array(),$p1=null,$unbuffered=false){//echo htmlspecialchars($p1)."
\n"; + // Query translation is needed, especially when changing the data in database. + // So far, this routine is written for 'CREATE TABLE','DROP TABLE', 'INSERT INTO', + // 'SHOW TABLES LIKE', 'SHOW KEYS FROM', 'SHOW INDEX FROM' + // and several functions used in query. + // How about 'UPDATE' ??? + global $SQLITE_DBHANDLE,$SQLITECONF; + $beforetrans=time()+microtime(); + if (!$p1) $p1=$query; + $morequeries=array(); + $temptable=false; + $uquery=strtoupper($query); + if (strpos($uquery,'CREATE TABLE')===0 || ($temptable=(strpos($uquery,'CREATE TEMPORARY TABLE')===0))) { + if (!($i=strpos($query,'('))) return sqlite_ReturnWithError('nucleus_mysql_query: '.$p1); + //check if the command is 'CREATE TABLE IF NOT EXISTS' + if (strpos(strtoupper($uquery),'CREATE TABLE IF NOT EXISTS')===0) { + $tablename=trim(substr($query,26,$i-26)); + if (substr($tablename,0,1)!="'") $tablename="'$tablename'"; + $res=sqlite_query($dbhandle,"SELECT tbl_name FROM sqlite_master WHERE tbl_name=$tablename LIMIT 1"); + if (nucleus_mysql_num_rows($res)) return true; + } else { + $tablename=trim(substr($query,12,$i-12)); + if (substr($tablename,0,1)!="'") $tablename="'$tablename'"; + } + $query=trim(substr($query,$i+1)); + for ($i=strlen($query);0<$i;$i--) if ($query[$i]==')') break; + $query=substr($query,0,$i); + $commands=_sqlite_divideByChar(',',$query); + require_once(dirname(__FILE__) . '/sqlitealtertable.php'); + $query=sqlite_createtable_query($commands,$tablename,$temptable,$morequeries); + } else if (strpos($uquery,'DROP TABLE IF EXISTS')===0) { + if (!($i=strpos($query,';'))) $i=strlen($query); + $tablename=trim(substr($query,20,$i-20)); + if (substr($tablename,0,1)!="'") $tablename="'$tablename'"; + $res=sqlite_query($dbhandle,"SELECT tbl_name FROM sqlite_master WHERE tbl_name=$tablename LIMIT 1"); + if (!nucleus_mysql_num_rows($res)) return true; + $query='DROP TABLE '.$tablename; + } else if (strpos($uquery,'ALTER TABLE ')===0) { + $query=trim(substr($query,11)); + if ($i=strpos($query,' ')) { + $tablename=trim(substr($query,0,$i)); + $query=trim(substr($query,$i)); + require_once(dirname(__FILE__) . '/sqlitealtertable.php'); + $ret =sqlite_altertable($tablename,$query,$dbhandle); + if (!$ret) sqlite_ReturnWithError('SQL error',"
".nucleus_mysql_error()."
".htmlspecialchars($p1)."

\n".htmlspecialchars("ALTER TABLE $tablename $query")."
\n"); + return $ret; + } + // Else, syntax error + } else if (strpos($uquery,'RENAME TABLE ')===0) { + require_once(dirname(__FILE__) . '/sqlitealtertable.php'); + return sqlite_renametable(_sqlite_divideByChar(',',substr($query,13)),$dbhandle); + } else if (strpos($uquery,'INSERT INTO ')===0 || strpos($uquery,'REPLACE INTO ')===0 || + strpos($uquery,'INSERT IGNORE INTO ')===0 || strpos($uquery,'REPLACE IGNORE INTO ')===0) { + $buff=str_replace(' IGNORE ',' OR IGNORE ',substr($uquery,0,($i=strpos($uquery,' INTO ')+6))); + $query=trim(substr($query,$i)); + if ($i=strpos($query,' ')) { + $buff.=trim(substr($query,0,$i+1)); + $query=trim(substr($query,$i)); + } + if ($i=strpos($query,' ')) { + if (strpos(strtoupper($query),'SET')===0) { + $query=trim(substr($query,3)); + $commands=_sqlite_divideByChar(',',$query); + $query=' VALUES('; + $buff.=' ('; + foreach($commands as $key=>$value){ + //echo "[".htmlspecialchars($value)."]"; + if (0<$key) { + $buff.=', '; + $query.=', '; + } + if ($i=strpos($value,'=')) { + $buff.=trim(substr($value,0,$i)); + $query.=substr($value,$i+1); + } + } + $buff.=')'; + $query.=')'; + } else { + $beforevalues=''; + $commands=_sqlite_divideByChar(',',$query); + $query=''; + foreach($commands as $key=>$value){ + if ($beforevalues=='' && preg_match('/^(.*)\)\s+VALUES\s+\(/i',$value,$matches)) { + $beforevalues=$buff.' '.$query.$matches[1].')'; + } + if (0<$key) $query.=$beforevalues.' VALUES ';// supports multiple insertion + $query.=$value.';'; + } + } + } + $query=$buff.' '.$query; + } else if (strpos($uquery,'SHOW TABLES LIKE ')===0) { + $query='SELECT name FROM sqlite_master WHERE type=\'table\' AND name LIKE '.substr($query,17); + } else if (strpos($uquery,'SHOW TABLES')===0) { + $query='SELECT name FROM sqlite_master WHERE type=\'table\''; + } else if (strpos($uquery,'SHOW KEYS FROM ')===0) { + require_once(dirname(__FILE__) . '/sqlitealtertable.php'); + $query=sqlite_showKeysFrom(trim(substr($query,15)),$dbhandle); + } else if (strpos($uquery,'SHOW INDEX FROM ')===0) { + require_once(dirname(__FILE__) . '/sqlitealtertable.php'); + $query=sqlite_showKeysFrom(trim(substr($query,16)),$dbhandle); + } else if (strpos($uquery,'SHOW FIELDS FROM ')===0) { + require_once(dirname(__FILE__) . '/sqlitealtertable.php'); + $query=sqlite_showFieldsFrom(trim(substr($query,17)),$dbhandle); + } else if (strpos($uquery,'SHOW COLUMNS FROM ')===0) { + require_once(dirname(__FILE__) . '/sqlitealtertable.php'); + $query=sqlite_showFieldsFrom(trim(substr($query,18)),$dbhandle); + } else if (strpos($uquery,'TRUNCATE TABLE ')===0) { + $query='DELETE FROM '.substr($query,15); + } else if (preg_match('/^DESC \'([^\']+)\' \'([^\']+)\'$/',$query,$m)) { + return nucleus_mysql_query("SHOW FIELDS FROM '$m[1]' LIKE '$m[2]'"); + } else if (preg_match('/^DESC ([^\s]+) ([^\s]+)$/',$query,$m)) { + return nucleus_mysql_query("SHOW FIELDS FROM '$m[1]' LIKE '$m[2]'"); + } else SQLite_Functions::sqlite_modifyQueryForUserFunc($query,$strpositions); + + //Throw query again. + $aftertrans=time()+microtime(); + if ($unbuffered) { + $ret=sqlite_unbuffered_query($dbhandle,$query); + } else { + $ret=sqlite_query($dbhandle,$query); + } + + $afterquery=time()+microtime(); + if ($SQLITECONF['MEASURESPEED']) sqlite_DebugMessage("translated query:$query\n". + 'translation: '.($aftertrans-$beforetrans).'sec, query: '.($afterquery-$aftertrans).'sec'); + if (!$ret) sqlite_ReturnWithError('SQL error',"
".nucleus_mysql_error()."
".htmlspecialchars($p1)."

\n".htmlspecialchars($query)."
\n"); + foreach ($morequeries as $value) if ($value) @sqlite_query($dbhandle,$value); + return $ret; +} +function sqlite_changeQuote(&$query){ + // This function is most important. + // When you modify this function, do it very carefully. + // Otherwise, you may allow crackers to do SQL-injection. + // This function returns array that shows where the strings are. + $sarray=array(); + $ret=''; + $qlen=strlen($query); + for ($i=0;$i<$qlen;$i++) { + // Go to next quote + if (($i1=strpos($query,'"',$i))===false) $i1=$qlen; + if (($i2=strpos($query,"'",$i))===false) $i2=$qlen; + if (($i3=strpos($query,'`',$i))===false) $i3=$qlen; + if ($i1==$qlen && $i2==$qlen && $i3==$qlen) { + $temp=preg_replace('/[\s]+/',' ',substr($query,$i)); // Change all spacying to ' '. + $ret.=($temp); + if (strstr($temp,';')) exit('Warning: try to use more than two queries?'); + break; + } + if ($i2<($j=$i1)) $j=$i2; + if ($i3<$j) $j=$i3; + $temp=preg_replace('/[\s]+/',' ',substr($query,$i,$j-$i)); // Change all spacying to ' '. + $ret.=($temp); + $c=$query[($i=$j)]; // $c keeps the type of quote. + if (strstr($temp,';')) exit('Warning: try to use more than two queries?'); + + // Check between quotes. + // $j shows the begging positioin. + // $i will show the ending position. + $j=(++$i); + while ($i<$qlen) { + if (($i1=strpos($query,$c,$i))===false) $i1=$qlen; + if (($i2=strpos($query,"\\",$i))===false) $i2=$qlen; + if ($i2<$i1) { + // \something. Skip two characters. + $i=$i2+2; + continue; + } if ($i1<($qlen-1) && $query[$i1+1]==$c) { + // "", '' or ``. Skip two characters. + $i=$i1+2; + continue; + } else {// OK. Reached the end position + $i=$i1; + break; + } + } + $i1=strlen($ret); + $ret.="'".sqlite_changeslashes(substr($query,$j,$i-$j)); + if ($i<$qlen) $ret.="'"; //else Syntax error in query. + $i2=strlen($ret); + $sarray[$i1]=$i2; + }//echo htmlspecialchars($query).'
'.htmlspecialchars($ret).'
'; + $query=$ret; + return $sarray; +} +function sqlite_changeslashes(&$text){ + // By SQLite, "''" is used in the quoted string instead of "\'". + // In addition, only "'" seems to be allowed for perfect quotation of string. + // This routine is used for the conversion from MySQL type to SQL type. + // Do NOT use stripslashes() but use stripcslashes(). Otherwise, "\r\n" is not converted. + if ($text==='') return ''; + return (sqlite_escape_string (stripcslashes((string)$text))); +} +function _sqlite_divideByChar($char,$query,$limit=-1){ + if (!is_array($char)) $char=array($char); + $ret=array(); + $query=trim($query); + $buff=''; + while (strlen($query)){ + $i=strlen($query); + foreach($char as $value){ + if (($j=strpos($query,$value))!==false) { + if ($j<$i) $i=$j; + } + } + if (($j=strpos($query,'('))===false) $j=strlen($query); + if (($k=strpos($query,"'"))===false) $k=strlen($query); + if ($i<$j && $i<$k) {// ',' found + $buff.=substr($query,0,$i); + if (strlen($buff)) $ret[]=$buff; + $query=trim(substr($query,$i+1)); + $buff=''; + $limit--; + if ($limit==0) exit; + } else if ($j<$i && $j<$k) {// '(' found + if (($i=strpos($query,')',$j))===false) { + $buff.=$query; + if (strlen($buff)) $ret[]=$buff; + $query=$buff=''; + } else { + $buff.=substr($query,0,$i+1); + $query=substr($query,$i+1); + } + } else if ($k<$i && $k<$j) {// "'" found + if (($i=strpos($query,"'",$k+1))===false) { + $buff.=$query; + if (strlen($buff)) $ret[]=$buff; + $query=$buff=''; + } else { + $buff.=substr($query,0,$i+1); + $query=substr($query,$i+1); + } + } else {// last column + $buff.=$query; + if (strlen($buff)) $ret[]=$buff; + $query=$buff=''; + } + } + if (strlen($buff)) $ret[]=$buff; + return $ret; +} +function sqlite_mysql_query_debug(&$query){ + // There is nothing to do here in this version. + return $query; +} + +function nucleus_mysql_list_tables($p1=null,$p2=null) { + global $SQLITE_DBHANDLE,$MYSQL_DATABASE; + return sqlite_query($SQLITE_DBHANDLE,"SELECT name as Tables_in_$MYSQL_DATABASE FROM sqlite_master WHERE type='table'"); +} +function nucleus_mysql_listtables($p1=null,$p2=null) { return nucleus_mysql_list_tables($p1,$p2);} + +function nucleus_mysql_affected_rows($p1=null){ + global $SQLITE_DBHANDLE; + if (!($dbhandle=$p1)) $dbhandle=$SQLITE_DBHANDLE; + return sqlite_changes($dbhandle); +} + +function nucleus_mysql_error($p1=null){ + global $SQLITE_DBHANDLE; + if (!($dbhandle=$p1)) $dbhandle=$SQLITE_DBHANDLE; + return sqlite_error_string ( sqlite_last_error ($dbhandle) ); +} + +function nucleus_mysql_fetch_array($p1,$p2=SQLITE_BOTH){ + return sqlite_fetch_array ($p1,$p2); +} + +function nucleus_mysql_fetch_assoc($p1){ + return sqlite_fetch_array($p1,SQLITE_ASSOC); +} + +function nucleus_mysql_fetch_object($p1,$p2=SQLITE_BOTH){ + if (is_array($ret=sqlite_fetch_array ($p1,$p2))) { + $o=new SQLITE_OBJECT; + foreach ($ret as $key=>$value) { + if (strstr($key,'.')) {// Remove table name. + $key=preg_replace('/^(.+)\."(.+)"$/','"$2"',$key); + $key=preg_replace('/^(.+)\.([^.^"]+)$/','$2',$key); + } + $o->$key=$value; + } + return $o; + } else return false; +} + +function nucleus_mysql_fetch_row($p1){ + return sqlite_fetch_array($p1,SQLITE_NUM); +} + +function nucleus_mysql_field_name($p1,$p2){ + return sqlite_field_name ($p1,$p2); +} + +function nucleus_mysql_free_result($p1){ + // ???? Cannot find corresponding function of SQLite. + // Maybe SQLite is NOT used for the high spec server + // that need mysql_free_result() function because of + // many SQL-queries in a script. + return true; +} + +function nucleus_mysql_insert_id($p1=null){ + global $SQLITE_DBHANDLE; + if (!($dbhandle=$p1)) $dbhandle=$SQLITE_DBHANDLE; + return sqlite_last_insert_rowid ($dbhandle); +} + +function nucleus_mysql_num_fields($p1){ + return sqlite_num_fields ($p1); +} + +function nucleus_mysql_num_rows($p1){ + return sqlite_num_rows ($p1); +} +function nucleus_mysql_numrows($p1){ + return sqlite_num_rows ($p1); +} + +function nucleus_mysql_result($p1,$p2,$p3=null){ + if ($p3) return sqlite_ReturnWithError('nucleus_mysql_result'); + if (!$p2) return sqlite_fetch_single ($p1); + $a=sqlite_fetch_array ($p1); + return $a[$p2]; +} + +function nucleus_mysql_unbuffered_query($p1,$p2=null){ + return nucleus_mysql_query($p1,$p2,true); +} + +function nucleus_mysql_client_encoding($p1=null){ + return sqlite_libencoding(); +} + +function nucleus_mysql_data_seek($p1,$p2) { + return sqlite_seek($p1,$p2); +} + +function nucleus_mysql_errno ($p1=null){ + global $SQLITE_DBHANDLE; + if (!($dbhandle=$p1)) $dbhandle=$SQLITE_DBHANDLE; + return sqlite_last_error($dbhandle); +} + +function nucleus_mysql_escape_string ($p1){ + // The "'" will be changed to "''". + // This way works for both MySQL and SQLite when single quotes are used for string. + // Note that single quote is always used in this wrapper. + // If a plugin is made on SQLite-Nucleus and such plugin will be used for MySQL-Nucleus, + // nucleus_mysql_escape_string() will be changed to mysql_escape_string() and + // this routine won't be used, so this way won't be problem. + return sqlite_escape_string($p1); +} + +function nucleus_mysql_real_escape_string ($p1,$p2=null){ + //addslashes used here. + return addslashes($p1); +} + +function nucleus_mysql_create_db ($p1,$p2=null){ + // All prameters are ignored. + // Returns always true; + return true; +} + +function nucleus_mysql_pconnect($p1=null,$p2=null,$p3=null,$p4=null,$p5=null){ + global $SQLITE_DBHANDLE,$SQLITECONF; + sqlite_close ($SQLITE_DBHANDLE); + $SQLITE_DBHANDLE=sqlite_popen($SQLITECONF['DBFILENAME']); + return ($SQLITE['DBHANDLE']=$SQLITE_DBHANDLE); +} + +function nucleus_mysql_fetch_field($p1,$p2=null){ + if ($p2) return sqlite_ReturnWithError('nucleus_mysql_fetch_field'); + // Only 'name' is supported. + $o=new SQLITE_OBJECT; + $o->name=array(); + if(is_array($ret=sqlite_fetch_array ($p1,SQLITE_ASSOC ))) + foreach ($ret as $key=>$value) { + if (is_string($key)) array_push($o->name,$key); + } + return $o; + +} +function nucleus_mysql_get_client_info(){ + return nucleus_mysql_get_server_info(); +} +function nucleus_mysql_get_server_info(){ + $res=nucleus_mysql_query('SELECT sqlite_version();'); + if (!$res) return '?.?.?'; + $row=nucleus_mysql_fetch_row($res); + if (!$row) return '?.?.?'; + return $row[0]; +} + +// This function is called instead of _execute_queries() in backp.php +function sqlite_restore_execute_queries(&$query){ + global $DIR_NUCLEUS,$DIR_LIBS,$DIR_PLUGINS,$CONF; + + // Skip until the first "#" or "--" + if (($i=strpos($query,"\n#"))===false) $i=strlen($query); + if (($j=strpos($query,"\n--"))===false) $j=strlen($query); + if ($i<$j) $query=substr($query,$i+1); + else $query=substr($query,$j+1); + + // Save the query to temporary file in sqlite directory. + if (function_exists('microtime')) { + $prefix=preg_replace('/[^0-9]/','',microtime()); + } else { + srand(time()); + $prefix=(string)rand(0,999999); + } + $tmpname=tempnam($DIR_NUCLEUS.'sqlite/',"tmp$prefix"); + if (!($handle=@fopen($tmpname,'w'))) return 'Cannot save temporary DB file.'; + fwrite($handle,$query); + fclose($handle); + $tmpname=preg_replace('/[\s\S]*?[\/\\\\]([^\/\\\\]+)$/','$1',$tmpname); + + // Read the option from NP_SQLite + if (!class_exists('NucleusPlugin')) { include($DIR_LIBS.'PLUGIN.php');} + if (!class_exists('NP_SQLite')) { include($DIR_PLUGINS.'NP_SQLite.php'); } + $p=new NP_SQLite(); + if (!($numatonce=@$p->getOption('numatonce'))) $numatonce=20; + if (!($refreshwait=@$p->getOption('refreshwait'))) $refreshwait=1; + + // Start process. + $url="plugins/sqlite/restore.php?dbfile=$tmpname&numatonce=$numatonce&refreshwait=$refreshwait"; + header('HTTP/1.0 301 Moved Permanently'); + header('Location: '.$url); + exit('Moved Permanently'); +} + +?> \ No newline at end of file diff --git a/sqlite/tags/sqlite0904/nucleus/sqlite/sqlitealtertable.php b/sqlite/tags/sqlite0904/nucleus/sqlite/sqlitealtertable.php new file mode 100644 index 0000000..f6cd8dd --- /dev/null +++ b/sqlite/tags/sqlite0904/nucleus/sqlite/sqlitealtertable.php @@ -0,0 +1,391 @@ + $value) { + if (strpos(strtolower($value),'auto_increment')==strlen($value)-14) $auto_increment=true; + $isint=preg_match('/int\(([0-9]*?)\)/i',$value); + $isint=$isint | preg_match('/tinyint\(([0-9]*?)\)/i',$value); + $value=preg_replace('/int\(([0-9]*?)\)[\s]+unsigned/i','int($1)',$value); + $value=preg_replace('/int\([0-9]*?\)[\s]+NOT NULL[\s]+auto_increment$/i',' INTEGER NOT NULL PRIMARY KEY',$value); + $value=preg_replace('/int\([0-9]*?\)[\s]+auto_increment$/i',' INTEGER PRIMARY KEY',$value); + if ($auto_increment) $value=preg_replace('/^PRIMARY KEY(.*?)$/i','',$value); + while (preg_match('/PRIMARY KEY[\s]*\((.*)\([0-9]+\)(.*)\)/i',$value)) // Remove '(100)' from 'PRIMARY KEY (`xxx` (100))' + $value=preg_replace('/PRIMARY KEY[\s]*\((.*)\([0-9]+\)(.*)\)/i','PRIMARY KEY ($1 $2)',$value); + + // CREATE KEY queries for SQLite (corresponds to KEY 'xxxx'('xxxx', ...) of MySQL + if (preg_match('/^FULLTEXT KEY(.*?)$/i',$value,$matches)) { + array_push($morequeries,'CREATE INDEX '.str_replace('('," ON $tablename (",$matches[1])); + $value=''; + } else if (preg_match('/^UNIQUE KEY(.*?)$/i',$value,$matches)) { + array_push($morequeries,'CREATE UNIQUE INDEX '.str_replace('('," ON $tablename (",$matches[1])); + $value=''; + } else if (preg_match('/^KEY(.*?)$/i',$value,$matches)) { + array_push($morequeries,'CREATE INDEX '.str_replace('('," ON $tablename (",$matches[1])); + $value=''; + } + + // Check if 'DEFAULT' is set when 'NOT NULL' + $uvalue=strtoupper($value); + if (strpos($uvalue,'NOT NULL')!==false && + strpos($uvalue,'DEFAULT')===false && + strpos($uvalue,'INTEGER NOT NULL PRIMARY KEY')===false) { + if ($isint) $value.=" DEFAULT 0"; + else $value.=" DEFAULT ''"; + } + + if ($value) { + if ($first) $first=false; + else $query.=','; + $query.=' '.$value; + } + } + $query.=' )'; + return $query; +} + +function sqlite_renametable($commands,$dbhandle){ + $carray=array(); + foreach($commands as $command){ + $command=_sqlite_divideByChar(array(' ',"\t","\r","\n"),$command); + if (count($command)!=3) return sqlite_ReturnWithError(htmlspecialchars("near '$command[0]': syntax error")); + if (strtoupper($command[1])!='TO') return sqlite_ReturnWithError(htmlspecialchars("near '$command[1]': syntax error")); + $carray[str_replace("'",'',$command[0])]=str_replace("'",'',$command[2]); + } + foreach($carray as $old=>$new){ + if (!sqlite_copytable($old,$new,$dbhandle)) return false; + if (!sqlite_query($dbhandle,"DROP TABLE $old")) return sqlite_ReturnWithError(htmlspecialchars("fail to remove table, '$old'")); + } + sqlite_query($dbhandle,'VACUUM'); + return true; +} + +function sqlite_copytable($table,$newname,$dbhandle,$newtablearray=array()){ + // Getting information from original table and create new table + $res = sqlite_query($dbhandle,"SELECT sql,name,type FROM sqlite_master WHERE tbl_name = '".$table."' ORDER BY type DESC"); + if(!sqlite_num_rows($res)) return sqlite_ReturnWithError('no such table: '.$table); + if (count($newtablearray)) { + $query="CREATE TABLE $newname (".implode(',',$newtablearray).')'; + if (!sqlite_query($dbhandle,$query)) return sqlite_ReturnWithError('Table could not be created.'); + } else { + while($row=sqlite_fetch_array($res,SQLITE_ASSOC)){ + if (!preg_match('/^([^\(]*)[\s]([^\(\']+)[\s]*\(([\s\S]*)$/',$row['sql'],$m) && + !preg_match('/^([^\(]*)[\s]\'([^\(]+)\'[\s]*\(([\s\S]*)$/',$row['sql'],$m)) return sqlite_ReturnWithError('unknown error'); + if (!sqlite_query($dbhandle,$m[1]." '$newname' (".$m[3])) return sqlite_ReturnWithError('Table could not be created.'); + } + } + // Copy the items + sqlite_query($dbhandle,'BEGIN'); + $res=sqlite_unbuffered_query($dbhandle,"SELECT * FROM $table"); + while($row=sqlite_fetch_array($res,SQLITE_ASSOC)){ + $keys=$values=array(); + foreach($row as $key=>$value) { + if (count($newtablearray) && !isset($newtablearray[strtolower($key)])) continue; + $keys[]="'$key'"; + $values[]="'".sqlite_escape_string($value)."'"; + } + if (!sqlite_query($dbhandle,"INSERT INTO '$newname'(".implode(', ',$keys).') VALUES ('.implode(', ',$values).')')) { + sqlite_query($dbhandle,'COMMIT'); + return false; + } + } + sqlite_query($dbhandle,'COMMIT'); + $orgnum=sqlite_array_query($dbhandle,"SELECT COUNT(*) FROM $table"); + $newnum=sqlite_array_query($dbhandle,"SELECT COUNT(*) FROM $newname"); + if ($orgnum[0][0]!=$newnum[0][0]) return sqlite_ReturnWithError('Data transfer failed.'); + return true; +} +function sqlite_altertable($table,$alterdefs,$dbhandle){ + // Almost completely re-written in February 2008. + $table=str_replace("'",'',$table); + + // Getting information from original table + $res = sqlite_query($dbhandle,"SELECT sql,name,type FROM sqlite_master WHERE tbl_name = '".$table."' ORDER BY type DESC"); + if(!sqlite_num_rows($res)) return sqlite_ReturnWithError('no such table: '.$table); + $orgindex=array(); + $row=sqlite_fetch_array($res,SQLITE_ASSOC); //table sql + $orgsql=$row['sql']; + while($row=sqlite_fetch_array($res,SQLITE_ASSOC)) $orgindex[strtolower($row['name'])]=$row['sql']; + if (!preg_match('/^[^\(]+\((.*)\);*$/',$orgsql,$m)) return sqlite_ReturnWithError('unknown error'); + $orgtablearray=array(); + foreach(_sqlite_divideByChar(',',$orgtable=$m[1]) as $value){ + if (!preg_match('/^([^\s\']+)[\s]+([\s\S]*)$/',$value,$m) && + !preg_match('/^\'([^\']+)\'[\s]+([\s\S]*)$/',$value,$m)) return sqlite_ReturnWithError('unknown error'); + $orgtablearray[strtolower($m[1])]="'$m[1]' $m[2]"; + } + $desttablearray=$orgtablearray; + $destindex=$orgindex; + + // Convert table + foreach(_sqlite_divideByChar(',',$alterdefs) as $def){ + $def=_sqlite_divideByChar(array(' ',"\t","\r","\n"),trim($def)); + if (($c=count($def))<2) return sqlite_ReturnWithError('near "'.htmlspecialchars($def[0]).'": syntax error'); + // Check if FIRST/AFTER is used. + $first=$after=false; + if (strtoupper($def[$c-1])=='FIRST') { + $first=true; + array_pop($def); + } elseif (strtoupper($def[$c-2])=='AFTER') { + $after=strtolower(str_replace("'",'',array_pop($def))); + array_pop($def); + } + // Ignore CONSTRAINT and COLUMN + $method=strtoupper(array_shift($def)); + switch(strtoupper($def[0])){ + case 'CONSTRAINT': // delete two + array_shift($def); + case 'COLUMN': // delete one + array_shift($def); + default: + break; + } + // The main routine of this function follow. + switch($method){ + case 'MODIFY': + case 'ALTER': + if (error_reporting() & E_NOTICE) sqlite_ReturnWithError('ALTER/MODIFY is not supported'); + break; + case 'DROP': + case 'CHANGE': + if (strtoupper($def[0])=='INDEX') { + // delete index + unset($destindex[strtolower($def[1])]); + } else { + // delete field + unset($desttablearray[strtolower(str_replace("'",'',$def[0]))]); + } + if ($method!='CHANGE') break; + case 'ADD': + $field=array_shift($def); + switch($submedthod=strtoupper($field)){ + case 'UNIQUE': + case 'PRIMARY': + case 'FOREIGN': + case 'INDEX': + case 'FULLTEXT': + // add index + if (strtoupper($index=array_shift($def))=='KEY') $index=array_shift($def); + $def=implode(' ',$def); + $destindex[strtolower(str_replace("'",'',$index))]= + ($submedthod=='UNIQUE'?'CREATE UNIQUE INDEX ':'CREATE INDEX '). + "$index ON '$table' $def"; + break; + default: + // add field + $field=str_replace("'",'',$field); + if ($first) { + $desttablearray=array_merge( + array(strtolower($field)=>"'$field' ".implode(' ',$def)), + $desttablearray); + } elseif($after) { + $temp=$desttablearray; + $desttablearray=array(); + $ok=false; + foreach($temp as $key=>$value) { + $desttablearray[$key]=$value; + if ($ok || $key!=$after) continue; + $ok=true; + $desttablearray[strtolower($field)]="'$field' ".implode(' ',$def); + } + if (!$ok) { + $desttablearray[strtolower($field)]="'$field' ".implode(' ',$def); + if (error_reporting() & E_NOTICE) sqlite_ReturnWithError(htmlspecialchars("Field '$after' not found.")); + } + } else { + $desttablearray[strtolower($field)]="'$field' ".implode(' ',$def); + } + } + break; + default: + return sqlite_ReturnWithError('near "'.htmlspecialchars($method).'": syntax error'); + } + } + + // Create temporary table that has the modified field and copy the items into it. + if (function_exists('microtime')) $tmptable='t'.str_replace(array(' ','.'),'',microtime()); + else $tmptable = 't'.rand(0,999999).time(); + if (!sqlite_copytable($table,$tmptable,$dbhandle,$desttablearray)) return false; + + // New temporary table sccusfully made. + // So, delete the original table and copy back the temporary table to one with original name. + sqlite_query("DROP TABLE $table",$dbhandle); + if (sqlite_copytable($tmptable,$table,$dbhandle)) sqlite_query("DROP TABLE $tmptable",$dbhandle); + + // Add the indexes, finally. + foreach($destindex as $index) sqlite_query($index,$dbhandle); + sqlite_query($dbhandle,'VACUUM'); + return true; +} +function sqlite_showKeysFrom($tname,$dbhandle) { + // This function is for supporing 'SHOW KEYS FROM' and 'SHOW INDEX FROM'. + // For making the same result as obtained by MySQL, temporary table is made. + if (preg_match('/^([^\s]+)\s+LIKE\s+\'([^\']+)\'$/i',$tname,$m)) list($m,$tname,$like)=$m; + $tname=str_replace("'",'',$tname); + + // Create a temporary table for making result + if (function_exists('microtime')) $tmpname='t'.str_replace('.','',str_replace(' ','',microtime())); + else $tmpname = 't'.rand(0,999999).time(); + sqlite_query($dbhandle,"CREATE TEMPORARY TABLE $tmpname ('Table', 'Non_unique', 'Key_name', 'Seq_in_index',". + " 'Column_name', 'Collation', 'Cardinality', 'Sub_part', 'Packed', 'Null', 'Index_type', 'Comment')"); + + // First, get the sql query when the table created + $res=sqlite_query($dbhandle,"SELECT sql FROM sqlite_master WHERE tbl_name = '$tname' ORDER BY type DESC"); + $a=nucleus_mysql_fetch_assoc($res); + $tablesql=$a['sql']; + + // Check if each columns are unique + $notnull=array(); + foreach(_sqlite_divideByChar(',',substr($tablesql,strpos($tablesql,'(')+1)) as $value) { + $name=str_replace("'",'',substr($value,0,strpos($value,' '))); + if (strpos(strtoupper($value),'NOT NULL')!==false) $notnull[$name]=''; + else $notnull[$name]='YES'; + } + + // Get the primary key (and check if it is unique???). + if (preg_match('/[^a-zA-Z_\']([\S]+)[^a-zA-Z_\']+INTEGER NOT NULL PRIMARY KEY/i',$tablesql,$matches)) { + $pkey=str_replace("'",'',$matches[1]); + $pkeynull=''; + } else if (preg_match('/[^a-zA-Z_\']([\S]+)[^a-zA-Z_\']+INTEGER PRIMARY KEY/i',$tablesql,$matches)) { + $pkey=str_replace("'",'',$matches[1]); + $pkeynull='YES'; + } else if (preg_match('/PRIMARY KEY[\s]*?\(([^\)]+)\)/i',$tablesql,$matches)) { + $pkey=null;// PRIMARY KEY ('xxx'[,'xxx']) + foreach(explode(',',$matches[1]) as $key=>$value) { + $value=str_replace("'",'',trim($value)); + $key++; + $cardinality=nucleus_mysql_num_rows(sqlite_query($dbhandle,"SELECT '$value' FROM '$tname'")); + sqlite_query($dbhandle,"INSERT INTO $tmpname ('Table', 'Non_unique', 'Key_name', 'Seq_in_index',". + " 'Column_name', 'Collation', 'Cardinality', 'Sub_part', 'Packed', 'Null', 'Index_type', 'Comment')". + " VALUES ('$tname', '0', 'PRIMARY', '$key',". + " '$value', 'A', '$cardinality', null, null, '', 'BTREE', '')"); + } + } else $pkey=null; + + // Check the index. + $res=sqlite_query($dbhandle,"SELECT sql,name FROM sqlite_master WHERE type = 'index' and tbl_name = '$tname' ORDER BY type DESC"); + while ($a=nucleus_mysql_fetch_assoc($res)) { + if (!($sql=$a['sql'])) {// Primary key + if ($pkey && strpos(strtolower($a['name']),'autoindex')) { + $cardinality=nucleus_mysql_num_rows(sqlite_query($dbhandle,"SELECT $pkey FROM '$tname'")); + sqlite_query($dbhandle,"INSERT INTO $tmpname ('Table', 'Non_unique', 'Key_name', 'Seq_in_index',". + " 'Column_name', 'Collation', 'Cardinality', 'Sub_part', 'Packed', 'Null', 'Index_type', 'Comment')". + " VALUES ('$tname', '0', 'PRIMARY', '1',". + " '$pkey', 'A', '$cardinality', null, null, '$pkeynull', 'BTREE', '')"); + $pkey=null; + } + } else {// Non-primary key + if (($name=str_replace("'",'',$a['name'])) && preg_match('/\(([\s\S]+)\)/',$sql,$matches)) { + if (isset($like) && $name!=$like) continue; + foreach(explode(',',$matches[1]) as $key=>$value) { + $columnname=str_replace("'",'',$value); + if (strpos(strtoupper($sql),'CREATE UNIQUE ')===0) $nonunique='0'; + else $nonunique='1'; + $cardinality=nucleus_mysql_num_rows(sqlite_query($dbhandle,"SELECT $columnname FROM '$tname'")); + sqlite_query($dbhandle,"INSERT INTO $tmpname ('Table', 'Non_unique', 'Key_name', 'Seq_in_index',". + " 'Column_name', 'Collation', 'Cardinality', 'Sub_part', 'Packed', 'Null', 'Index_type', 'Comment')". + " VALUES ('$tname', '$nonunique', '$name', '".(string)($key+1)."',". + " '$columnname', 'A', '$cardinality', null, null, '$notnull[$columnname]', 'BTREE', '')"); + } + } + } + } + if ($pkey) { // The case that the key (index) is not defined. + $cardinality=nucleus_mysql_num_rows(sqlite_query($dbhandle,"SELECT $pkey FROM '$tname'")); + sqlite_query($dbhandle,"INSERT INTO $tmpname ('Table', 'Non_unique', 'Key_name', 'Seq_in_index',". + " 'Column_name', 'Collation', 'Cardinality', 'Sub_part', 'Packed', 'Null', 'Index_type', 'Comment')". + " VALUES ('$tname', '0', 'PRIMARY', '1',". + " '$pkey', 'A', '$cardinality', null, null, '$pkeynull', 'BTREE', '')"); + $pkey=null; + } + + // return the final query to show the keys in MySQL style (using temporary table). + return "SELECT * FROM $tmpname"; +} +function sqlite_showFieldsFrom($tname,$dbhandle){ + // This function is for supporing 'SHOW FIELDS FROM' and 'SHOW COLUMNS FROM'. + // For making the same result as obtained by MySQL, temporary table is made. + if (preg_match('/^([^\s]+)\s+LIKE\s+\'([^\']+)\'$/i',$tname,$m)) list($m,$tname,$like)=$m; + $tname=str_replace("'",'',$tname); + + // First, get the sql query when the table created + $res=sqlite_query($dbhandle,"SELECT sql FROM sqlite_master WHERE tbl_name = '$tname' ORDER BY type DESC"); + $a=nucleus_mysql_fetch_assoc($res); + $tablesql=trim($a['sql']); + if (preg_match('/^[^\(]+\(([\s\S]*?)\)$/',$tablesql,$matches)) $tablesql=$matches[1]; + $tablearray=array(); + foreach(_sqlite_divideByChar(',',$tablesql) as $value) { + $value=trim($value); + if ($i=strpos($value,' ')) { + $name=str_replace("'",'',substr($value,0,$i)); + $value=trim(substr($value,$i)); + if (substr($value,-1)==',') $value=substr($value,strlen($value)-1); + $tablearray[$name]=$value; + } + } + + // Check if INDEX has been made for the parameter 'MUL' in 'KEY' column + $multi=array(); + $res=sqlite_query($dbhandle,"SELECT name FROM sqlite_master WHERE type = 'index' and tbl_name = '$tname' ORDER BY type DESC"); + while ($a=nucleus_mysql_fetch_assoc($res)) $multi[str_replace("'",'',$a['name'])]='MUL'; + + // Create a temporary table for making result + if (function_exists('microtime')) $tmpname='t'.str_replace('.','',str_replace(' ','',microtime())); + else $tmpname = 't'.rand(0,999999).time(); + sqlite_query($dbhandle,"CREATE TEMPORARY TABLE $tmpname ('Field', 'Type', 'Null', 'Key', 'Default', 'Extra')"); + + // Check the table + foreach($tablearray as $field=>$value) { + if (strtoupper($field)=='PRIMARY') continue;//PRIMARY KEY('xx'[,'xx']) + if (isset($like) && $field!=$like) continue; + $uvalue=strtoupper($value.' '); + $key=(string)$multi[$field]; + if ($uvalue=='INTEGER NOT NULL PRIMARY KEY ' || $uvalue=='INTEGER PRIMARY KEY ') { + $key='PRI'; + $extra='auto_increment'; + } else $extra=''; + if ($i=strpos($uvalue,' ')) { + $type=substr($value,0,$i); + if (strpos($type,'(') && ($i=strpos($value,')'))) + $type=substr($value,0,$i+1); + } else $type=''; + if (strtoupper($type)=='INTEGER') $type='int(11)'; + if (strpos($uvalue,'NOT NULL')===false) $null='YES'; + else { + $null=''; + $value=preg_replace('/NOT NULL/i','',$value); + $uvalue=strtoupper($value); + } + if ($i=strpos($uvalue,'DEFAULT')) { + $default=trim(substr($value,$i+7)); + if (strtoupper($default)=='NULL') { + $default=""; + $setdefault=""; + } else { + if (substr($default,0,1)=="'") $default=substr($default,1,strlen($default)-2); + $default="'".$default."',"; + $setdefault="'Default',"; + } + } else if ($null!='YES' && $extra!='auto_increment') { + if (strpos(strtolower($type),'int')===false) $default="'',"; + else $default="'0',"; + $setdefault="'Default',"; + } else { + $default=""; + $setdefault=""; + } + sqlite_query($dbhandle,"INSERT INTO '$tmpname' ('Field', 'Type', 'Null', 'Key', $setdefault 'Extra')". + " VALUES ('$field', '$type', '$null', '$key', $default '$extra')"); + } + + // return the final query to show the keys in MySQL style (using temporary table). + return "SELECT * FROM $tmpname"; +} + +?> \ No newline at end of file diff --git a/sqlite/tags/sqlite0904/nucleus/sqlite/sqliteconfig.php b/sqlite/tags/sqlite0904/nucleus/sqlite/sqliteconfig.php new file mode 100644 index 0000000..4b556b8 --- /dev/null +++ b/sqlite/tags/sqlite0904/nucleus/sqlite/sqliteconfig.php @@ -0,0 +1,14 @@ + \ No newline at end of file diff --git a/sqlite/tags/sqlite0904/nucleus/sqlite/sqlitequeryfunctions.php b/sqlite/tags/sqlite0904/nucleus/sqlite/sqlitequeryfunctions.php new file mode 100644 index 0000000..244faf3 --- /dev/null +++ b/sqlite/tags/sqlite0904/nucleus/sqlite/sqlitequeryfunctions.php @@ -0,0 +1,890 @@ +$value){ + $key=strtoupper($key); + if (substr($key,0,7)!='DEFINE_') continue; + $key=substr($key,7); + if (substr($value,0,7)=='sqlite_') $value=array('SQLite_Functions',$value); + @sqlite_create_function($SQLITE_DBHANDLE,$key,$value); + } +} + +var $define_ASCII='ord'; + +var $define_BIN='decbin'; + +var $define_BIT_LENGTH='sqlite_userfunc_BIT_LENGTH'; +function sqlite_userfunc_BIT_LENGTH($p1){ + return strlen($p1)*8; +} + +var $define_CHAR='sqlite_userfunc_CHAR'; +function sqlite_userfunc_CHAR(){ + if (!($lastnum=func_num_args())) return null; + $args=&func_get_args(); + $ret=''; + for ($i=0;$i<$lastnum;$i++) { + if ($args[$i]!==null) $ret.=chr($args[$i]); + } + return $ret; +} + +var $define_CHAR_LENGTH='sqlite_userfunc_CHAR_LENGTH'; +function sqlite_userfunc_CHAR_LENGTH($str){ + if (function_exists('mb_strlen')) return mb_strlen($str); + return strlen($str); +} + +var $define_CONCAT_WS='sqlite_userfunc_CONCAT_WS'; +function sqlite_userfunc_CONCAT_WS(){ + if (($lastnum=func_num_args())<2) return null; + $args=&func_get_args(); + if ($args[0]===null) return null; + $ret=''; + for ($i=1;$i<$lastnum;$i++) { + if ($args[$i]===null) continue; + if ($ret) $ret.=$args[0]; + $ret.=(string)($args[$i]); + } + return $ret; +} + +var $define_CONV='sqlite_userfunc_CONV'; +function sqlite_userfunc_CONV($p1,$p2,$p3){ + $t36='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'; + $p1=strtoupper(trim((string)$p1)); + if ($p3<0 && substr($p1,0,1)=='-') { + $sign='-'; + $p1=substr($p1,1); + } else $sign=''; + $p3=abs($p3); + $v=0; + for ($i=0;$i0 && $p2>0) return atan($p1/$p2); + else if ($p1>0 && $p2<0) return pi-atan(-$p1/$p2); + else if ($p1<0 && $p2<0) return pi+atan($p1/$p2); + else if ($p1<0 && $p2>0) return 2*pi-atan(-$p1/$p2); + else return 0; +} + +var $define_CEIL='ceil'; +var $define_CEILING='ceil'; +var $define_COS='cos'; + +var $define_COT='sqlite_userfunc_COT'; +function sqlite_userfunc_COT($p1){ + return 1/tan($p1); +} + +var $define_CRC32='crc32'; + +var $define_DEGREES='sqlite_userfunc_DEGREES'; +function sqlite_userfunc_DEGREES($p1){ + return ($p1/pi)*180; +} + +var $define_EXP='exp'; +var $define_FLOOR='floor'; +var $define_GREATEST='max'; +var $define_MAX='max'; +var $define_LEAST='min'; +var $define_MIN='min'; +var $define_ln='log'; + +var $define_log='sqlite_userfunc_LOG'; +function sqlite_userfunc_LOG($p1,$p2=null){ + if ($p2) return log($p1)/log($p2); + return log($p1); +} + +var $define_log2='sqlite_userfunc_LOG2'; +function sqlite_userfunc_LOG2($p1){ + return log($p1)/log(2); +} + +var $define_log10='log10'; + +var $define_MOD='sqlite_userfunc_MOD'; +function sqlite_userfunc_MOD($p1,$p2){ + return $p1 % $p2; +} + +var $define_PI='sqlite_userfunc_PI'; +function sqlite_userfunc_PI(){ + return pi; +} + +var $define_POW='sqlite_userfunc_POW'; +var $define_POWER='sqlite_userfunc_POW'; +function sqlite_userfunc_POW($p1,$p2){ + return pow($p1,$p2); +} + +var $define_RADIANS='sqlite_userfunc_RADIANS'; +function sqlite_userfunc_RADIANS($p1){ + return ($p1/180)*pi; +} + +var $define_RAND='sqlite_userfunc_RAND'; +function sqlite_userfunc_RAND($p1=null){ + if ($p1) srand($p1); + return rand(0,1073741823)/1073741824; +} + +var $define_SIGN='sqlite_userfunc_SIGN'; +function sqlite_userfunc_SIGN($p1){ + if ($p1>0) return 1; + else if ($p1<0) return -1; + return 0; +} + +var $define_SIN='sin'; +var $define_SQRT='sqrt'; +var $define_TAN='tan'; + +var $define_TRUNCATE='sqlite_userfunc_TRUNCATE'; +function sqlite_userfunc_TRUNCATE($p1,$p2){ + $p2=pow(10,$p2); + return ((int)($p1*$p2))/$p2; +} + +var $define_FORMAT='sqlite_userfunc_FORMAT'; +function sqlite_userfunc_FORMAT($p1,$p2){ + return number_format($p1, $p2, '.', ','); +} + +var $define_INET_ATON='sqlite_userfunc_INET_ATON'; +function sqlite_userfunc_INET_ATON($p1){ + $a=explode('.',$p1); + return (($a[0]*256+$a[1])*256+$a[2])*256+$a[3]; +} + +var $define_INET_NTOA='sqlite_userfunc_INET_NTOA'; +function sqlite_userfunc_INET_NTOA($p1){ + $a=array(); + for ($i=0;$i<4;$i++){ + $a[$i]=(string)($p1 % 256); + $p1=(int)($p1/256); + } + return $a[3].'.'.$a[2].'.'.$a[1].'.'.$a[0]; +} + +var $define_MD5='md5'; + + +var $define_CURDATE='sqlite_userfunc_CURDATE'; +var $define_CURRENT_DATE='sqlite_userfunc_CURDATE'; +function sqlite_userfunc_CURDATE(){ + return date('Y-m-d'); +} + +var $define_CURTIME='sqlite_userfunc_CURTIME'; +var $define_CURRENT_TIME='sqlite_userfunc_CURTIME'; +function sqlite_userfunc_CURTIME(){ + return date('H:i:s'); +} + +var $define_CURRENT_TIMESTAMP='sqlite_userfunc_NOW'; +var $define_LOCALTIME='sqlite_userfunc_NOW'; +var $define_LOCALTIMESTAMP='sqlite_userfunc_NOW'; +var $define_SYSDATE='sqlite_userfunc_NOW'; +function sqlite_userfunc_NOW(){ + return date('Y-m-d H:i:s'); +} + +var $define_DATE_FORMAT='sqlite_userfunc_DATE_FORMAT'; +var $define_TIME_FORMAT='sqlite_userfunc_DATE_FORMAT'; +function sqlite_userfunc_DATE_FORMAT($p1,$p2){ + $t=SQLite_Functions::sqlite_resolvedatetime($p1,$yr,$mt,$dy,$hr,$mn,$sc); + $func='if ($matches=="%") return "%";'; + $func='return date($matches,'.$t.');'; + return preg_replace_callback ('/%([%a-zA-Z])/',create_function('$matches',$func), $p2); +} + +var $define_DAYNAME='sqlite_userfunc_DAYNAME'; +function sqlite_userfunc_DAYNAME($p1){ + $t=SQLite_Functions::sqlite_resolvedatetime($p1,$yr,$mt,$dy,$hr,$mn,$sc); + return date('l',$t); +} + +var $define_DAYOFWEEK='sqlite_userfunc_DAYOFWEEK'; +function sqlite_userfunc_DAYOFWEEK($p1){ + $t=SQLite_Functions::sqlite_resolvedatetime($p1,$yr,$mt,$dy,$hr,$mn,$sc); + return date('w',$t)+1; +} + +var $define_DAYOFYEAR='sqlite_userfunc_DAYOFYEAR'; +function sqlite_userfunc_DAYOFYEAR($p1){ + $t=SQLite_Functions::sqlite_resolvedatetime($p1,$yr,$mt,$dy,$hr,$mn,$sc); + return date('z',$t); +} + +var $define_EXTRACT='sqlite_userfunc_EXTRACT'; +function sqlite_userfunc_EXTRACT($p1,$p2){ + $t=SQLite_Functions::sqlite_resolvedatetime($p2,$yr,$mt,$dy,$hr,$mn,$sc); + switch(strtoupper($p1)) { + case'SECOND': // SECONDS + return $sc; + case'MINUTE': // MINUTES + return $m; + case'HOUR': // HOURS + return $hr; + case'MONTH': // MONTHS + return $mt; + case'YEAR': // YEARS + return $y; + case'MINUTE_SECOND': // 'MINUTES:SECONDS' + return date('is',$t); + case'HOUR_MINUTE': // 'HOURS:MINUTES' + return date('Hi',$t); + case'DAY_HOUR': // 'DAYS HOURS' + return date('dH',$t); + case'YEAR_MONTH': // 'YEARS-MONTHS' + return date('Ym',$t); + case'HOUR_SECOND': // 'HOURS:MINUTES:SECONDS' + return date('Hs',$t); + case'DAY_MINUTE': // 'DAYS HOURS:MINUTES' + return date('di',$t); + case'DAY_SECOND': // 'DAYS HOURS:MINUTES:SECONDS' + return date('ds',$t); + case'DAY': // DAYS + default: + return $dy; + } +} + +var $define_FROM_DAYS='sqlite_userfunc_FROM_DAYS'; +function sqlite_userfunc_FROM_DAYS($p1){ + return date('Y-m-d',($p1-719528)*86400); +} + +var $define_FROM_UNIXTIME='sqlite_userfunc_FROM_UNIXTIME'; +function sqlite_userfunc_FROM_UNIXTIME($p1,$p2=null){ + if ($p2) return sqlite_userfunc_DATE_FORMAT($p1,$p2); + return date('Y-m-d H:i:s',$p1); +} + +var $define_HOUR='sqlite_userfunc_HOUR'; +function sqlite_userfunc_HOUR($p1){ + SQLite_Functions::sqlite_resolvedatetime($p1,$yr,$mt,$dy,$hr,$mn,$sc); + return $hr; +} + +var $define_MINUTE='sqlite_userfunc_MINUTE'; +function sqlite_userfunc_MINUTE($p1){ + SQLite_Functions::sqlite_resolvedatetime($p1,$yr,$mt,$dy,$hr,$mn,$sc); + return $mn; +} + +var $define_MONTHNAME='sqlite_userfunc_MONTHNAME'; +function sqlite_userfunc_MONTHNAME($p1){ + $t=SQLite_Functions::sqlite_resolvedatetime($p1,$yr,$mt,$dy,$hr,$mn,$sc); + return date('F',$t); +} + + +var $define_PERIOD_ADD='sqlite_userfunc_PERIOD_ADD'; +function sqlite_userfunc_PERIOD_ADD($p1,$p2){ + $y=(int)($p1/100); + $m=$p1-$y*100; + $t=mktime(0,0,0,$m+$p2,1,$y, -1); + return date('Ym',$t); +} + +var $define_PERIOD_DIFF='sqlite_userfunc_PERIOD_DIFF'; +function sqlite_userfunc_PERIOD_DIFF($p1,$p2){ + $y1=(int)($p1/100); + $m1=$p1-$y1*100; + $y2=(int)($p2/100); + $m2=$p1-$y2*100; + $t1=mktime(0,0,0,$m1,1,$y1, -1); + $t2=mktime(0,0,0,$m2,1,$y2, -1); + $y1=date('Y',$t1); + $y2=date('Y',$t2); + return (int)(mktime(0,0,0,$m1-$m2,1,1970+$y1-$y2, -1)/60/60/24/28); +} + +var $define_QUARTER='sqlite_userfunc_QUARTER'; +function sqlite_userfunc_QUARTER($p1){ + SQLite_Functions::sqlite_resolvedatetime($p1,$yr,$mt,$dy,$hr,$mn,$sc); + switch($mt){ + case 1: case 2: case 3: return 1; + case 4: case 5: case 6: return 2; + case 7: case 8: case 9: return 3; + default: return 4; + } +} + +var $define_SECOND='sqlite_userfunc_SECOND'; +function sqlite_userfunc_SECOND($p1){ + SQLite_Functions::sqlite_resolvedatetime($p1,$yr,$mt,$dy,$hr,$mn,$sc); + return $sc; +} + +var $define_SEC_TO_TIME='sqlite_userfunc_SEC_TO_TIME'; +function sqlite_userfunc_SEC_TO_TIME($p1){ + return date('H:i:s',$p1); +} + +var $define_WEEK='sqlite_userfunc_WEEK'; +function sqlite_userfunc_WEEK($p1){ + $t=SQLite_Functions::sqlite_resolvedatetime($p1,$yr,$mt,$dy,$hr,$mn,$sc); + return date('W',$t); +} + +var $define_WEEKDAY='sqlite_userfunc_WEEKDAY'; +function sqlite_userfunc_WEEKDAY($p1){ + $t=SQLite_Functions::sqlite_resolvedatetime($p1,$yr,$mt,$dy,$hr,$mn,$sc); + if (0<($w=date('w',$t))) return $w-1; + return 6; +} + +var $define_YEAR='sqlite_userfunc_YEAR'; +function sqlite_userfunc_YEAR($p1){ + $t=SQLite_Functions::sqlite_resolvedatetime($p1,$yr,$mt,$dy,$hr,$mn,$sc); + return date('Y',$t); +} + +var $define_YEARWEEK='sqlite_userfunc_YEARWEEK'; +function sqlite_userfunc_YEARWEEK($p1){ + $t=SQLite_Functions::sqlite_resolvedatetime($p1,$yr,$mt,$dy,$hr,$mn,$sc); + return date('YW',$t); +} + + +var $define_FIND_IN_SET='sqlite_userfunc_FIND_IN_SET'; +function sqlite_userfunc_FIND_IN_SET($p1,$p2){ + if ($p1==null && $p2==null) return null; + if (!$p2) return 0; + foreach (explode(',',$p2) as $key=>$value) if ($value==$p1) return ($key+1); + return 0; +} + + +var $define_ADDDATE='sqlite_userfunc_ADDDATE'; +function sqlite_userfunc_ADDDATE($p1,$p2,$p3='DAY'){ + return date("Y-m-d",sqlite_ADDDATE($p1,$p2,$p3)); +} + +var $define_SUBDATE='sqlite_userfunc_SUBDATE'; +function sqlite_userfunc_SUBDATE($p1,$p2,$p3='DAY'){ + return date("Y-m-d",sqlite_ADDDATE($p1,0-$p2,$p3)); +} + +var $define_CONCAT='sqlite_userfunc_CONCAT'; +function sqlite_userfunc_CONCAT(){ + if (!($lastnum=func_num_args())) return null; + $args=&func_get_args(); + $ret=''; + for ($i=0;$i<$lastnum;$i++) { + if ($args[$i]===null) return null; + $ret.=(string)($args[$i]); + } + return $ret; +} + +var $define_IF='sqlite_userfunc_IF'; +function sqlite_userfunc_IF($p1,$p2,$p3){ + if ((int)$p1) return $p2; + return $p3; +} + +var $define_IFNULL='sqlite_userfunc_IFNULL'; +function sqlite_userfunc_IFNULL($p1,$p2){ + if ($p1!=null) return $p1; + return $p2; +} + +var $define_NULLIF='sqlite_userfunc_NULLIF'; +function sqlite_userfunc_NULLIF($p1,$p2){ + if ($p1==$p2) return null; + return $p1; +} + + +var $define_match_against='sqlite_userfunc_match_against'; +function sqlite_userfunc_match_against(){ + if (!($lastnum=func_num_args())) return 0; + if (!(--$lastnum)) return 0; + $args=&func_get_args(); + if (!$args[$lastnum]) return 0; + $pattern='/'.quotemeta($args[$lastnum]).'/i'; + $ret=0; + for($i=0;$i<$lastnum;$i++) $ret=$ret+preg_match_all ($pattern,$args[$i],$matches); + return $ret; +} + +var $define_replace='sqlite_userfunc_replace'; +function sqlite_userfunc_replace($p1,$p2,$p3){ + return str_replace($p3,$p1,$p2); +} + +var $define_UNIX_TIMESTAMP='sqlite_userfunc_UNIX_TIMESTAMP'; +function sqlite_userfunc_UNIX_TIMESTAMP($p1=null){ + if (!$p1) return time(); + SQLite_Functions::sqlite_resolvedatetime($p1,$yr,$mt,$dy,$hr,$mn,$sc); + if ($yr) return mktime($hr,$mn,$sc,$mt,$dy,$yr, -1); + return $p1;//TIMESTAMP +} + +var $define_REGEXP='sqlite_userfunc_REGEXP'; +function sqlite_userfunc_REGEXP($p1,$p2){ + return preg_match ("/$p2/",$p1); +} + +var $define_DAYOFMONTH='sqlite_userfunc_DAYOFMONTH'; +function sqlite_userfunc_DAYOFMONTH($p1){ + SQLite_Functions::sqlite_resolvedatetime($p1,$yr,$mt,$dy,$hr,$mn,$sc); + return $dy; +} + +var $define_MONTH='sqlite_userfunc_MONTH'; +function sqlite_userfunc_MONTH($p1){ + SQLite_Functions::sqlite_resolvedatetime($p1,$yr,$mt,$dy,$hr,$mn,$sc); + return $mt; +} + + +function sqlite_resolvedatetime($p1,&$yr,&$mt,&$dy,&$hr,&$mn,&$sc){ + $t=trim($p1); + if (preg_match('/^([0-9]{4})-([0-9]{2})-([0-9]{2}) ([0-9]{2}):([0-9]{2}):([0-9]{2})$/', $t,$matches)) { + //DATETIME + $yr=(int)$matches[1]; + $mt=(int)$matches[2]; + $dy=(int)$matches[3]; + $hr=(int)$matches[4]; + $mn=(int)$matches[5]; + $sc=(int)$matches[6]; + } else if (preg_match('/^([0-9]{4})-([0-9]{2})-([0-9]{2})$/', $t,$matches)) { + //DATE + $yr=(int)$matches[1]; + $mt=(int)$matches[2]; + $dy=(int)$matches[3]; + $hr=$mn=$sc=0; + } else if (preg_match('/^([0-9]{4})([0-9]{2})([0-9]{2})$/', $t,$matches)) { + //YYYYMMDD + $yr=(int)$matches[1]; + $mt=(int)$matches[2]; + $dy=(int)$matches[3]; + $hr=$mn=$sc=0; + } else if (preg_match('/^([0-9]{2})([0-9]{2})([0-9]{2})$/', $t,$matches)) { + //YYMMDD + $yr=(int)$matches[1]; + $mt=(int)$matches[2]; + $dy=(int)$matches[3]; + $hr=$mn=$sc=0; + if ($yr<70) $yr=$yr+2000; + else $yr=$yr+1900; + } + return mktime($hr,$mn,$sc,$mt,$dy,$yr, -1); +} + +function sqlite_ADDDATE($p1,$p2,$p3){ + SQLite_Functions::sqlite_resolvedatetime($p1,$yr,$mt,$dy,$hr,$mn,$sc); + $a=explode(' ',preg_replace('/[^0-9]/',' ',trim((string)$p2))); + switch(strtoupper($p3)) { + case'SECOND': // SECONDS + $sc += (int)$p2; + break; + case'MINUTE': // MINUTES + $mn += (int)$p2; + break; + case'HOUR': // HOURS + $hr += (int)$p2; + break; + case'MONTH': // MONTHS + $mt += (int)$p2; + break; + case'YEAR': // YEARS + $yr += (int)$p2; + break; + case'MINUTE_SECOND': // 'MINUTES:SECONDS' + $mn += (int)$a[0]; + $sc += (int)$a[1]; + break; + case'HOUR_MINUTE': // 'HOURS:MINUTES' + $hr += (int)$a[0]; + $mn += (int)$a[1]; + break; + case'DAY_HOUR': // 'DAYS HOURS' + $dy += (int)$a[0]; + $hr += (int)$a[1]; + break; + case'YEAR_MONTH': // 'YEARS-MONTHS' + $yr += (int)$a[0]; + $mt += (int)$a[1]; + break; + case'HOUR_SECOND': // 'HOURS:MINUTES:SECONDS' + $hr += (int)$a[0]; + $mn += (int)$a[1]; + $sc += (int)$a[2]; + break; + case'DAY_MINUTE': // 'DAYS HOURS:MINUTES' + $dy += (int)$a[0]; + $hr += (int)$a[1]; + $mn += (int)$a[2]; + break; + case'DAY_SECOND': // 'DAYS HOURS:MINUTES:SECONDS' + $dy += (int)$a[0]; + $hr += (int)$a[1]; + $mn += (int)$a[2]; + $sc += (int)$a[3]; + break; + case'DAY': // DAYS + default: + $dy += (int)$p2; + break; + } + return mktime($hr,$mn,$sc,$mt,$dy,$yr, -1); +} + +// For creating table structure (table and index/indeces) +var $define_sqlite_table_structure='sqlite_userfunc_sqlite_table_structure'; +function sqlite_userfunc_sqlite_table_structure($p1){ + global $SQLITE_DBHANDLE; + $ret=''; + if ($res=sqlite_query($SQLITE_DBHANDLE,"SELECT sql FROM sqlite_master WHERE tbl_name='$p1'")) { + while ($array=sqlite_fetch_array($res,SQLITE_NUM)) $ret.=$array[0].";\n"; + } + return $ret; +} + + +// Modification of query for some functions. +function sqlite_modifyQueryForUserFunc(&$query,$strpositions,$pattern=null,$replacement=null){ + // Write this part very carefully. Otherwise, you may allow crackers to do SQL-injection. + global $SQLITE_MQFUFCB_OK,$SQLITE_MQFUFCB_COUNT,$SQLITE_MQFUFCB_REPLACE; + + // Store the previous string + $orgstrings=array(); + foreach ($strpositions as $start => $end) array_push($orgstrings, trim(substr($query,$start,$end-$start))); + + $lquery=strtolower($query); + if (!$pattern) $pattern=array(); + if (!$replacement) $replacement=array(); + + // match() against() support. Following way does NOT accept SQL-injection. Note that the string is always quoted by "'". + array_push($pattern,'/match \(([^\']*?)\) against \(/i'); + array_push($replacement,'match_against ($1,'); + // REGEXP support + if (strpos($lquery,'regexp')!==false) { + array_push($pattern,'/([^a-z_\.])([a-z_\.]+)[\s]+REGEXP[\s]+\'([^\']*?)\'([^\']?)/i'); + array_push($replacement,'$1regexp($2,\'$3\')$4'); + } + // ADDDATE/SUBDATE support (INTERVAL support) + array_push($pattern,'/([^a-zA-Z_])ADDDATE[\s]*?\(([^,]+),[\s]*?INTERVAL[\s]+([\S]+)[\s]+([^\)]+)\)/i'); + array_push($replacement,'$1adddate($2,$3,\'$4\')'); + array_push($pattern,'/([^a-zA-Z_])DATE_ADD[\s]*?\(([^,]+),[\s]*?INTERVAL[\s]+([\S]+)[\s]+([^\)]+)\)/i'); + array_push($replacement,'$1adddate($2,$3,\'$4\')'); + array_push($pattern,'/([^a-zA-Z_])SUBDATE[\s]*?\(([^,]+),[\s]*?INTERVAL[\s]+([\S]+)[\s]+([^\)]+)\)/i'); + array_push($replacement,'$1subdate($2,$3,\'$4\')'); + array_push($pattern,'/([^a-zA-Z_])DATE_SUB[\s]*?\(([^,]+),[\s]*?INTERVAL[\s]+([\S]+)[\s]+([^\)]+)\)/i'); + array_push($replacement,'$1subdate($2,$3,\'$4\')'); + + // EXTRACT support + array_push($pattern,'/([^a-zA-Z_])EXTRACT[\s]*?\(([a-zA-Z_]+)[\s]+FROM/i'); + array_push($replacement,'$1extract(\'$2\','); + + // TRIM support: + array_push($pattern,'/([^a-zA-Z_])TRIM[\s]*?\((BOTH|LEADING|TRAILING)[\s]+FROM/i'); + array_push($replacement,'$1extract(\'$2\',\' \','); + array_push($pattern,'/([^a-zA-Z_])TRIM[\s]*?\((BOTH|LEADING|TRAILING)[\s]+([\s\S]+)[\s]+FROM/i'); + array_push($replacement,'$1extract(\'$2\',$3,'); + + // Change it. + $temp=preg_replace ($pattern,$replacement,$query); + + // Comfirm if strings did not change. + $ok=true; + foreach ($orgstrings as $key=>$value) if ($value) { + if (strpos($temp,$value)!==false) { + // This string is OK, therefore will be ignored in the next "step by step" step. + $orgstrings[$key]=''; + continue; + } + $ok=false; + } + if ($ok) { // return if everything is OK. + $query=$temp; + return; + } + + // At least one of string changed. Need to do step by step. + foreach ($pattern as $key=>$pat) { + // Replace is done step by step for each RegExp replace statement. + $SQLITE_MQFUFCB_REPLACE=$replace[$key];// Set the grobal var. + $num=preg_match_all($pat,$query,$matches); + // First, check if OK. + $replaceOK=array(); + for ($i=1;$i<=$num;$i++) { + $SQLITE_MQFUFCB_OK=array(); + $SQLITE_MQFUFCB_OK[$i]=true; // Set the grobal var. + $SQLITE_MQFUFCB_COUNT=0; // Set the grobal var. + // Only $i-st replacement will be done in the next line. + $temp=preg_replace_callback($pat,array('SQLite_Functions','sqlite_modifyQueryForUserFuncCallBack'), $query, $i); + $ok=true; + foreach ($orgstrings as $value) if ($value) { + if (strpos($temp,$value)!==false) continue; + $ok=false; + break; + } + if ($ok) $replaceOK[$i]=true; + } + // Replace + $SQLITE_MQFUFCB_OK=$replaceOK;// Copy the OK array + $SQLITE_MQFUFCB_COUNT=0; + $query=preg_replace_callback($pat,array('SQLite_Functions','sqlite_modifyQueryForUserFuncCallBack'), $query); + } +} + +function sqlite_modifyQueryForUserFuncCallBack($mathces){ + global $SQLITE_MQFUFCB_OK,$SQLITE_MQFUFCB_COUNT,$SQLITE_MQFUFCB_REPLACE; + if ($SQLITE_MQFUFCB_OK[++$SQLITE_MQFUFCB_COUNT]) return $SQLITE_MQFUFCB_REPLACE; + else return $mathces[0]; +} + +}//class SQLite_QueryFunctions + +?> \ No newline at end of file diff --git a/sqlite/tags/sqlite0904/readme-en.txt b/sqlite/tags/sqlite0904/readme-en.txt new file mode 100644 index 0000000..408e83e --- /dev/null +++ b/sqlite/tags/sqlite0904/readme-en.txt @@ -0,0 +1,39 @@ +************************************************* +* MySQL-SQLite wrapper for Nucleus ver 0.8 * +************************************************* + +Copyright (C) 2006-2007 Katsumi + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +---------------------------------------------------------------------- + +This tool is needed when using Nucleus with SQLite as database engine. + + +****************************** How to use ****************************** + + When installing Nucleus, the access-ID and password are not required. SQLite +uses normal file as database. This is fixed to "nucleus/sqlite/.dbsqlite" +(if you would like another file name, please set it in "sqlite.php" file). +Set the permission of "nucleus/sqlite/" directory to 777 or something like this. +Then execute install.php. That's it! If you see the install-complete message, +probably the install is succeded. NP_SkinFiles as well as NP_SQLite are +automatically installed. If not, install it manually. + + The usage of Nucleus is almost (99%) the same as that of normal Nucleus. When +installing plugins, NP_SQLite will convert the plugin files automatically if the +permission of these files is set to be writable. + diff --git a/sqlite/tags/sqlite0904/readme-ja.txt b/sqlite/tags/sqlite0904/readme-ja.txt new file mode 100644 index 0000000..6afe98d --- /dev/null +++ b/sqlite/tags/sqlite0904/readme-ja.txt @@ -0,0 +1,45 @@ +********************************************** +* MySQL-SQLite wrapper for Nucleus ver 0.8 * +********************************************** + +Copyright (C) 2006-2007”NAKatsumi + +‚±‚̃vƒƒOƒ‰ƒ€‚̓tƒŠ[ƒ\ƒtƒgƒEƒFƒA‚Å‚·B‚ ‚È‚½‚Í‚±‚ê‚ðAƒtƒŠ[ƒ\ƒtƒgƒEƒF +ƒAà’c‚É‚æ‚Á‚Ä”­s‚³‚ꂽ GNU ˆê”ÊŒöO—˜—p‹–‘øŒ_–ñ‘(ƒo[ƒWƒ‡ƒ“2‚©AŠó +–]‚É‚æ‚Á‚Ä‚Í‚»‚êˆÈ~‚̃o[ƒWƒ‡ƒ“‚Ì‚¤‚¿‚Ç‚ê‚©)‚Ì’è‚ß‚éðŒ‚̉º‚ōĔЕz +‚Ü‚½‚͉ü•Ï‚·‚邱‚Æ‚ª‚Å‚«‚Ü‚·B + +‚±‚̃vƒƒOƒ‰ƒ€‚Í—L—p‚Å‚ ‚邱‚Æ‚ðŠè‚Á‚ĔЕz‚³‚ê‚Ü‚·‚ªA*‘S‚­‚Ì–³•ÛØ* +‚Å‚·B¤‹Æ‰Â”\«‚̕ۏ؂â“Á’è‚Ì–Ú“I‚Ö‚Ì“K‡«‚́AŒ¾ŠO‚ÉŽ¦‚³‚ꂽ‚à‚Ì‚àŠÜ +‚ß‘S‚­‘¶Ý‚µ‚Ü‚¹‚ñBÚ‚µ‚­‚ÍGNU ˆê”ÊŒöO—˜—p‹–‘øŒ_–ñ‘‚ð‚²——‚­‚¾‚³‚¢B + +‚ ‚È‚½‚Í‚±‚̃vƒƒOƒ‰ƒ€‚Æ‹¤‚ɁAGNU ˆê”ÊŒöO—˜—p‹–‘øŒ_–ñ‘‚Ì•¡»•¨‚ðˆê•” +Žó‚¯Žæ‚Á‚½‚Í‚¸‚Å‚·B‚à‚µŽó‚¯Žæ‚Á‚Ä‚¢‚È‚¯‚ê‚΁AƒtƒŠ[ƒ\ƒtƒgƒEƒFƒAà’c‚Ü +‚Ő¿‹‚µ‚Ä‚­‚¾‚³‚¢(ˆ¶æ‚Í the Free Software Foundation, Inc., 59 +Temple Place, Suite 330, Boston, MA 02111-1307 USA)B + +---------------------------------------------------------------------- + +‚±‚̃c[ƒ‹‚́ANucleus ‚Ńf[ƒ^ƒx[ƒX‚Æ‚µ‚āASQLite ‚ð—p‚¢‚邽‚ß‚Ì•¨‚Å‚·B + +–––––––––––––––@Žg—p•û–@@––––––––––––––– + +@Nucleus ‚̃Cƒ“ƒXƒg[ƒ‹‚̍ۂ́Aƒf[ƒ^ƒx[ƒX‚̃AƒNƒZƒXID‚âƒpƒXƒ[ƒh‚È‚Ç‚Í +Žw’è‚·‚é•K—v‚Í‚ ‚è‚Ü‚¹‚ñBSQLite ‚̓f[ƒ^ƒx[ƒX‚Æ‚µ‚Ēʏíƒtƒ@ƒCƒ‹‚ð—p‚¢‚Ü‚·B +‚±‚ê‚́Awnucleus/sqlite/.dbsqlitexŒÅ’è‚Å‚·BƒCƒ“ƒXƒg[ƒ‹‘O‚Ɂwnucleus/sqlite/x +ƒtƒHƒ‹ƒ_‚̃p[ƒ~ƒbƒVƒ‡ƒ“‚ðA“ǂݏ‘‚«‰Â”\‚ÈŒ`i777‚Æ‚©j‚É‚µ‚Ä‚­‚¾‚³‚¢B•Ê‚Ì +ƒtƒ@ƒCƒ‹–¼‚ðŽg—p‚µ‚½‚¢ê‡‚́Awnucleus/sqlite/sqlite.phpx‚ð‘‚«Š·‚¦‚Ä‚­‚¾‚³‚¢B + +@‚ ‚Ƃ́Awinstall.phpx‚ðŽÀs‚·‚邾‚¯‚Å‚·BƒIƒŠƒWƒiƒ‹”Å‚ÌNucleus‚Æ“¯‚¶‚æ +‚¤‚ȃCƒ“ƒXƒg[ƒ‹Š®—¹‰æ–Ê‚ªo‚ê‚΁A‚¨‚»‚ç‚­ƒCƒ“ƒXƒg[ƒ‹‚ª¬Œ÷‚µ‚Ä‚¢‚Ü‚·B +‚±‚Ì‚Æ‚«ANP_SkinFiles ‚ɉÁ‚¦‚āANP_SQLite ‚àƒvƒ‰ƒOƒCƒ“‚Æ‚µ‚ăfƒtƒHƒ‹ƒg‚ŃCƒ“ƒX +ƒg[ƒ‹‚³‚ê‚é‚Í‚¸‚Å‚·B‚à‚µƒCƒ“ƒXƒg[ƒ‹‚³‚ê‚Ä‚¢‚È‚¢ê‡‚́AŽè“®‚ŃCƒ“ƒXƒg[ƒ‹ +‚µ‚Ä‚­‚¾‚³‚¢B + +@‚ ‚Æ‚ÌŽg‚¢•û‚Í•’Ê‚Ì Nucleus ‚Æ 99% “¯‚¶‚Å‚·Bƒvƒ‰ƒOƒCƒ“‚ðƒCƒ“ƒXƒg[ƒ‹‚·‚éÛ‚́A +PHPƒtƒ@ƒCƒ‹‚̃p[ƒ~ƒbƒVƒ‡ƒ“‚ð“ǂݏ‘‚«‰Â”\‚Ȑݒè‚É‚µ‚Ä‚¨‚¯‚΁ANP_SQLite ‚ªŽ©“®“I‚É +SQLite—p‚Ƀvƒ‰ƒOƒCƒ“‚ÌPHPƒtƒ@ƒCƒ‹‚ð‘‚«Š·‚¦‚Ä‚­‚ê‚é‚Í‚¸‚Å‚·B + +@extra/sqlite/ ƒtƒHƒ‹ƒ_‚ɂ́ANucleus ‚̃o[ƒWƒ‡ƒ“ƒAƒbƒv‚ª‚ ‚Á‚½Û‚̑Ώˆ +ƒc[ƒ‹‚ª’u‚©‚ê‚Ä‚¢‚Ü‚·‚̂ŁAŠJ”­ŽÒ‚Ì•û‚Í‚»‚¿‚ç‚àŽQÆ‚µ‚Ä‚­‚¾‚³‚¢B +