Implemented first phase of splitting up the codebase. FuzeWorks Core is now significantly smaller than its previous iterations.
This commit is contained in:
parent
ec167e92b7
commit
627f83734f
|
@ -4,5 +4,4 @@
|
|||
.travis.yml export-ignore
|
||||
tests/ export-ignore
|
||||
CI/ export-ignore
|
||||
Application/ export-ignore
|
||||
DCO export-ignore
|
|
@ -1,4 +0,0 @@
|
|||
RewriteEngine On
|
||||
RewriteCond %{REQUEST_FILENAME} !-f
|
||||
RewriteCond %{REQUEST_FILENAME} !-d
|
||||
RewriteRule (.*) index.php?path=$1 [QSA,L]
|
|
@ -1,45 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks Application Skeleton.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2016 TechFuze
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 1.1.1
|
||||
*
|
||||
* @version Version 1.1.1
|
||||
*/
|
||||
|
||||
return array(
|
||||
'cache_query_string' => false,
|
||||
'memcached' => array(
|
||||
'default' => array(
|
||||
'hostname' => '127.0.0.1',
|
||||
'port' => '11211',
|
||||
'weight' => '1',
|
||||
)
|
||||
),
|
||||
'redis' => array(
|
||||
'' => ''
|
||||
)
|
||||
);
|
|
@ -1,42 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks Application Skeleton.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2016 TechFuze
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 1.1.1
|
||||
*
|
||||
* @version Version 1.1.1
|
||||
*/
|
||||
|
||||
return array(
|
||||
'contact_email' => '',
|
||||
'contact_name' => '',
|
||||
'contact_adress' => '',
|
||||
'contact_phone' => '',
|
||||
'contact_postal_code' => '',
|
||||
'contact_region' => '',
|
||||
'contact_country' => '',
|
||||
'contact_city' => '',
|
||||
);
|
|
@ -1,63 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks Application Skeleton.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2016 TechFuze
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 1.1.1
|
||||
*
|
||||
* @version Version 1.1.1
|
||||
*/
|
||||
|
||||
return array(
|
||||
'active_group' => 'default',
|
||||
'query_builder' => true,
|
||||
'databases' => array(
|
||||
|
||||
'default' => array(
|
||||
'dsn' => '',
|
||||
'hostname' => '',
|
||||
'username' => '',
|
||||
'password' => '',
|
||||
'database' => '',
|
||||
'dbdriver' => '',
|
||||
'subdriver'=> '',
|
||||
'dbprefix' => '',
|
||||
'pconnect' => FALSE,
|
||||
'db_debug' => FALSE,
|
||||
'cache_on' => FALSE,
|
||||
'char_set' => 'utf8',
|
||||
'dbcollat' => 'utf8_general_ci',
|
||||
'swap_pre' => '',
|
||||
'encrypt' => FALSE,
|
||||
'compress' => FALSE,
|
||||
'stricton' => FALSE,
|
||||
'failover' => array(),
|
||||
),
|
||||
|
||||
|
||||
),
|
||||
);
|
||||
|
||||
|
|
@ -1,35 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks Application Skeleton.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2016 TechFuze
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 1.1.1
|
||||
*
|
||||
* @version Version 1.1.1
|
||||
*/
|
||||
|
||||
return array(
|
||||
'encryption_key' => '',
|
||||
);
|
|
@ -31,7 +31,9 @@
|
|||
*/
|
||||
|
||||
return array(
|
||||
'error_reporting' => true,
|
||||
'fuzeworks_error_reporting' => true,
|
||||
'tracy_error_reporting' => true,
|
||||
'php_error_reporting' => false,
|
||||
'log_to_file' => false,
|
||||
'logger_template' => 'logger_default',
|
||||
);
|
|
@ -42,7 +42,6 @@ return array(
|
|||
'application_prefix' => 'MY_',
|
||||
|
||||
'charset' => 'UTF-8',
|
||||
'language' => 'english',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
|
@ -1,196 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks Application Skeleton.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2016 TechFuze
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 1.1.1
|
||||
*
|
||||
* @version Version 1.1.1
|
||||
*/
|
||||
|
||||
/*
|
||||
| -------------------------------------------------------------------
|
||||
| MIME TYPES
|
||||
| -------------------------------------------------------------------
|
||||
| This file contains an array of mime types. It is used by the
|
||||
| Upload class to help identify allowed file types.
|
||||
|
|
||||
*/
|
||||
return array(
|
||||
'hqx' => array('application/mac-binhex40', 'application/mac-binhex', 'application/x-binhex40', 'application/x-mac-binhex40'),
|
||||
'cpt' => 'application/mac-compactpro',
|
||||
'csv' => array('text/x-comma-separated-values', 'text/comma-separated-values', 'application/octet-stream', 'application/vnd.ms-excel', 'application/x-csv', 'text/x-csv', 'text/csv', 'application/csv', 'application/excel', 'application/vnd.msexcel', 'text/plain'),
|
||||
'bin' => array('application/macbinary', 'application/mac-binary', 'application/octet-stream', 'application/x-binary', 'application/x-macbinary'),
|
||||
'dms' => 'application/octet-stream',
|
||||
'lha' => 'application/octet-stream',
|
||||
'lzh' => 'application/octet-stream',
|
||||
'exe' => array('application/octet-stream', 'application/x-msdownload'),
|
||||
'class' => 'application/octet-stream',
|
||||
'psd' => array('application/x-photoshop', 'image/vnd.adobe.photoshop'),
|
||||
'so' => 'application/octet-stream',
|
||||
'sea' => 'application/octet-stream',
|
||||
'dll' => 'application/octet-stream',
|
||||
'oda' => 'application/oda',
|
||||
'pdf' => array('application/pdf', 'application/force-download', 'application/x-download', 'binary/octet-stream'),
|
||||
'ai' => array('application/pdf', 'application/postscript'),
|
||||
'eps' => 'application/postscript',
|
||||
'ps' => 'application/postscript',
|
||||
'smi' => 'application/smil',
|
||||
'smil' => 'application/smil',
|
||||
'mif' => 'application/vnd.mif',
|
||||
'xls' => array('application/vnd.ms-excel', 'application/msexcel', 'application/x-msexcel', 'application/x-ms-excel', 'application/x-excel', 'application/x-dos_ms_excel', 'application/xls', 'application/x-xls', 'application/excel', 'application/download', 'application/vnd.ms-office', 'application/msword'),
|
||||
'ppt' => array('application/powerpoint', 'application/vnd.ms-powerpoint', 'application/vnd.ms-office', 'application/msword'),
|
||||
'pptx' => array('application/vnd.openxmlformats-officedocument.presentationml.presentation', 'application/x-zip', 'application/zip'),
|
||||
'wbxml' => 'application/wbxml',
|
||||
'wmlc' => 'application/wmlc',
|
||||
'dcr' => 'application/x-director',
|
||||
'dir' => 'application/x-director',
|
||||
'dxr' => 'application/x-director',
|
||||
'dvi' => 'application/x-dvi',
|
||||
'gtar' => 'application/x-gtar',
|
||||
'gz' => 'application/x-gzip',
|
||||
'gzip' => 'application/x-gzip',
|
||||
'php' => array('application/x-httpd-php', 'application/php', 'application/x-php', 'text/php', 'text/x-php', 'application/x-httpd-php-source'),
|
||||
'php4' => 'application/x-httpd-php',
|
||||
'php3' => 'application/x-httpd-php',
|
||||
'phtml' => 'application/x-httpd-php',
|
||||
'phps' => 'application/x-httpd-php-source',
|
||||
'js' => array('application/x-javascript', 'text/plain'),
|
||||
'swf' => 'application/x-shockwave-flash',
|
||||
'sit' => 'application/x-stuffit',
|
||||
'tar' => 'application/x-tar',
|
||||
'tgz' => array('application/x-tar', 'application/x-gzip-compressed'),
|
||||
'z' => 'application/x-compress',
|
||||
'xhtml' => 'application/xhtml+xml',
|
||||
'xht' => 'application/xhtml+xml',
|
||||
'zip' => array('application/x-zip', 'application/zip', 'application/x-zip-compressed', 'application/s-compressed', 'multipart/x-zip'),
|
||||
'rar' => array('application/x-rar', 'application/rar', 'application/x-rar-compressed'),
|
||||
'mid' => 'audio/midi',
|
||||
'midi' => 'audio/midi',
|
||||
'mpga' => 'audio/mpeg',
|
||||
'mp2' => 'audio/mpeg',
|
||||
'mp3' => array('audio/mpeg', 'audio/mpg', 'audio/mpeg3', 'audio/mp3'),
|
||||
'aif' => array('audio/x-aiff', 'audio/aiff'),
|
||||
'aiff' => array('audio/x-aiff', 'audio/aiff'),
|
||||
'aifc' => 'audio/x-aiff',
|
||||
'ram' => 'audio/x-pn-realaudio',
|
||||
'rm' => 'audio/x-pn-realaudio',
|
||||
'rpm' => 'audio/x-pn-realaudio-plugin',
|
||||
'ra' => 'audio/x-realaudio',
|
||||
'rv' => 'video/vnd.rn-realvideo',
|
||||
'wav' => array('audio/x-wav', 'audio/wave', 'audio/wav'),
|
||||
'bmp' => array('image/bmp', 'image/x-bmp', 'image/x-bitmap', 'image/x-xbitmap', 'image/x-win-bitmap', 'image/x-windows-bmp', 'image/ms-bmp', 'image/x-ms-bmp', 'application/bmp', 'application/x-bmp', 'application/x-win-bitmap'),
|
||||
'gif' => 'image/gif',
|
||||
'jpeg' => array('image/jpeg', 'image/pjpeg'),
|
||||
'jpg' => array('image/jpeg', 'image/pjpeg'),
|
||||
'jpe' => array('image/jpeg', 'image/pjpeg'),
|
||||
'jp2' => array('image/jp2', 'video/mj2', 'image/jpx', 'image/jpm'),
|
||||
'j2k' => array('image/jp2', 'video/mj2', 'image/jpx', 'image/jpm'),
|
||||
'jpf' => array('image/jp2', 'video/mj2', 'image/jpx', 'image/jpm'),
|
||||
'jpg2' => array('image/jp2', 'video/mj2', 'image/jpx', 'image/jpm'),
|
||||
'jpx' => array('image/jp2', 'video/mj2', 'image/jpx', 'image/jpm'),
|
||||
'jpm' => array('image/jp2', 'video/mj2', 'image/jpx', 'image/jpm'),
|
||||
'mj2' => array('image/jp2', 'video/mj2', 'image/jpx', 'image/jpm'),
|
||||
'mjp2' => array('image/jp2', 'video/mj2', 'image/jpx', 'image/jpm'),
|
||||
'png' => array('image/png', 'image/x-png'),
|
||||
'tiff' => 'image/tiff',
|
||||
'tif' => 'image/tiff',
|
||||
'css' => array('text/css', 'text/plain'),
|
||||
'html' => array('text/html', 'text/plain'),
|
||||
'htm' => array('text/html', 'text/plain'),
|
||||
'shtml' => array('text/html', 'text/plain'),
|
||||
'txt' => 'text/plain',
|
||||
'text' => 'text/plain',
|
||||
'log' => array('text/plain', 'text/x-log'),
|
||||
'rtx' => 'text/richtext',
|
||||
'rtf' => 'text/rtf',
|
||||
'xml' => array('application/xml', 'text/xml', 'text/plain'),
|
||||
'xsl' => array('application/xml', 'text/xsl', 'text/xml'),
|
||||
'mpeg' => 'video/mpeg',
|
||||
'mpg' => 'video/mpeg',
|
||||
'mpe' => 'video/mpeg',
|
||||
'qt' => 'video/quicktime',
|
||||
'mov' => 'video/quicktime',
|
||||
'avi' => array('video/x-msvideo', 'video/msvideo', 'video/avi', 'application/x-troff-msvideo'),
|
||||
'movie' => 'video/x-sgi-movie',
|
||||
'doc' => array('application/msword', 'application/vnd.ms-office'),
|
||||
'docx' => array('application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'application/zip', 'application/msword', 'application/x-zip'),
|
||||
'dot' => array('application/msword', 'application/vnd.ms-office'),
|
||||
'dotx' => array('application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'application/zip', 'application/msword'),
|
||||
'xlsx' => array('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/zip', 'application/vnd.ms-excel', 'application/msword', 'application/x-zip'),
|
||||
'word' => array('application/msword', 'application/octet-stream'),
|
||||
'xl' => 'application/excel',
|
||||
'eml' => 'message/rfc822',
|
||||
'json' => array('application/json', 'text/json'),
|
||||
'pem' => array('application/x-x509-user-cert', 'application/x-pem-file', 'application/octet-stream'),
|
||||
'p10' => array('application/x-pkcs10', 'application/pkcs10'),
|
||||
'p12' => 'application/x-pkcs12',
|
||||
'p7a' => 'application/x-pkcs7-signature',
|
||||
'p7c' => array('application/pkcs7-mime', 'application/x-pkcs7-mime'),
|
||||
'p7m' => array('application/pkcs7-mime', 'application/x-pkcs7-mime'),
|
||||
'p7r' => 'application/x-pkcs7-certreqresp',
|
||||
'p7s' => 'application/pkcs7-signature',
|
||||
'crt' => array('application/x-x509-ca-cert', 'application/x-x509-user-cert', 'application/pkix-cert'),
|
||||
'crl' => array('application/pkix-crl', 'application/pkcs-crl'),
|
||||
'der' => 'application/x-x509-ca-cert',
|
||||
'kdb' => 'application/octet-stream',
|
||||
'pgp' => 'application/pgp',
|
||||
'gpg' => 'application/gpg-keys',
|
||||
'sst' => 'application/octet-stream',
|
||||
'csr' => 'application/octet-stream',
|
||||
'rsa' => 'application/x-pkcs7',
|
||||
'cer' => array('application/pkix-cert', 'application/x-x509-ca-cert'),
|
||||
'3g2' => 'video/3gpp2',
|
||||
'3gp' => array('video/3gp', 'video/3gpp'),
|
||||
'mp4' => 'video/mp4',
|
||||
'm4a' => 'audio/x-m4a',
|
||||
'f4v' => array('video/mp4', 'video/x-f4v'),
|
||||
'flv' => 'video/x-flv',
|
||||
'webm' => 'video/webm',
|
||||
'aac' => 'audio/x-acc',
|
||||
'm4u' => 'application/vnd.mpegurl',
|
||||
'm3u' => 'text/plain',
|
||||
'xspf' => 'application/xspf+xml',
|
||||
'vlc' => 'application/videolan',
|
||||
'wmv' => array('video/x-ms-wmv', 'video/x-ms-asf'),
|
||||
'au' => 'audio/x-au',
|
||||
'ac3' => 'audio/ac3',
|
||||
'flac' => 'audio/x-flac',
|
||||
'ogg' => array('audio/ogg', 'video/ogg', 'application/ogg'),
|
||||
'kmz' => array('application/vnd.google-earth.kmz', 'application/zip', 'application/x-zip'),
|
||||
'kml' => array('application/vnd.google-earth.kml+xml', 'application/xml', 'text/xml'),
|
||||
'ics' => 'text/calendar',
|
||||
'ical' => 'text/calendar',
|
||||
'zsh' => 'text/x-scriptzsh',
|
||||
'7zip' => array('application/x-compressed', 'application/x-zip-compressed', 'application/zip', 'multipart/x-zip'),
|
||||
'cdr' => array('application/cdr', 'application/coreldraw', 'application/x-cdr', 'application/x-coreldraw', 'image/cdr', 'image/x-cdr', 'zz-application/zz-winassoc-cdr'),
|
||||
'wma' => array('audio/x-ms-wma', 'video/x-ms-asf'),
|
||||
'jar' => array('application/java-archive', 'application/x-java-application', 'application/x-jar', 'application/x-compressed'),
|
||||
'svg' => array('image/svg+xml', 'application/xml', 'text/xml'),
|
||||
'vcf' => 'text/x-vcard',
|
||||
'srt' => array('text/srt', 'text/plain'),
|
||||
'vtt' => array('text/vtt', 'text/plain'),
|
||||
'ico' => array('image/x-icon', 'image/x-ico', 'image/vnd.microsoft.icon')
|
||||
);
|
|
@ -1,50 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks Application Skeleton.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2016 TechFuze
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2018, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 1.1.1
|
||||
*
|
||||
* @version Version 1.1.4
|
||||
*/
|
||||
|
||||
/**
|
||||
* Possible values:
|
||||
* Default callable: Adds a route that changes the URL structure. Sends all matches to the defaultCallable router
|
||||
* 'routingString'
|
||||
*
|
||||
* Custom callable: Adds a route that sends all matches to the provided callable. Allows user to replace defaultCallable
|
||||
* 'routingString' => array('callable' => array(CALLABLE))
|
||||
*
|
||||
* Dynamic rewrite: Adds a route that rewrites an URL to a specific controller and method configuration, using a callable. The callable can dynamically determine which page to load.
|
||||
* 'routingString' => CALLABLE
|
||||
*
|
||||
* Static rewrite: Adds a route that rewrites and URL to a specific controller and method using a fixed route. This allows for pre-determined rewrites of pages.
|
||||
* 'routingString' => 'standard/index'
|
||||
*
|
||||
* Example routingString: '/^(?P<controller>.*?)(|\/(?P<function>.*?)(|\/(?P<parameters>.*?)))$/'
|
||||
*/
|
||||
return array(
|
||||
);
|
|
@ -1,131 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks Application Skeleton.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2016 TechFuze
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 1.1.1
|
||||
*
|
||||
* @version Version 1.1.1
|
||||
*/
|
||||
|
||||
return array(
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Enable Query Strings
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| By default CodeIgniter uses search-engine friendly segment based URLs:
|
||||
| example.com/who/what/where/
|
||||
|
|
||||
| By default CodeIgniter enables access to the $_GET array. If for some
|
||||
| reason you would like to disable it, set 'allow_get_array' to FALSE.
|
||||
|
|
||||
| You can optionally enable standard query string based URLs:
|
||||
| example.com?who=me&what=something&where=here
|
||||
|
|
||||
| Options are: TRUE or FALSE (boolean)
|
||||
|
|
||||
| The other items let you set the query string 'words' that will
|
||||
| invoke your controllers and its functions:
|
||||
| example.com/index.php?c=controller&m=function
|
||||
|
|
||||
| Please note that some of the helpers won't work as expected when
|
||||
| this feature is enabled, since CodeIgniter is designed primarily to
|
||||
| use segment based URLs.
|
||||
|
|
||||
*/
|
||||
'allow_get_array' => TRUE,
|
||||
'enable_query_strings' => FALSE,
|
||||
'controller_trigger' => 'c',
|
||||
'function_trigger' => 'm',
|
||||
'directory_trigger' => 'd',
|
||||
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Allowed URL Characters
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This lets you specify which characters are permitted within your URLs.
|
||||
| When someone tries to submit a URL with disallowed characters they will
|
||||
| get a warning message.
|
||||
|
|
||||
| As a security measure you are STRONGLY encouraged to restrict URLs to
|
||||
| as few characters as possible. By default only these are allowed: a-z 0-9~%.:_-
|
||||
|
|
||||
| Leave blank to allow all characters -- but only if you are insane.
|
||||
|
|
||||
| The configured value is actually a regular expression character group
|
||||
| and it will be executed as: ! preg_match('/^[<permitted_uri_chars>]+$/i
|
||||
|
|
||||
| DO NOT CHANGE THIS UNLESS YOU FULLY UNDERSTAND THE REPERCUSSIONS!!
|
||||
|
|
||||
*/
|
||||
'permitted_uri_chars' => 'a-z 0-9~%.:_\-',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Translate URI Dashes
|
||||
|--------------------------------------------------------------------------
|
||||
| Determines whether dashes in controller & method segments
|
||||
| should be automatically replaced by underscores.
|
||||
|
|
||||
*/
|
||||
'translate_uri_dashes' => FALSE,
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| URI PROTOCOL
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This item determines which server global should be used to retrieve the
|
||||
| URI string. The default setting of 'REQUEST_URI' works for most servers.
|
||||
| If your links do not seem to work, try one of the other delicious flavors:
|
||||
|
|
||||
| 'REQUEST_URI' Uses $_SERVER['REQUEST_URI']
|
||||
| 'QUERY_STRING' Uses $_SERVER['QUERY_STRING']
|
||||
| 'PATH_INFO' Uses $_SERVER['PATH_INFO']
|
||||
|
|
||||
| WARNING: If you set this to 'PATH_INFO', URIs will always be URL-decoded!
|
||||
*/
|
||||
'uri_protocol' => 'REQUEST_URI',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| URL suffix
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This option allows you to add a suffix to all URLs generated by CodeIgniter.
|
||||
| For more information please see the user guide:
|
||||
|
|
||||
| https://codeigniter.com/user_guide/general/urls.html
|
||||
*/
|
||||
'url_suffix' => '',
|
||||
|
||||
'default_controller' => 'standard',
|
||||
'default_function' => 'index',
|
||||
|
||||
);
|
|
@ -1,102 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks Application Skeleton.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2016 TechFuze
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 1.1.1
|
||||
*
|
||||
* @version Version 1.1.1
|
||||
*/
|
||||
|
||||
return array(
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Cross Site Request Forgery
|
||||
|--------------------------------------------------------------------------
|
||||
| Enables a CSRF cookie token to be set. When set to TRUE, token will be
|
||||
| checked on a submitted form. If you are accepting user data, it is strongly
|
||||
| recommended CSRF protection be enabled.
|
||||
|
|
||||
| 'csrf_token_name' = The token name
|
||||
| 'csrf_cookie_name' = The cookie name
|
||||
| 'csrf_expire' = The number in seconds the token should expire.
|
||||
| 'csrf_regenerate' = Regenerate token on every submission
|
||||
| 'csrf_exclude_uris' = Array of URIs which ignore CSRF checks
|
||||
*/
|
||||
'csrf_protection' => true,
|
||||
'csrf_token_name' => 'fw_csrf_token',
|
||||
'csrf_cookie_name' => 'fw_csrf_cookie',
|
||||
'csrf_expire' => 7200,
|
||||
'csrf_regenerate' => TRUE,
|
||||
'csrf_exclude_uris' => array(),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Standardize newlines
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Determines whether to standardize newline characters in input data,
|
||||
| meaning to replace \r\n, \r, \n occurrences with the PHP_EOL value.
|
||||
|
|
||||
| This is particularly useful for portability between UNIX-based OSes,
|
||||
| (usually \n) and Windows (\r\n).
|
||||
|
|
||||
*/
|
||||
'standardize_newlines' => FALSE,
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Global XSS Filtering
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Determines whether the XSS filter is always active when GET, POST or
|
||||
| COOKIE data is encountered
|
||||
|
|
||||
| WARNING: This feature is DEPRECATED and currently available only
|
||||
| for backwards compatibility purposes!
|
||||
|
|
||||
*/
|
||||
'global_xss_filtering' => FALSE,
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Reverse Proxy IPs
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| If your server is behind a reverse proxy, you must whitelist the proxy
|
||||
| IP addresses from which CodeIgniter should trust headers such as
|
||||
| HTTP_X_FORWARDED_FOR and HTTP_CLIENT_IP in order to properly identify
|
||||
| the visitor's IP address.
|
||||
|
|
||||
| You can use both an array or a comma-separated list of proxy addresses,
|
||||
| as well as specifying whole subnets. Here are a few examples:
|
||||
|
|
||||
| Comma-separated: '10.0.1.200,192.168.5.0/24'
|
||||
| Array: array('10.0.1.200', '192.168.5.0/24')
|
||||
*/
|
||||
'proxy_ips' => ''
|
||||
|
||||
);
|
|
@ -1,201 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2015 TechFuze
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 1.0.0
|
||||
*/
|
||||
|
||||
use FuzeWorks\Factory;
|
||||
use FuzeWorks\Database;
|
||||
use FuzeWorks\Exception\DatabaseException;
|
||||
use FuzeWorks\Core;
|
||||
|
||||
/**
|
||||
* Initialize the database
|
||||
*
|
||||
* Converted from CodeIgniter.
|
||||
*
|
||||
* @package FuzeWorks
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
*
|
||||
* @param string|string[] $params
|
||||
* @param bool $query_builder_override
|
||||
* Determines if query builder should be used or not
|
||||
*/
|
||||
function &DB($params = '', $query_builder_override = NULL)
|
||||
{
|
||||
// Load the DB config file if a DSN string wasn't passed
|
||||
if (is_string($params) && strpos($params, '://') === FALSE)
|
||||
{
|
||||
// First retrieve the config file
|
||||
try {
|
||||
$config = Factory::getInstance()->config->get('database');
|
||||
} catch (ConfigException $e) {
|
||||
throw new DatabaseException($e->getMessage(), 1);
|
||||
}
|
||||
|
||||
// Determine if there are actually settings in the config file
|
||||
if ( ! isset($config->databases) OR count($config->databases) === 0)
|
||||
{
|
||||
throw new DatabaseException('No database connection settings were found in the database config file.', 1);
|
||||
}
|
||||
|
||||
// Define the active group
|
||||
$active_group = ($params !== '' ? $params : $config->active_group);
|
||||
|
||||
if ( ! isset($active_group))
|
||||
{
|
||||
throw new DatabaseException('You have not specified a database connection group via $active_group in your config.database.php file.', 1);
|
||||
}
|
||||
elseif ( ! isset($config->databases[$active_group]))
|
||||
{
|
||||
throw new DatabaseException('You have specified an invalid database connection group ('.$active_group.') in your config.database.php file.', 1);
|
||||
}
|
||||
|
||||
$params = $config->databases[$active_group];
|
||||
}
|
||||
elseif (is_string($params))
|
||||
{
|
||||
/**
|
||||
* Parse the URL from the DSN string
|
||||
* Database settings can be passed as discreet
|
||||
* parameters or as a data source name in the first
|
||||
* parameter. DSNs must have this prototype:
|
||||
* $dsn = 'driver://username:password@hostname/database';
|
||||
*/
|
||||
if (($dsn = @parse_url($params)) === FALSE)
|
||||
{
|
||||
throw new DatabaseException('Invalid DB Connection String', 1);
|
||||
}
|
||||
|
||||
$params = array(
|
||||
'dbdriver' => $dsn['scheme'],
|
||||
'hostname' => isset($dsn['host']) ? rawurldecode($dsn['host']) : '',
|
||||
'port' => isset($dsn['port']) ? rawurldecode($dsn['port']) : '',
|
||||
'username' => isset($dsn['user']) ? rawurldecode($dsn['user']) : '',
|
||||
'password' => isset($dsn['pass']) ? rawurldecode($dsn['pass']) : '',
|
||||
'database' => isset($dsn['path']) ? rawurldecode(substr($dsn['path'], 1)) : ''
|
||||
);
|
||||
|
||||
// Were additional config items set?
|
||||
if (isset($dsn['query']))
|
||||
{
|
||||
parse_str($dsn['query'], $extra);
|
||||
|
||||
foreach ($extra as $key => $val)
|
||||
{
|
||||
if (is_string($val) && in_array(strtoupper($val), array('TRUE', 'FALSE', 'NULL')))
|
||||
{
|
||||
$val = var_export($val, TRUE);
|
||||
}
|
||||
|
||||
$params[$key] = $val;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// No DB specified yet? Beat them senseless...
|
||||
if (empty($params['dbdriver']))
|
||||
{
|
||||
throw new DatabaseException('You have not selected a database type to connect to.', 1);
|
||||
}
|
||||
|
||||
// Load the DB classes. Note: Since the query builder class is optional
|
||||
// we need to dynamically create a class that extends proper parent class
|
||||
// based on whether we're using the query builder class or not.
|
||||
if ($query_builder_override !== NULL)
|
||||
{
|
||||
$query_builder = $query_builder_override;
|
||||
}
|
||||
// Backwards compatibility work-around for keeping the
|
||||
// $active_record config variable working. Should be
|
||||
// removed in v3.1
|
||||
elseif ( ! isset($query_builder) && isset($active_record))
|
||||
{
|
||||
$query_builder = $active_record;
|
||||
}
|
||||
|
||||
require_once(Core::$coreDir . DS . 'Database'.DS.'DB_driver.php');
|
||||
|
||||
if ( ! isset($query_builder) OR $query_builder === TRUE)
|
||||
{
|
||||
require_once(Core::$coreDir . DS . 'Database'.DS.'DB_query_builder.php');
|
||||
if ( ! class_exists('FW_DB', FALSE))
|
||||
{
|
||||
/**
|
||||
* FW_DB
|
||||
*
|
||||
* Acts as an alias for both FW_DB_driver and FW_DB_query_builder.
|
||||
*
|
||||
* @see FW_DB_query_builder
|
||||
* @see FW_DB_driver
|
||||
*/
|
||||
class FW_DB extends FW_DB_query_builder { }
|
||||
}
|
||||
}
|
||||
elseif ( ! class_exists('FW_DB', FALSE))
|
||||
{
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
class FW_DB extends FW_DB_driver { }
|
||||
}
|
||||
|
||||
// Load the DB driver
|
||||
$driver_file = Core::$coreDir . DS . 'Database'.DS.'drivers'.DS.$params['dbdriver'].DS.$params['dbdriver'].'_driver.php';
|
||||
|
||||
if (!file_exists($driver_file))
|
||||
{
|
||||
throw new DatabaseException("Invalid DB Driver", 1);
|
||||
}
|
||||
|
||||
require_once($driver_file);
|
||||
|
||||
// Instantiate the DB adapter
|
||||
$driver = 'FW_DB_'.$params['dbdriver'].'_driver';
|
||||
$DB = new $driver($params);
|
||||
|
||||
// Check for a subdriver
|
||||
if ( ! empty($DB->subdriver))
|
||||
{
|
||||
$driver_file = Core::$coreDir . DS . 'Database'.DS.'drivers'.DS.$DB->dbdriver.DS.'subdrivers'.DS.$DB->dbdriver.'_'.$DB->subdriver.'_driver.php';
|
||||
|
||||
if (file_exists($driver_file))
|
||||
{
|
||||
require_once($driver_file);
|
||||
$driver = 'FW_DB_'.$DB->dbdriver.'_'.$DB->subdriver.'_driver';
|
||||
$DB = new $driver($params);
|
||||
}
|
||||
}
|
||||
|
||||
$DB->initialize();
|
||||
return $DB;
|
||||
}
|
|
@ -1,216 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2015 TechFuze
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 1.0.0
|
||||
*/
|
||||
|
||||
use FuzeWorks\Logger;
|
||||
use Fuzeworks\Factory;
|
||||
use FuzeWorks\Core;
|
||||
|
||||
/**
|
||||
* Database Cache Class
|
||||
*
|
||||
* Converted from CodeIgniter.
|
||||
*
|
||||
* @package FuzeWorks
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
*/
|
||||
class FW_DB_Cache {
|
||||
|
||||
/**
|
||||
* Database object
|
||||
*
|
||||
* Allows passing of DB object so that multiple database connections
|
||||
* and returned DB objects can be supported.
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
public $db;
|
||||
|
||||
/**
|
||||
* The FuzeWorks factory class
|
||||
*
|
||||
* @var Fuzeworks\Factory;
|
||||
*/
|
||||
private $factory;
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param object &$db
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(&$db)
|
||||
{
|
||||
$this->db =& $db;
|
||||
$this->factory = Factory::getInstance();
|
||||
$this->factory->helpers->load('file');
|
||||
|
||||
$this->check_path();
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Set Cache Directory Path
|
||||
*
|
||||
* @param string $path Path to the cache directory
|
||||
* @return bool
|
||||
*/
|
||||
public function check_path($path = '')
|
||||
{
|
||||
$path = ($path === '' ? Core::$tempDir . DS . 'Database' : $path);
|
||||
|
||||
// Add a trailing slash to the path if needed
|
||||
$path = realpath($path)
|
||||
? rtrim(realpath($path), DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR
|
||||
: rtrim($path, '/').'/';
|
||||
|
||||
if ( ! is_dir($path))
|
||||
{
|
||||
if (!mkdir($path, 0777, false))
|
||||
{
|
||||
Logger::logDebug('DB cache path error: '.$path);
|
||||
|
||||
// If the path is wrong we'll turn off caching
|
||||
return $this->db->cache_off();
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! Core::isReallyWritable($path))
|
||||
{
|
||||
Logger::logDebug('DB cache dir not writable: '.$path);
|
||||
|
||||
// If the path is not really writable we'll turn off caching
|
||||
return $this->db->cache_off();
|
||||
}
|
||||
|
||||
$this->db->cachedir = $path;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Retrieve a cached query
|
||||
*
|
||||
* The URI being requested will become the name of the cache sub-folder.
|
||||
* An MD5 hash of the SQL statement will become the cache file name.
|
||||
*
|
||||
* @param string $sql
|
||||
* @return string
|
||||
*/
|
||||
public function read($sql)
|
||||
{
|
||||
$segment_one = ($this->factory->uri->segment(1) == FALSE) ? 'default' : $this->factory->uri->segment(1);
|
||||
$segment_two = ($this->factory->uri->segment(2) == FALSE) ? 'index' : $this->factory->uri->segment(2);
|
||||
$filepath = $this->db->cachedir.$segment_one.'+'.$segment_two.'/'.md5($sql);
|
||||
|
||||
if (FALSE === ($cachedata = @file_get_contents($filepath)))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return unserialize($cachedata);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Write a query to a cache file
|
||||
*
|
||||
* @param string $sql
|
||||
* @param object $object
|
||||
* @return bool
|
||||
*/
|
||||
public function write($sql, $object)
|
||||
{
|
||||
$segment_one = ($this->factory->uri->segment(1) == FALSE) ? 'default' : $this->factory->uri->segment(1);
|
||||
$segment_two = ($this->factory->uri->segment(2) == FALSE) ? 'index' : $this->factory->uri->segment(2);
|
||||
$dir_path = $this->db->cachedir.$segment_one.'+'.$segment_two.'/';
|
||||
$filename = md5($sql);
|
||||
|
||||
if ( ! is_dir($dir_path) && ! @mkdir($dir_path, 0750))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (write_file($dir_path.$filename, serialize($object)) === FALSE)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
chmod($dir_path.$filename, 0640);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Delete cache files within a particular directory
|
||||
*
|
||||
* @param string $segment_one
|
||||
* @param string $segment_two
|
||||
* @return void
|
||||
*/
|
||||
public function delete($segment_one = '', $segment_two = '')
|
||||
{
|
||||
if ($segment_one === '')
|
||||
{
|
||||
$segment_one = ($this->factory->uri->segment(1) == FALSE) ? 'default' : $this->factory->uri->segment(1);
|
||||
}
|
||||
|
||||
if ($segment_two === '')
|
||||
{
|
||||
$segment_two = ($this->factory->uri->segment(2) == FALSE) ? 'index' : $this->factory->uri->segment(2);
|
||||
}
|
||||
|
||||
$dir_path = $this->db->cachedir.$segment_one.'+'.$segment_two.'/';
|
||||
delete_files($dir_path, TRUE);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Delete all existing cache files
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function delete_all()
|
||||
{
|
||||
delete_files($this->db->cachedir, TRUE, TRUE);
|
||||
}
|
||||
|
||||
}
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -1,666 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2015 TechFuze
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 1.0.0
|
||||
*/
|
||||
|
||||
use FuzeWorks\Logger;
|
||||
use FuzeWorks\Exception\DatabaseException;
|
||||
|
||||
/**
|
||||
* Database Result Class
|
||||
*
|
||||
* This is the platform-independent result class.
|
||||
* This class will not be called directly. Rather, the adapter
|
||||
* class for the specific database will extend and instantiate it.
|
||||
*
|
||||
* Converted from CodeIgniter.
|
||||
*
|
||||
* @package FuzeWorks
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
*/
|
||||
class FW_DB_result {
|
||||
|
||||
/**
|
||||
* Connection ID
|
||||
*
|
||||
* @var resource|object
|
||||
*/
|
||||
public $conn_id;
|
||||
|
||||
/**
|
||||
* Result ID
|
||||
*
|
||||
* @var resource|object
|
||||
*/
|
||||
public $result_id;
|
||||
|
||||
/**
|
||||
* Result Array
|
||||
*
|
||||
* @var array[]
|
||||
*/
|
||||
public $result_array = array();
|
||||
|
||||
/**
|
||||
* Result Object
|
||||
*
|
||||
* @var object[]
|
||||
*/
|
||||
public $result_object = array();
|
||||
|
||||
/**
|
||||
* Custom Result Object
|
||||
*
|
||||
* @var object[]
|
||||
*/
|
||||
public $custom_result_object = array();
|
||||
|
||||
/**
|
||||
* Current Row index
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $current_row = 0;
|
||||
|
||||
/**
|
||||
* Number of rows
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $num_rows;
|
||||
|
||||
/**
|
||||
* Row data
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $row_data;
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param object $driver_object
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(&$driver_object)
|
||||
{
|
||||
$this->conn_id = $driver_object->conn_id;
|
||||
$this->result_id = $driver_object->result_id;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Number of rows in the result set
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function num_rows()
|
||||
{
|
||||
if (is_int($this->num_rows))
|
||||
{
|
||||
return $this->num_rows;
|
||||
}
|
||||
elseif (count($this->result_array) > 0)
|
||||
{
|
||||
return $this->num_rows = count($this->result_array);
|
||||
}
|
||||
elseif (count($this->result_object) > 0)
|
||||
{
|
||||
return $this->num_rows = count($this->result_object);
|
||||
}
|
||||
|
||||
return $this->num_rows = count($this->result_array());
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Query result. Acts as a wrapper function for the following functions.
|
||||
*
|
||||
* @param string $type 'object', 'array' or a custom class name
|
||||
* @return array
|
||||
*/
|
||||
public function result($type = 'object')
|
||||
{
|
||||
if ($type === 'array')
|
||||
{
|
||||
return $this->result_array();
|
||||
}
|
||||
elseif ($type === 'object')
|
||||
{
|
||||
return $this->result_object();
|
||||
}
|
||||
else
|
||||
{
|
||||
return $this->custom_result_object($type);
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Custom query result.
|
||||
*
|
||||
* @param string $class_name
|
||||
* @return array
|
||||
*/
|
||||
public function custom_result_object($class_name)
|
||||
{
|
||||
if (isset($this->custom_result_object[$class_name]))
|
||||
{
|
||||
return $this->custom_result_object[$class_name];
|
||||
}
|
||||
elseif ( ! $this->result_id OR $this->num_rows === 0)
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
// Don't fetch the result set again if we already have it
|
||||
$_data = NULL;
|
||||
if (($c = count($this->result_array)) > 0)
|
||||
{
|
||||
$_data = 'result_array';
|
||||
}
|
||||
elseif (($c = count($this->result_object)) > 0)
|
||||
{
|
||||
$_data = 'result_object';
|
||||
}
|
||||
|
||||
if ($_data !== NULL)
|
||||
{
|
||||
for ($i = 0; $i < $c; $i++)
|
||||
{
|
||||
$this->custom_result_object[$class_name][$i] = new $class_name();
|
||||
|
||||
foreach ($this->{$_data}[$i] as $key => $value)
|
||||
{
|
||||
$this->custom_result_object[$class_name][$i]->$key = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->custom_result_object[$class_name];
|
||||
}
|
||||
|
||||
is_null($this->row_data) OR $this->data_seek(0);
|
||||
$this->custom_result_object[$class_name] = array();
|
||||
|
||||
while ($row = $this->_fetch_object($class_name))
|
||||
{
|
||||
$this->custom_result_object[$class_name][] = $row;
|
||||
}
|
||||
|
||||
return $this->custom_result_object[$class_name];
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Query result. "object" version.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function result_object()
|
||||
{
|
||||
if (count($this->result_object) > 0)
|
||||
{
|
||||
return $this->result_object;
|
||||
}
|
||||
|
||||
// In the event that query caching is on, the result_id variable
|
||||
// will not be a valid resource so we'll simply return an empty
|
||||
// array.
|
||||
if ( ! $this->result_id OR $this->num_rows === 0)
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
if (($c = count($this->result_array)) > 0)
|
||||
{
|
||||
for ($i = 0; $i < $c; $i++)
|
||||
{
|
||||
$this->result_object[$i] = (object) $this->result_array[$i];
|
||||
}
|
||||
|
||||
return $this->result_object;
|
||||
}
|
||||
|
||||
is_null($this->row_data) OR $this->data_seek(0);
|
||||
while ($row = $this->_fetch_object())
|
||||
{
|
||||
$this->result_object[] = $row;
|
||||
}
|
||||
|
||||
return $this->result_object;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Query result. "array" version.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function result_array()
|
||||
{
|
||||
if (count($this->result_array) > 0)
|
||||
{
|
||||
return $this->result_array;
|
||||
}
|
||||
|
||||
// In the event that query caching is on, the result_id variable
|
||||
// will not be a valid resource so we'll simply return an empty
|
||||
// array.
|
||||
if ( ! $this->result_id OR $this->num_rows === 0)
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
if (($c = count($this->result_object)) > 0)
|
||||
{
|
||||
for ($i = 0; $i < $c; $i++)
|
||||
{
|
||||
$this->result_array[$i] = (array) $this->result_object[$i];
|
||||
}
|
||||
|
||||
return $this->result_array;
|
||||
}
|
||||
|
||||
is_null($this->row_data) OR $this->data_seek(0);
|
||||
while ($row = $this->_fetch_assoc())
|
||||
{
|
||||
$this->result_array[] = $row;
|
||||
}
|
||||
|
||||
return $this->result_array;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Row
|
||||
*
|
||||
* A wrapper method.
|
||||
*
|
||||
* @param mixed $n
|
||||
* @param string $type 'object' or 'array'
|
||||
* @return mixed
|
||||
*/
|
||||
public function row($n = 0, $type = 'object')
|
||||
{
|
||||
if ( ! is_numeric($n))
|
||||
{
|
||||
// We cache the row data for subsequent uses
|
||||
is_array($this->row_data) OR $this->row_data = $this->row_array(0);
|
||||
|
||||
// array_key_exists() instead of isset() to allow for NULL values
|
||||
if (empty($this->row_data) OR ! array_key_exists($n, $this->row_data))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return $this->row_data[$n];
|
||||
}
|
||||
|
||||
if ($type === 'object') return $this->row_object($n);
|
||||
elseif ($type === 'array') return $this->row_array($n);
|
||||
else return $this->custom_row_object($n, $type);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Assigns an item into a particular column slot
|
||||
*
|
||||
* @param mixed $key
|
||||
* @param mixed $value
|
||||
* @return void
|
||||
*/
|
||||
public function set_row($key, $value = NULL)
|
||||
{
|
||||
// We cache the row data for subsequent uses
|
||||
if ( ! is_array($this->row_data))
|
||||
{
|
||||
$this->row_data = $this->row_array(0);
|
||||
}
|
||||
|
||||
if (is_array($key))
|
||||
{
|
||||
foreach ($key as $k => $v)
|
||||
{
|
||||
$this->row_data[$k] = $v;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if ($key !== '' && $value !== NULL)
|
||||
{
|
||||
$this->row_data[$key] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Returns a single result row - custom object version
|
||||
*
|
||||
* @param int $n
|
||||
* @param string $type
|
||||
* @return object
|
||||
*/
|
||||
public function custom_row_object($n, $type)
|
||||
{
|
||||
isset($this->custom_result_object[$type]) OR $this->custom_result_object($type);
|
||||
|
||||
if (count($this->custom_result_object[$type]) === 0)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if ($n !== $this->current_row && isset($this->custom_result_object[$type][$n]))
|
||||
{
|
||||
$this->current_row = $n;
|
||||
}
|
||||
|
||||
return $this->custom_result_object[$type][$this->current_row];
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Returns a single result row - object version
|
||||
*
|
||||
* @param int $n
|
||||
* @return object
|
||||
*/
|
||||
public function row_object($n = 0)
|
||||
{
|
||||
$result = $this->result_object();
|
||||
if (count($result) === 0)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if ($n !== $this->current_row && isset($result[$n]))
|
||||
{
|
||||
$this->current_row = $n;
|
||||
}
|
||||
|
||||
return $result[$this->current_row];
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Returns a single result row - array version
|
||||
*
|
||||
* @param int $n
|
||||
* @return array
|
||||
*/
|
||||
public function row_array($n = 0)
|
||||
{
|
||||
$result = $this->result_array();
|
||||
if (count($result) === 0)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if ($n !== $this->current_row && isset($result[$n]))
|
||||
{
|
||||
$this->current_row = $n;
|
||||
}
|
||||
|
||||
return $result[$this->current_row];
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Returns the "first" row
|
||||
*
|
||||
* @param string $type
|
||||
* @return mixed
|
||||
*/
|
||||
public function first_row($type = 'object')
|
||||
{
|
||||
$result = $this->result($type);
|
||||
return (count($result) === 0) ? NULL : $result[0];
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Returns the "last" row
|
||||
*
|
||||
* @param string $type
|
||||
* @return mixed
|
||||
*/
|
||||
public function last_row($type = 'object')
|
||||
{
|
||||
$result = $this->result($type);
|
||||
return (count($result) === 0) ? NULL : $result[count($result) - 1];
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Returns the "next" row
|
||||
*
|
||||
* @param string $type
|
||||
* @return mixed
|
||||
*/
|
||||
public function next_row($type = 'object')
|
||||
{
|
||||
$result = $this->result($type);
|
||||
if (count($result) === 0)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return isset($result[$this->current_row + 1])
|
||||
? $result[++$this->current_row]
|
||||
: NULL;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Returns the "previous" row
|
||||
*
|
||||
* @param string $type
|
||||
* @return mixed
|
||||
*/
|
||||
public function previous_row($type = 'object')
|
||||
{
|
||||
$result = $this->result($type);
|
||||
if (count($result) === 0)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (isset($result[$this->current_row - 1]))
|
||||
{
|
||||
--$this->current_row;
|
||||
}
|
||||
return $result[$this->current_row];
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Returns an unbuffered row and move pointer to next row
|
||||
*
|
||||
* @param string $type 'array', 'object' or a custom class name
|
||||
* @return mixed
|
||||
*/
|
||||
public function unbuffered_row($type = 'object')
|
||||
{
|
||||
if ($type === 'array')
|
||||
{
|
||||
return $this->_fetch_assoc();
|
||||
}
|
||||
elseif ($type === 'object')
|
||||
{
|
||||
return $this->_fetch_object();
|
||||
}
|
||||
|
||||
return $this->_fetch_object($type);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* The following methods are normally overloaded by the identically named
|
||||
* methods in the platform-specific driver -- except when query caching
|
||||
* is used. When caching is enabled we do not load the other driver.
|
||||
* These functions are primarily here to prevent undefined function errors
|
||||
* when a cached result object is in use. They are not otherwise fully
|
||||
* operational due to the unavailability of the database resource IDs with
|
||||
* cached results.
|
||||
*/
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Number of fields in the result set
|
||||
*
|
||||
* Overridden by driver result classes.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function num_fields()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Fetch Field Names
|
||||
*
|
||||
* Generates an array of column names.
|
||||
*
|
||||
* Overridden by driver result classes.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function list_fields()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Field data
|
||||
*
|
||||
* Generates an array of objects containing field meta-data.
|
||||
*
|
||||
* Overridden by driver result classes.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function field_data()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Free the result
|
||||
*
|
||||
* Overridden by driver result classes.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function free_result()
|
||||
{
|
||||
$this->result_id = FALSE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Data Seek
|
||||
*
|
||||
* Moves the internal pointer to the desired offset. We call
|
||||
* this internally before fetching results to make sure the
|
||||
* result set starts at zero.
|
||||
*
|
||||
* Overridden by driver result classes.
|
||||
*
|
||||
* @param int $n
|
||||
* @return bool
|
||||
*/
|
||||
public function data_seek($n = 0)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Result - associative array
|
||||
*
|
||||
* Returns the result set as an array.
|
||||
*
|
||||
* Overridden by driver result classes.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function _fetch_assoc()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Result - object
|
||||
*
|
||||
* Returns the result set as an object.
|
||||
*
|
||||
* Overridden by driver result classes.
|
||||
*
|
||||
* @param string $class_name
|
||||
* @return object
|
||||
*/
|
||||
protected function _fetch_object($class_name = 'stdClass')
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,434 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2015 TechFuze
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 1.0.0
|
||||
*/
|
||||
|
||||
use FuzeWorks\Logger;
|
||||
use FuzeWorks\Helpers;
|
||||
use FuzeWorks\Libraries;
|
||||
use Fuzeworks\Factory;
|
||||
use FuzeWorks\Exception\DatabaseException;
|
||||
|
||||
/**
|
||||
* Database Utility Class
|
||||
*
|
||||
* Converted from CodeIgniter.
|
||||
*
|
||||
* @package FuzeWorks
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
*/
|
||||
abstract class FW_DB_utility {
|
||||
|
||||
/**
|
||||
* Database object
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
protected $db;
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* List databases statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_list_databases = FALSE;
|
||||
|
||||
/**
|
||||
* OPTIMIZE TABLE statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_optimize_table = FALSE;
|
||||
|
||||
/**
|
||||
* REPAIR TABLE statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_repair_table = FALSE;
|
||||
|
||||
/**
|
||||
* The FuzeWorks factory class
|
||||
*
|
||||
* @var Fuzeworks\Factory;
|
||||
*/
|
||||
private $factory;
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param object &$db Database object
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(&$db)
|
||||
{
|
||||
$this->db =& $db;
|
||||
$this->factory = Factory::getInstance();
|
||||
Logger::log('Database Utility Class Initialized');
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* List databases
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function list_databases()
|
||||
{
|
||||
// Is there a cached result?
|
||||
if (isset($this->db->data_cache['db_names']))
|
||||
{
|
||||
return $this->db->data_cache['db_names'];
|
||||
}
|
||||
elseif ($this->_list_databases === FALSE)
|
||||
{
|
||||
return ($this->db->db_debug) ? $this->db->display_error('db_unsupported_feature') : FALSE;
|
||||
}
|
||||
|
||||
$this->db->data_cache['db_names'] = array();
|
||||
|
||||
$query = $this->db->query($this->_list_databases);
|
||||
if ($query === FALSE)
|
||||
{
|
||||
return $this->db->data_cache['db_names'];
|
||||
}
|
||||
|
||||
for ($i = 0, $query = $query->result_array(), $c = count($query); $i < $c; $i++)
|
||||
{
|
||||
$this->db->data_cache['db_names'][] = current($query[$i]);
|
||||
}
|
||||
|
||||
return $this->db->data_cache['db_names'];
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Determine if a particular database exists
|
||||
*
|
||||
* @param string $database_name
|
||||
* @return bool
|
||||
*/
|
||||
public function database_exists($database_name)
|
||||
{
|
||||
return in_array($database_name, $this->list_databases());
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Optimize Table
|
||||
*
|
||||
* @param string $table_name
|
||||
* @return mixed
|
||||
*/
|
||||
public function optimize_table($table_name)
|
||||
{
|
||||
if ($this->_optimize_table === FALSE)
|
||||
{
|
||||
return ($this->db->db_debug) ? $this->db->display_error('db_unsupported_feature') : FALSE;
|
||||
}
|
||||
|
||||
$query = $this->db->query(sprintf($this->_optimize_table, $this->db->escape_identifiers($table_name)));
|
||||
if ($query !== FALSE)
|
||||
{
|
||||
$query = $query->result_array();
|
||||
return current($query);
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Optimize Database
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function optimize_database()
|
||||
{
|
||||
if ($this->_optimize_table === FALSE)
|
||||
{
|
||||
return ($this->db->db_debug) ? $this->db->display_error('db_unsupported_feature') : FALSE;
|
||||
}
|
||||
|
||||
$result = array();
|
||||
foreach ($this->db->list_tables() as $table_name)
|
||||
{
|
||||
$res = $this->db->query(sprintf($this->_optimize_table, $this->db->escape_identifiers($table_name)));
|
||||
if (is_bool($res))
|
||||
{
|
||||
return $res;
|
||||
}
|
||||
|
||||
// Build the result array...
|
||||
$res = $res->result_array();
|
||||
$res = current($res);
|
||||
$key = str_replace($this->db->database.'.', '', current($res));
|
||||
$keys = array_keys($res);
|
||||
unset($res[$keys[0]]);
|
||||
|
||||
$result[$key] = $res;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Repair Table
|
||||
*
|
||||
* @param string $table_name
|
||||
* @return mixed
|
||||
*/
|
||||
public function repair_table($table_name)
|
||||
{
|
||||
if ($this->_repair_table === FALSE)
|
||||
{
|
||||
return ($this->db->db_debug) ? $this->db->display_error('db_unsupported_feature') : FALSE;
|
||||
}
|
||||
|
||||
$query = $this->db->query(sprintf($this->_repair_table, $this->db->escape_identifiers($table_name)));
|
||||
if (is_bool($query))
|
||||
{
|
||||
return $query;
|
||||
}
|
||||
|
||||
$query = $query->result_array();
|
||||
return current($query);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Generate CSV from a query result object
|
||||
*
|
||||
* @param object $query Query result object
|
||||
* @param string $delim Delimiter (default: ,)
|
||||
* @param string $newline Newline character (default: \n)
|
||||
* @param string $enclosure Enclosure (default: ")
|
||||
* @return string
|
||||
*/
|
||||
public function csv_from_result($query, $delim = ',', $newline = "\n", $enclosure = '"')
|
||||
{
|
||||
if ( ! is_object($query) OR ! method_exists($query, 'list_fields'))
|
||||
{
|
||||
throw new DatabaseException('You must submit a valid result object', 1);
|
||||
}
|
||||
|
||||
$out = '';
|
||||
// First generate the headings from the table column names
|
||||
foreach ($query->list_fields() as $name)
|
||||
{
|
||||
$out .= $enclosure.str_replace($enclosure, $enclosure.$enclosure, $name).$enclosure.$delim;
|
||||
}
|
||||
|
||||
$out = substr($out, 0, -strlen($delim)).$newline;
|
||||
|
||||
// Next blast through the result array and build out the rows
|
||||
while ($row = $query->unbuffered_row('array'))
|
||||
{
|
||||
$line = array();
|
||||
foreach ($row as $item)
|
||||
{
|
||||
$line[] = $enclosure.str_replace($enclosure, $enclosure.$enclosure, $item).$enclosure;
|
||||
}
|
||||
$out .= implode($delim, $line).$newline;
|
||||
}
|
||||
|
||||
return $out;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Generate XML data from a query result object
|
||||
*
|
||||
* @param object $query Query result object
|
||||
* @param array $params Any preferences
|
||||
* @return string
|
||||
*/
|
||||
public function xml_from_result($query, $params = array())
|
||||
{
|
||||
if ( ! is_object($query) OR ! method_exists($query, 'list_fields'))
|
||||
{
|
||||
throw new DatabaseException('You must submit a valid result object', 1);
|
||||
}
|
||||
|
||||
// Set our default values
|
||||
foreach (array('root' => 'root', 'element' => 'element', 'newline' => "\n", 'tab' => "\t") as $key => $val)
|
||||
{
|
||||
if ( ! isset($params[$key]))
|
||||
{
|
||||
$params[$key] = $val;
|
||||
}
|
||||
}
|
||||
|
||||
// Create variables for convenience
|
||||
extract($params);
|
||||
|
||||
// Load the xml helper
|
||||
$this->factory->helpers->load('xml');
|
||||
|
||||
// Generate the result
|
||||
$xml = '<'.$root.'>'.$newline;
|
||||
while ($row = $query->unbuffered_row())
|
||||
{
|
||||
$xml .= $tab.'<'.$element.'>'.$newline;
|
||||
foreach ($row as $key => $val)
|
||||
{
|
||||
$xml .= $tab.$tab.'<'.$key.'>'.xml_convert($val).'</'.$key.'>'.$newline;
|
||||
}
|
||||
$xml .= $tab.'</'.$element.'>'.$newline;
|
||||
}
|
||||
|
||||
return $xml.'</'.$root.'>'.$newline;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Database Backup
|
||||
*
|
||||
* @param array $params
|
||||
* @return string
|
||||
*/
|
||||
public function backup($params = array())
|
||||
{
|
||||
// If the parameters have not been submitted as an
|
||||
// array then we know that it is simply the table
|
||||
// name, which is a valid short cut.
|
||||
if (is_string($params))
|
||||
{
|
||||
$params = array('tables' => $params);
|
||||
}
|
||||
|
||||
// Set up our default preferences
|
||||
$prefs = array(
|
||||
'tables' => array(),
|
||||
'ignore' => array(),
|
||||
'filename' => '',
|
||||
'format' => 'gzip', // gzip, zip, txt
|
||||
'add_drop' => TRUE,
|
||||
'add_insert' => TRUE,
|
||||
'newline' => "\n",
|
||||
'foreign_key_checks' => TRUE
|
||||
);
|
||||
|
||||
// Did the user submit any preferences? If so set them....
|
||||
if (count($params) > 0)
|
||||
{
|
||||
foreach ($prefs as $key => $val)
|
||||
{
|
||||
if (isset($params[$key]))
|
||||
{
|
||||
$prefs[$key] = $params[$key];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Are we backing up a complete database or individual tables?
|
||||
// If no table names were submitted we'll fetch the entire table list
|
||||
if (count($prefs['tables']) === 0)
|
||||
{
|
||||
$prefs['tables'] = $this->db->list_tables();
|
||||
}
|
||||
|
||||
// Validate the format
|
||||
if ( ! in_array($prefs['format'], array('gzip', 'zip', 'txt'), TRUE))
|
||||
{
|
||||
$prefs['format'] = 'txt';
|
||||
}
|
||||
|
||||
// Is the encoder supported? If not, we'll either issue an
|
||||
// error or use plain text depending on the debug settings
|
||||
if (($prefs['format'] === 'gzip' && ! function_exists('gzencode'))
|
||||
OR ($prefs['format'] === 'zip' && ! function_exists('gzcompress')))
|
||||
{
|
||||
if ($this->db->db_debug)
|
||||
{
|
||||
return $this->db->display_error('db_unsupported_compression');
|
||||
}
|
||||
|
||||
$prefs['format'] = 'txt';
|
||||
}
|
||||
|
||||
// Was a Zip file requested?
|
||||
if ($prefs['format'] === 'zip')
|
||||
{
|
||||
// Set the filename if not provided (only needed with Zip files)
|
||||
if ($prefs['filename'] === '')
|
||||
{
|
||||
$prefs['filename'] = (count($prefs['tables']) === 1 ? $prefs['tables'] : $this->db->database)
|
||||
.date('Y-m-d_H-i', time()).'.sql';
|
||||
}
|
||||
else
|
||||
{
|
||||
// If they included the .zip file extension we'll remove it
|
||||
if (preg_match('|.+?\.zip$|', $prefs['filename']))
|
||||
{
|
||||
$prefs['filename'] = str_replace('.zip', '', $prefs['filename']);
|
||||
}
|
||||
|
||||
// Tack on the ".sql" file extension if needed
|
||||
if ( ! preg_match('|.+?\.sql$|', $prefs['filename']))
|
||||
{
|
||||
$prefs['filename'] .= '.sql';
|
||||
}
|
||||
}
|
||||
|
||||
// Load the Zip class and output it
|
||||
$zip = Libraries::get('zip');
|
||||
$zip->add_data($prefs['filename'], $this->_backup($prefs));
|
||||
return $zip->get_zip();
|
||||
}
|
||||
elseif ($prefs['format'] === 'txt') // Was a text file requested?
|
||||
{
|
||||
return $this->_backup($prefs);
|
||||
}
|
||||
elseif ($prefs['format'] === 'gzip') // Was a Gzip file requested?
|
||||
{
|
||||
return gzencode($this->_backup($prefs));
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,401 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2015 TechFuze
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 1.0.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* CUBRID Database Adapter Class
|
||||
*
|
||||
* Note: _DB is an extender class that the app controller
|
||||
* creates dynamically based on whether the query builder
|
||||
* class is being used or not.
|
||||
*
|
||||
* Converted from CodeIgniter.
|
||||
*
|
||||
* @package FuzeWorks
|
||||
* @subpackage Drivers
|
||||
* @category Database
|
||||
* @author Esen Sagynov
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
*/
|
||||
class FW_DB_cubrid_driver extends FW_DB {
|
||||
|
||||
/**
|
||||
* Database driver
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $dbdriver = 'cubrid';
|
||||
|
||||
/**
|
||||
* Auto-commit flag
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $auto_commit = TRUE;
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Identifier escape character
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_escape_char = '`';
|
||||
|
||||
/**
|
||||
* ORDER BY random keyword
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_random_keyword = array('RANDOM()', 'RANDOM(%d)');
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param array $params
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($params)
|
||||
{
|
||||
parent::__construct($params);
|
||||
|
||||
if (preg_match('/^CUBRID:[^:]+(:[0-9][1-9]{0,4})?:[^:]+:[^:]*:[^:]*:(\?.+)?$/', $this->dsn, $matches))
|
||||
{
|
||||
if (stripos($matches[2], 'autocommit=off') !== FALSE)
|
||||
{
|
||||
$this->auto_commit = FALSE;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// If no port is defined by the user, use the default value
|
||||
empty($this->port) OR $this->port = 33000;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Non-persistent database connection
|
||||
*
|
||||
* @param bool $persistent
|
||||
* @return resource
|
||||
*/
|
||||
public function db_connect($persistent = FALSE)
|
||||
{
|
||||
if (preg_match('/^CUBRID:[^:]+(:[0-9][1-9]{0,4})?:[^:]+:([^:]*):([^:]*):(\?.+)?$/', $this->dsn, $matches))
|
||||
{
|
||||
$func = ($persistent !== TRUE) ? 'cubrid_connect_with_url' : 'cubrid_pconnect_with_url';
|
||||
return ($matches[2] === '' && $matches[3] === '' && $this->username !== '' && $this->password !== '')
|
||||
? $func($this->dsn, $this->username, $this->password)
|
||||
: $func($this->dsn);
|
||||
}
|
||||
|
||||
$func = ($persistent !== TRUE) ? 'cubrid_connect' : 'cubrid_pconnect';
|
||||
return ($this->username !== '')
|
||||
? $func($this->hostname, $this->port, $this->database, $this->username, $this->password)
|
||||
: $func($this->hostname, $this->port, $this->database);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Reconnect
|
||||
*
|
||||
* Keep / reestablish the db connection if no queries have been
|
||||
* sent for a length of time exceeding the server's idle timeout
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function reconnect()
|
||||
{
|
||||
if (cubrid_ping($this->conn_id) === FALSE)
|
||||
{
|
||||
$this->conn_id = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Database version number
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function version()
|
||||
{
|
||||
if (isset($this->data_cache['version']))
|
||||
{
|
||||
return $this->data_cache['version'];
|
||||
}
|
||||
|
||||
return ( ! $this->conn_id OR ($version = cubrid_get_server_info($this->conn_id)) === FALSE)
|
||||
? FALSE
|
||||
: $this->data_cache['version'] = $version;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Execute the query
|
||||
*
|
||||
* @param string $sql an SQL query
|
||||
* @return resource
|
||||
*/
|
||||
protected function _execute($sql)
|
||||
{
|
||||
return cubrid_query($sql, $this->conn_id);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Begin Transaction
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function _trans_begin()
|
||||
{
|
||||
if (($autocommit = cubrid_get_autocommit($this->conn_id)) === NULL)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
elseif ($autocommit === TRUE)
|
||||
{
|
||||
return cubrid_set_autocommit($this->conn_id, CUBRID_AUTOCOMMIT_FALSE);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Commit Transaction
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function _trans_commit()
|
||||
{
|
||||
if ( ! cubrid_commit($this->conn_id))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if ($this->auto_commit && ! cubrid_get_autocommit($this->conn_id))
|
||||
{
|
||||
return cubrid_set_autocommit($this->conn_id, CUBRID_AUTOCOMMIT_TRUE);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Rollback Transaction
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function _trans_rollback()
|
||||
{
|
||||
if ( ! cubrid_rollback($this->conn_id))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if ($this->auto_commit && ! cubrid_get_autocommit($this->conn_id))
|
||||
{
|
||||
cubrid_set_autocommit($this->conn_id, CUBRID_AUTOCOMMIT_TRUE);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Platform-dependant string escape
|
||||
*
|
||||
* @param string
|
||||
* @return string
|
||||
*/
|
||||
protected function _escape_str($str)
|
||||
{
|
||||
return cubrid_real_escape_string($str, $this->conn_id);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Affected Rows
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function affected_rows()
|
||||
{
|
||||
return cubrid_affected_rows();
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Insert ID
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function insert_id()
|
||||
{
|
||||
return cubrid_insert_id($this->conn_id);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* List table query
|
||||
*
|
||||
* Generates a platform-specific query string so that the table names can be fetched
|
||||
*
|
||||
* @param bool $prefix_limit
|
||||
* @return string
|
||||
*/
|
||||
protected function _list_tables($prefix_limit = FALSE)
|
||||
{
|
||||
$sql = 'SHOW TABLES';
|
||||
|
||||
if ($prefix_limit !== FALSE && $this->dbprefix !== '')
|
||||
{
|
||||
return $sql." LIKE '".$this->escape_like_str($this->dbprefix)."%'";
|
||||
}
|
||||
|
||||
return $sql;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Show column query
|
||||
*
|
||||
* Generates a platform-specific query string so that the column names can be fetched
|
||||
*
|
||||
* @param string $table
|
||||
* @return string
|
||||
*/
|
||||
protected function _list_columns($table = '')
|
||||
{
|
||||
return 'SHOW COLUMNS FROM '.$this->protect_identifiers($table, TRUE, NULL, FALSE);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Returns an object with field data
|
||||
*
|
||||
* @param string $table
|
||||
* @return array
|
||||
*/
|
||||
public function field_data($table)
|
||||
{
|
||||
if (($query = $this->query('SHOW COLUMNS FROM '.$this->protect_identifiers($table, TRUE, NULL, FALSE))) === FALSE)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
$query = $query->result_object();
|
||||
|
||||
$retval = array();
|
||||
for ($i = 0, $c = count($query); $i < $c; $i++)
|
||||
{
|
||||
$retval[$i] = new stdClass();
|
||||
$retval[$i]->name = $query[$i]->Field;
|
||||
|
||||
sscanf($query[$i]->Type, '%[a-z](%d)',
|
||||
$retval[$i]->type,
|
||||
$retval[$i]->max_length
|
||||
);
|
||||
|
||||
$retval[$i]->default = $query[$i]->Default;
|
||||
$retval[$i]->primary_key = (int) ($query[$i]->Key === 'PRI');
|
||||
}
|
||||
|
||||
return $retval;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Error
|
||||
*
|
||||
* Returns an array containing code and message of the last
|
||||
* database error that has occured.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function error()
|
||||
{
|
||||
return array('code' => cubrid_errno($this->conn_id), 'message' => cubrid_error($this->conn_id));
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* FROM tables
|
||||
*
|
||||
* Groups tables in FROM clauses if needed, so there is no confusion
|
||||
* about operator precedence.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function _from_tables()
|
||||
{
|
||||
if ( ! empty($this->qb_join) && count($this->qb_from) > 1)
|
||||
{
|
||||
return '('.implode(', ', $this->qb_from).')';
|
||||
}
|
||||
|
||||
return implode(', ', $this->qb_from);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Close DB Connection
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _close()
|
||||
{
|
||||
cubrid_close($this->conn_id);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,224 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2015 TechFuze
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 1.0.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* CUBRID Forge Class
|
||||
*
|
||||
* Converted from CodeIgniter.
|
||||
*
|
||||
* @package FuzeWorks
|
||||
* @category Database
|
||||
* @author Esen Sagynov
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
*/
|
||||
class FW_DB_cubrid_forge extends FW_DB_forge {
|
||||
|
||||
/**
|
||||
* CREATE DATABASE statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_create_database = FALSE;
|
||||
|
||||
/**
|
||||
* CREATE TABLE keys flag
|
||||
*
|
||||
* Whether table keys are created from within the
|
||||
* CREATE TABLE statement.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $_create_table_keys = TRUE;
|
||||
|
||||
/**
|
||||
* DROP DATABASE statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_drop_database = FALSE;
|
||||
|
||||
/**
|
||||
* CREATE TABLE IF statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_create_table_if = FALSE;
|
||||
|
||||
/**
|
||||
* UNSIGNED support
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_unsigned = array(
|
||||
'SHORT' => 'INTEGER',
|
||||
'SMALLINT' => 'INTEGER',
|
||||
'INT' => 'BIGINT',
|
||||
'INTEGER' => 'BIGINT',
|
||||
'BIGINT' => 'NUMERIC',
|
||||
'FLOAT' => 'DOUBLE',
|
||||
'REAL' => 'DOUBLE'
|
||||
);
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* ALTER TABLE
|
||||
*
|
||||
* @param string $alter_type ALTER type
|
||||
* @param string $table Table name
|
||||
* @param mixed $field Column definition
|
||||
* @return string|string[]
|
||||
*/
|
||||
protected function _alter_table($alter_type, $table, $field)
|
||||
{
|
||||
if (in_array($alter_type, array('DROP', 'ADD'), TRUE))
|
||||
{
|
||||
return parent::_alter_table($alter_type, $table, $field);
|
||||
}
|
||||
|
||||
$sql = 'ALTER TABLE '.$this->db->escape_identifiers($table);
|
||||
$sqls = array();
|
||||
for ($i = 0, $c = count($field); $i < $c; $i++)
|
||||
{
|
||||
if ($field[$i]['_literal'] !== FALSE)
|
||||
{
|
||||
$sqls[] = $sql.' CHANGE '.$field[$i]['_literal'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$alter_type = empty($field[$i]['new_name']) ? ' MODIFY ' : ' CHANGE ';
|
||||
$sqls[] = $sql.$alter_type.$this->_process_column($field[$i]);
|
||||
}
|
||||
}
|
||||
|
||||
return $sqls;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Process column
|
||||
*
|
||||
* @param array $field
|
||||
* @return string
|
||||
*/
|
||||
protected function _process_column($field)
|
||||
{
|
||||
$extra_clause = isset($field['after'])
|
||||
? ' AFTER '.$this->db->escape_identifiers($field['after']) : '';
|
||||
|
||||
if (empty($extra_clause) && isset($field['first']) && $field['first'] === TRUE)
|
||||
{
|
||||
$extra_clause = ' FIRST';
|
||||
}
|
||||
|
||||
return $this->db->escape_identifiers($field['name'])
|
||||
.(empty($field['new_name']) ? '' : ' '.$this->db->escape_identifiers($field['new_name']))
|
||||
.' '.$field['type'].$field['length']
|
||||
.$field['unsigned']
|
||||
.$field['null']
|
||||
.$field['default']
|
||||
.$field['auto_increment']
|
||||
.$field['unique']
|
||||
.$extra_clause;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Field attribute TYPE
|
||||
*
|
||||
* Performs a data type mapping between different databases.
|
||||
*
|
||||
* @param array &$attributes
|
||||
* @return void
|
||||
*/
|
||||
protected function _attr_type(&$attributes)
|
||||
{
|
||||
switch (strtoupper($attributes['TYPE']))
|
||||
{
|
||||
case 'TINYINT':
|
||||
$attributes['TYPE'] = 'SMALLINT';
|
||||
$attributes['UNSIGNED'] = FALSE;
|
||||
return;
|
||||
case 'MEDIUMINT':
|
||||
$attributes['TYPE'] = 'INTEGER';
|
||||
$attributes['UNSIGNED'] = FALSE;
|
||||
return;
|
||||
default: return;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Process indexes
|
||||
*
|
||||
* @param string $table (ignored)
|
||||
* @return string
|
||||
*/
|
||||
protected function _process_indexes($table)
|
||||
{
|
||||
$sql = '';
|
||||
|
||||
for ($i = 0, $c = count($this->keys); $i < $c; $i++)
|
||||
{
|
||||
if (is_array($this->keys[$i]))
|
||||
{
|
||||
for ($i2 = 0, $c2 = count($this->keys[$i]); $i2 < $c2; $i2++)
|
||||
{
|
||||
if ( ! isset($this->fields[$this->keys[$i][$i2]]))
|
||||
{
|
||||
unset($this->keys[$i][$i2]);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
elseif ( ! isset($this->fields[$this->keys[$i]]))
|
||||
{
|
||||
unset($this->keys[$i]);
|
||||
continue;
|
||||
}
|
||||
|
||||
is_array($this->keys[$i]) OR $this->keys[$i] = array($this->keys[$i]);
|
||||
|
||||
$sql .= ",\n\tKEY ".$this->db->escape_identifiers(implode('_', $this->keys[$i]))
|
||||
.' ('.implode(', ', $this->db->escape_identifiers($this->keys[$i])).')';
|
||||
}
|
||||
|
||||
$this->keys = array();
|
||||
|
||||
return $sql;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,174 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2015 TechFuze
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 1.0.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* CUBRID Result Class
|
||||
*
|
||||
* This class extends the parent result class: FW_DB_result
|
||||
*
|
||||
* Converted from CodeIgniter.
|
||||
*
|
||||
* @package FuzeWorks
|
||||
* @category Database
|
||||
* @author Esen Sagynov
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
*/
|
||||
class FW_DB_cubrid_result extends FW_DB_result {
|
||||
|
||||
/**
|
||||
* Number of rows in the result set
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function num_rows()
|
||||
{
|
||||
return is_int($this->num_rows)
|
||||
? $this->num_rows
|
||||
: $this->num_rows = cubrid_num_rows($this->result_id);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Number of fields in the result set
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function num_fields()
|
||||
{
|
||||
return cubrid_num_fields($this->result_id);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Fetch Field Names
|
||||
*
|
||||
* Generates an array of column names
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function list_fields()
|
||||
{
|
||||
return cubrid_column_names($this->result_id);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Field data
|
||||
*
|
||||
* Generates an array of objects containing field meta-data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function field_data()
|
||||
{
|
||||
$retval = array();
|
||||
|
||||
for ($i = 0, $c = $this->num_fields(); $i < $c; $i++)
|
||||
{
|
||||
$retval[$i] = new stdClass();
|
||||
$retval[$i]->name = cubrid_field_name($this->result_id, $i);
|
||||
$retval[$i]->type = cubrid_field_type($this->result_id, $i);
|
||||
$retval[$i]->max_length = cubrid_field_len($this->result_id, $i);
|
||||
$retval[$i]->primary_key = (int) (strpos(cubrid_field_flags($this->result_id, $i), 'primary_key') !== FALSE);
|
||||
}
|
||||
|
||||
return $retval;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Free the result
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function free_result()
|
||||
{
|
||||
if (is_resource($this->result_id) OR
|
||||
(get_resource_type($this->result_id) === 'Unknown' && preg_match('/Resource id #/', strval($this->result_id))))
|
||||
{
|
||||
cubrid_close_request($this->result_id);
|
||||
$this->result_id = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Data Seek
|
||||
*
|
||||
* Moves the internal pointer to the desired offset. We call
|
||||
* this internally before fetching results to make sure the
|
||||
* result set starts at zero.
|
||||
*
|
||||
* @param int $n
|
||||
* @return bool
|
||||
*/
|
||||
public function data_seek($n = 0)
|
||||
{
|
||||
return cubrid_data_seek($this->result_id, $n);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Result - associative array
|
||||
*
|
||||
* Returns the result set as an array
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function _fetch_assoc()
|
||||
{
|
||||
return cubrid_fetch_assoc($this->result_id);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Result - object
|
||||
*
|
||||
* Returns the result set as an object
|
||||
*
|
||||
* @param string $class_name
|
||||
* @return object
|
||||
*/
|
||||
protected function _fetch_object($class_name = 'stdClass')
|
||||
{
|
||||
return cubrid_fetch_object($this->result_id, $class_name);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,76 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2015 TechFuze
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 1.0.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* CUBRID Utility Class
|
||||
*
|
||||
* Converted from CodeIgniter.
|
||||
*
|
||||
* @package FuzeWorks
|
||||
* @category Database
|
||||
* @author Esen Sagynov
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
*/
|
||||
class FW_DB_cubrid_utility extends FW_DB_utility {
|
||||
|
||||
/**
|
||||
* List databases
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function list_databases()
|
||||
{
|
||||
if (isset($this->db->data_cache['db_names']))
|
||||
{
|
||||
return $this->db->data_cache['db_names'];
|
||||
}
|
||||
|
||||
return $this->db->data_cache['db_names'] = cubrid_list_dbs($this->db->conn_id);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* CUBRID Export
|
||||
*
|
||||
* @param array Preferences
|
||||
* @return mixed
|
||||
*/
|
||||
protected function _backup($params = array())
|
||||
{
|
||||
// No SQL based support in CUBRID as of version 8.4.0. Database or
|
||||
// table backup can be performed using CUBRID Manager
|
||||
// database administration tool.
|
||||
return $this->db->display_error('db_unsupported_feature');
|
||||
}
|
||||
}
|
|
@ -1,392 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2015 TechFuze
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 1.0.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* Firebird/Interbase Database Adapter Class
|
||||
*
|
||||
* Note: _DB is an extender class that the app controller
|
||||
* creates dynamically based on whether the query builder
|
||||
* class is being used or not.
|
||||
*
|
||||
* Converted from CodeIgniter.
|
||||
*
|
||||
* @package FuzeWorks
|
||||
* @subpackage Drivers
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
*/
|
||||
class FW_DB_ibase_driver extends FW_DB {
|
||||
|
||||
/**
|
||||
* Database driver
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $dbdriver = 'ibase';
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* ORDER BY random keyword
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_random_keyword = array('RAND()', 'RAND()');
|
||||
|
||||
/**
|
||||
* IBase Transaction status flag
|
||||
*
|
||||
* @var resource
|
||||
*/
|
||||
protected $_ibase_trans;
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Non-persistent database connection
|
||||
*
|
||||
* @param bool $persistent
|
||||
* @return resource
|
||||
*/
|
||||
public function db_connect($persistent = FALSE)
|
||||
{
|
||||
return ($persistent === TRUE)
|
||||
? ibase_pconnect($this->hostname.':'.$this->database, $this->username, $this->password, $this->char_set)
|
||||
: ibase_connect($this->hostname.':'.$this->database, $this->username, $this->password, $this->char_set);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Database version number
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function version()
|
||||
{
|
||||
if (isset($this->data_cache['version']))
|
||||
{
|
||||
return $this->data_cache['version'];
|
||||
}
|
||||
|
||||
if (($service = ibase_service_attach($this->hostname, $this->username, $this->password)))
|
||||
{
|
||||
$this->data_cache['version'] = ibase_server_info($service, IBASE_SVC_SERVER_VERSION);
|
||||
|
||||
// Don't keep the service open
|
||||
ibase_service_detach($service);
|
||||
return $this->data_cache['version'];
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Execute the query
|
||||
*
|
||||
* @param string $sql an SQL query
|
||||
* @return resource
|
||||
*/
|
||||
protected function _execute($sql)
|
||||
{
|
||||
return ibase_query(isset($this->_ibase_trans) ? $this->_ibase_trans : $this->conn_id, $sql);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Begin Transaction
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function _trans_begin()
|
||||
{
|
||||
if (($trans_handle = ibase_trans($this->conn_id)) === FALSE)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$this->_ibase_trans = $trans_handle;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Commit Transaction
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function _trans_commit()
|
||||
{
|
||||
if (ibase_commit($this->_ibase_trans))
|
||||
{
|
||||
$this->_ibase_trans = NULL;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Rollback Transaction
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function _trans_rollback()
|
||||
{
|
||||
if (ibase_rollback($this->_ibase_trans))
|
||||
{
|
||||
$this->_ibase_trans = NULL;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Affected Rows
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function affected_rows()
|
||||
{
|
||||
return ibase_affected_rows($this->conn_id);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Insert ID
|
||||
*
|
||||
* @param string $generator_name
|
||||
* @param int $inc_by
|
||||
* @return int
|
||||
*/
|
||||
public function insert_id($generator_name, $inc_by = 0)
|
||||
{
|
||||
//If a generator hasn't been used before it will return 0
|
||||
return ibase_gen_id('"'.$generator_name.'"', $inc_by);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* List table query
|
||||
*
|
||||
* Generates a platform-specific query string so that the table names can be fetched
|
||||
*
|
||||
* @param bool $prefix_limit
|
||||
* @return string
|
||||
*/
|
||||
protected function _list_tables($prefix_limit = FALSE)
|
||||
{
|
||||
$sql = 'SELECT TRIM("RDB$RELATION_NAME") AS TABLE_NAME FROM "RDB$RELATIONS" WHERE "RDB$RELATION_NAME" NOT LIKE \'RDB$%\' AND "RDB$RELATION_NAME" NOT LIKE \'MON$%\'';
|
||||
|
||||
if ($prefix_limit !== FALSE && $this->dbprefix !== '')
|
||||
{
|
||||
return $sql.' AND TRIM("RDB$RELATION_NAME") AS TABLE_NAME LIKE \''.$this->escape_like_str($this->dbprefix)."%' "
|
||||
.sprintf($this->_like_escape_str, $this->_like_escape_chr);
|
||||
}
|
||||
|
||||
return $sql;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Show column query
|
||||
*
|
||||
* Generates a platform-specific query string so that the column names can be fetched
|
||||
*
|
||||
* @param string $table
|
||||
* @return string
|
||||
*/
|
||||
protected function _list_columns($table = '')
|
||||
{
|
||||
return 'SELECT TRIM("RDB$FIELD_NAME") AS COLUMN_NAME FROM "RDB$RELATION_FIELDS" WHERE "RDB$RELATION_NAME" = '.$this->escape($table);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Returns an object with field data
|
||||
*
|
||||
* @param string $table
|
||||
* @return array
|
||||
*/
|
||||
public function field_data($table)
|
||||
{
|
||||
$sql = 'SELECT "rfields"."RDB$FIELD_NAME" AS "name",
|
||||
CASE "fields"."RDB$FIELD_TYPE"
|
||||
WHEN 7 THEN \'SMALLINT\'
|
||||
WHEN 8 THEN \'INTEGER\'
|
||||
WHEN 9 THEN \'QUAD\'
|
||||
WHEN 10 THEN \'FLOAT\'
|
||||
WHEN 11 THEN \'DFLOAT\'
|
||||
WHEN 12 THEN \'DATE\'
|
||||
WHEN 13 THEN \'TIME\'
|
||||
WHEN 14 THEN \'CHAR\'
|
||||
WHEN 16 THEN \'INT64\'
|
||||
WHEN 27 THEN \'DOUBLE\'
|
||||
WHEN 35 THEN \'TIMESTAMP\'
|
||||
WHEN 37 THEN \'VARCHAR\'
|
||||
WHEN 40 THEN \'CSTRING\'
|
||||
WHEN 261 THEN \'BLOB\'
|
||||
ELSE NULL
|
||||
END AS "type",
|
||||
"fields"."RDB$FIELD_LENGTH" AS "max_length",
|
||||
"rfields"."RDB$DEFAULT_VALUE" AS "default"
|
||||
FROM "RDB$RELATION_FIELDS" "rfields"
|
||||
JOIN "RDB$FIELDS" "fields" ON "rfields"."RDB$FIELD_SOURCE" = "fields"."RDB$FIELD_NAME"
|
||||
WHERE "rfields"."RDB$RELATION_NAME" = '.$this->escape($table).'
|
||||
ORDER BY "rfields"."RDB$FIELD_POSITION"';
|
||||
|
||||
return (($query = $this->query($sql)) !== FALSE)
|
||||
? $query->result_object()
|
||||
: FALSE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Error
|
||||
*
|
||||
* Returns an array containing code and message of the last
|
||||
* database error that has occured.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function error()
|
||||
{
|
||||
return array('code' => ibase_errcode(), 'message' => ibase_errmsg());
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Update statement
|
||||
*
|
||||
* Generates a platform-specific update string from the supplied data
|
||||
*
|
||||
* @param string $table
|
||||
* @param array $values
|
||||
* @return string
|
||||
*/
|
||||
protected function _update($table, $values)
|
||||
{
|
||||
$this->qb_limit = FALSE;
|
||||
return parent::_update($table, $values);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Truncate statement
|
||||
*
|
||||
* Generates a platform-specific truncate string from the supplied data
|
||||
*
|
||||
* If the database does not support the TRUNCATE statement,
|
||||
* then this method maps to 'DELETE FROM table'
|
||||
*
|
||||
* @param string $table
|
||||
* @return string
|
||||
*/
|
||||
protected function _truncate($table)
|
||||
{
|
||||
return 'DELETE FROM '.$table;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Delete statement
|
||||
*
|
||||
* Generates a platform-specific delete string from the supplied data
|
||||
*
|
||||
* @param string $table
|
||||
* @return string
|
||||
*/
|
||||
protected function _delete($table)
|
||||
{
|
||||
$this->qb_limit = FALSE;
|
||||
return parent::_delete($table);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* LIMIT
|
||||
*
|
||||
* Generates a platform-specific LIMIT clause
|
||||
*
|
||||
* @param string $sql SQL Query
|
||||
* @return string
|
||||
*/
|
||||
protected function _limit($sql)
|
||||
{
|
||||
// Limit clause depends on if Interbase or Firebird
|
||||
if (stripos($this->version(), 'firebird') !== FALSE)
|
||||
{
|
||||
$select = 'FIRST '.$this->qb_limit
|
||||
.($this->qb_offset ? ' SKIP '.$this->qb_offset : '');
|
||||
}
|
||||
else
|
||||
{
|
||||
$select = 'ROWS '
|
||||
.($this->qb_offset ? $this->qb_offset.' TO '.($this->qb_limit + $this->qb_offset) : $this->qb_limit);
|
||||
}
|
||||
|
||||
return preg_replace('`SELECT`i', 'SELECT '.$select, $sql, 1);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Close DB Connection
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _close()
|
||||
{
|
||||
ibase_close($this->conn_id);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,248 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2015 TechFuze
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 1.0.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* Interbase/Firebird Forge Class
|
||||
*
|
||||
* Converted from CodeIgniter.
|
||||
*
|
||||
* @package FuzeWorks
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
*/
|
||||
class FW_DB_ibase_forge extends FW_DB_forge {
|
||||
|
||||
/**
|
||||
* CREATE TABLE IF statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_create_table_if = FALSE;
|
||||
|
||||
/**
|
||||
* RENAME TABLE statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_rename_table = FALSE;
|
||||
|
||||
/**
|
||||
* DROP TABLE IF statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_drop_table_if = FALSE;
|
||||
|
||||
/**
|
||||
* UNSIGNED support
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_unsigned = array(
|
||||
'SMALLINT' => 'INTEGER',
|
||||
'INTEGER' => 'INT64',
|
||||
'FLOAT' => 'DOUBLE PRECISION'
|
||||
);
|
||||
|
||||
/**
|
||||
* NULL value representation in CREATE/ALTER TABLE statements
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_null = 'NULL';
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Create database
|
||||
*
|
||||
* @param string $db_name
|
||||
* @return string
|
||||
*/
|
||||
public function create_database($db_name)
|
||||
{
|
||||
// Firebird databases are flat files, so a path is required
|
||||
|
||||
// Hostname is needed for remote access
|
||||
empty($this->db->hostname) OR $db_name = $this->hostname.':'.$db_name;
|
||||
|
||||
return parent::create_database('"'.$db_name.'"');
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Drop database
|
||||
*
|
||||
* @param string $db_name (ignored)
|
||||
* @return bool
|
||||
*/
|
||||
public function drop_database($db_name = '')
|
||||
{
|
||||
if ( ! ibase_drop_db($this->conn_id))
|
||||
{
|
||||
return ($this->db->db_debug) ? $this->db->display_error('db_unable_to_drop') : FALSE;
|
||||
}
|
||||
elseif ( ! empty($this->db->data_cache['db_names']))
|
||||
{
|
||||
$key = array_search(strtolower($this->db->database), array_map('strtolower', $this->db->data_cache['db_names']), TRUE);
|
||||
if ($key !== FALSE)
|
||||
{
|
||||
unset($this->db->data_cache['db_names'][$key]);
|
||||
}
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* ALTER TABLE
|
||||
*
|
||||
* @param string $alter_type ALTER type
|
||||
* @param string $table Table name
|
||||
* @param mixed $field Column definition
|
||||
* @return string|string[]
|
||||
*/
|
||||
protected function _alter_table($alter_type, $table, $field)
|
||||
{
|
||||
if (in_array($alter_type, array('DROP', 'ADD'), TRUE))
|
||||
{
|
||||
return parent::_alter_table($alter_type, $table, $field);
|
||||
}
|
||||
|
||||
$sql = 'ALTER TABLE '.$this->db->escape_identifiers($table);
|
||||
$sqls = array();
|
||||
for ($i = 0, $c = count($field); $i < $c; $i++)
|
||||
{
|
||||
if ($field[$i]['_literal'] !== FALSE)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (isset($field[$i]['type']))
|
||||
{
|
||||
$sqls[] = $sql.' ALTER COLUMN '.$this->db->escape_identififers($field[$i]['name'])
|
||||
.' TYPE '.$field[$i]['type'].$field[$i]['length'];
|
||||
}
|
||||
|
||||
if ( ! empty($field[$i]['default']))
|
||||
{
|
||||
$sqls[] = $sql.' ALTER COLUMN '.$this->db->escape_identifiers($field[$i]['name'])
|
||||
.' SET DEFAULT '.$field[$i]['default'];
|
||||
}
|
||||
|
||||
if (isset($field[$i]['null']))
|
||||
{
|
||||
$sqls[] = 'UPDATE "RDB$RELATION_FIELDS" SET "RDB$NULL_FLAG" = '
|
||||
.($field[$i]['null'] === TRUE ? 'NULL' : '1')
|
||||
.' WHERE "RDB$FIELD_NAME" = '.$this->db->escape($field[$i]['name'])
|
||||
.' AND "RDB$RELATION_NAME" = '.$this->db->escape($table);
|
||||
}
|
||||
|
||||
if ( ! empty($field[$i]['new_name']))
|
||||
{
|
||||
$sqls[] = $sql.' ALTER COLUMN '.$this->db->escape_identifiers($field[$i]['name'])
|
||||
.' TO '.$this->db->escape_identifiers($field[$i]['new_name']);
|
||||
}
|
||||
}
|
||||
|
||||
return $sqls;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Process column
|
||||
*
|
||||
* @param array $field
|
||||
* @return string
|
||||
*/
|
||||
protected function _process_column($field)
|
||||
{
|
||||
return $this->db->escape_identifiers($field['name'])
|
||||
.' '.$field['type'].$field['length']
|
||||
.$field['null']
|
||||
.$field['unique']
|
||||
.$field['default'];
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Field attribute TYPE
|
||||
*
|
||||
* Performs a data type mapping between different databases.
|
||||
*
|
||||
* @param array &$attributes
|
||||
* @return void
|
||||
*/
|
||||
protected function _attr_type(&$attributes)
|
||||
{
|
||||
switch (strtoupper($attributes['TYPE']))
|
||||
{
|
||||
case 'TINYINT':
|
||||
$attributes['TYPE'] = 'SMALLINT';
|
||||
$attributes['UNSIGNED'] = FALSE;
|
||||
return;
|
||||
case 'MEDIUMINT':
|
||||
$attributes['TYPE'] = 'INTEGER';
|
||||
$attributes['UNSIGNED'] = FALSE;
|
||||
return;
|
||||
case 'INT':
|
||||
$attributes['TYPE'] = 'INTEGER';
|
||||
return;
|
||||
case 'BIGINT':
|
||||
$attributes['TYPE'] = 'INT64';
|
||||
return;
|
||||
default: return;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Field attribute AUTO_INCREMENT
|
||||
*
|
||||
* @param array &$attributes
|
||||
* @param array &$field
|
||||
* @return void
|
||||
*/
|
||||
protected function _attr_auto_increment(&$attributes, &$field)
|
||||
{
|
||||
// Not supported
|
||||
}
|
||||
|
||||
}
|
|
@ -1,158 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2015 TechFuze
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 1.0.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* Interbase/Firebird Result Class
|
||||
*
|
||||
* This class extends the parent result class: FW_DB_result
|
||||
*
|
||||
* Converted from CodeIgniter.
|
||||
*
|
||||
* @package FuzeWorks
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
*/
|
||||
class FW_DB_ibase_result extends FW_DB_result {
|
||||
|
||||
/**
|
||||
* Number of fields in the result set
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function num_fields()
|
||||
{
|
||||
return ibase_num_fields($this->result_id);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Fetch Field Names
|
||||
*
|
||||
* Generates an array of column names
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function list_fields()
|
||||
{
|
||||
$field_names = array();
|
||||
for ($i = 0, $num_fields = $this->num_fields(); $i < $num_fields; $i++)
|
||||
{
|
||||
$info = ibase_field_info($this->result_id, $i);
|
||||
$field_names[] = $info['name'];
|
||||
}
|
||||
|
||||
return $field_names;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Field data
|
||||
*
|
||||
* Generates an array of objects containing field meta-data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function field_data()
|
||||
{
|
||||
$retval = array();
|
||||
for ($i = 0, $c = $this->num_fields(); $i < $c; $i++)
|
||||
{
|
||||
$info = ibase_field_info($this->result_id, $i);
|
||||
|
||||
$retval[$i] = new stdClass();
|
||||
$retval[$i]->name = $info['name'];
|
||||
$retval[$i]->type = $info['type'];
|
||||
$retval[$i]->max_length = $info['length'];
|
||||
}
|
||||
|
||||
return $retval;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Free the result
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function free_result()
|
||||
{
|
||||
ibase_free_result($this->result_id);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Result - associative array
|
||||
*
|
||||
* Returns the result set as an array
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function _fetch_assoc()
|
||||
{
|
||||
return ibase_fetch_assoc($this->result_id, IBASE_FETCH_BLOBS);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Result - object
|
||||
*
|
||||
* Returns the result set as an object
|
||||
*
|
||||
* @param string $class_name
|
||||
* @return object
|
||||
*/
|
||||
protected function _fetch_object($class_name = 'stdClass')
|
||||
{
|
||||
$row = ibase_fetch_object($this->result_id, IBASE_FETCH_BLOBS);
|
||||
|
||||
if ($class_name === 'stdClass' OR ! $row)
|
||||
{
|
||||
return $row;
|
||||
}
|
||||
|
||||
$class_name = new $class_name();
|
||||
foreach ($row as $key => $value)
|
||||
{
|
||||
$class_name->$key = $value;
|
||||
}
|
||||
|
||||
return $class_name;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,66 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2015 TechFuze
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 1.0.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* Interbase/Firebird Utility Class
|
||||
*
|
||||
* Converted from CodeIgniter.
|
||||
*
|
||||
* @package FuzeWorks
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
*/
|
||||
class FW_DB_ibase_utility extends FW_DB_utility {
|
||||
|
||||
/**
|
||||
* Export
|
||||
*
|
||||
* @param string $filename
|
||||
* @return mixed
|
||||
*/
|
||||
protected function _backup($filename)
|
||||
{
|
||||
if ($service = ibase_service_attach($this->db->hostname, $this->db->username, $this->db->password))
|
||||
{
|
||||
$res = ibase_backup($service, $this->db->database, $filename.'.fbk');
|
||||
|
||||
// Close the service connection
|
||||
ibase_service_detach($service);
|
||||
return $res;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,543 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2015 TechFuze
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 1.0.0
|
||||
*/
|
||||
|
||||
use FuzeWorks\Logger;
|
||||
use FuzeWorks\Core;
|
||||
|
||||
/**
|
||||
* MySQLi Database Adapter Class
|
||||
*
|
||||
* Note: _DB is an extender class that the app controller
|
||||
* creates dynamically based on whether the query builder
|
||||
* class is being used or not.
|
||||
*
|
||||
* Converted from CodeIgniter.
|
||||
*
|
||||
* @package FuzeWorks
|
||||
* @subpackage Drivers
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
*/
|
||||
class FW_DB_mysqli_driver extends FW_DB {
|
||||
|
||||
/**
|
||||
* Database driver
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $dbdriver = 'mysqli';
|
||||
|
||||
/**
|
||||
* Compression flag
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $compress = FALSE;
|
||||
|
||||
/**
|
||||
* DELETE hack flag
|
||||
*
|
||||
* Whether to use the MySQL "delete hack" which allows the number
|
||||
* of affected rows to be shown. Uses a preg_replace when enabled,
|
||||
* adding a bit more processing to all queries.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $delete_hack = TRUE;
|
||||
|
||||
/**
|
||||
* Strict ON flag
|
||||
*
|
||||
* Whether we're running in strict SQL mode.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $stricton;
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Identifier escape character
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_escape_char = '`';
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* MySQLi object
|
||||
*
|
||||
* Has to be preserved without being assigned to $conn_id.
|
||||
*
|
||||
* @var MySQLi
|
||||
*/
|
||||
protected $_mysqli;
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Database connection
|
||||
*
|
||||
* @param bool $persistent
|
||||
* @return object
|
||||
*/
|
||||
public function db_connect($persistent = FALSE)
|
||||
{
|
||||
// Do we have a socket path?
|
||||
if ($this->hostname[0] === '/')
|
||||
{
|
||||
$hostname = NULL;
|
||||
$port = NULL;
|
||||
$socket = $this->hostname;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Persistent connection support was added in PHP 5.3.0
|
||||
$hostname = ($persistent === TRUE && Core::isPHP('5.3'))
|
||||
? 'p:'.$this->hostname : $this->hostname;
|
||||
$port = empty($this->port) ? NULL : $this->port;
|
||||
$socket = NULL;
|
||||
}
|
||||
|
||||
$client_flags = ($this->compress === TRUE) ? MYSQLI_CLIENT_COMPRESS : 0;
|
||||
$this->_mysqli = mysqli_init();
|
||||
|
||||
$this->_mysqli->options(MYSQLI_OPT_CONNECT_TIMEOUT, 10);
|
||||
|
||||
if (isset($this->stricton))
|
||||
{
|
||||
if ($this->stricton)
|
||||
{
|
||||
$this->_mysqli->options(MYSQLI_INIT_COMMAND, 'SET SESSION sql_mode = CONCAT(@@sql_mode, ",", "STRICT_ALL_TABLES")');
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->_mysqli->options(MYSQLI_INIT_COMMAND,
|
||||
'SET SESSION sql_mode =
|
||||
REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(
|
||||
@@sql_mode,
|
||||
"STRICT_ALL_TABLES,", ""),
|
||||
",STRICT_ALL_TABLES", ""),
|
||||
"STRICT_ALL_TABLES", ""),
|
||||
"STRICT_TRANS_TABLES,", ""),
|
||||
",STRICT_TRANS_TABLES", ""),
|
||||
"STRICT_TRANS_TABLES", "")'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (is_array($this->encrypt))
|
||||
{
|
||||
$ssl = array();
|
||||
empty($this->encrypt['ssl_key']) OR $ssl['key'] = $this->encrypt['ssl_key'];
|
||||
empty($this->encrypt['ssl_cert']) OR $ssl['cert'] = $this->encrypt['ssl_cert'];
|
||||
empty($this->encrypt['ssl_ca']) OR $ssl['ca'] = $this->encrypt['ssl_ca'];
|
||||
empty($this->encrypt['ssl_capath']) OR $ssl['capath'] = $this->encrypt['ssl_capath'];
|
||||
empty($this->encrypt['ssl_cipher']) OR $ssl['cipher'] = $this->encrypt['ssl_cipher'];
|
||||
|
||||
if ( ! empty($ssl))
|
||||
{
|
||||
if (isset($this->encrypt['ssl_verify']))
|
||||
{
|
||||
if ($this->encrypt['ssl_verify'])
|
||||
{
|
||||
defined('MYSQLI_OPT_SSL_VERIFY_SERVER_CERT') && $this->_mysqli->options(MYSQLI_OPT_SSL_VERIFY_SERVER_CERT, TRUE);
|
||||
}
|
||||
// Apparently (when it exists), setting MYSQLI_OPT_SSL_VERIFY_SERVER_CERT
|
||||
// to FALSE didn't do anything, so PHP 5.6.16 introduced yet another
|
||||
// constant ...
|
||||
//
|
||||
// https://secure.php.net/ChangeLog-5.php#5.6.16
|
||||
// https://bugs.php.net/bug.php?id=68344
|
||||
elseif (defined('MYSQLI_CLIENT_SSL_DONT_VERIFY_SERVER_CERT'))
|
||||
{
|
||||
$this->_mysqli->options(MYSQLI_CLIENT_SSL_DONT_VERIFY_SERVER_CERT, TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
$client_flags |= MYSQLI_CLIENT_SSL;
|
||||
$this->_mysqli->ssl_set(
|
||||
isset($ssl['key']) ? $ssl['key'] : NULL,
|
||||
isset($ssl['cert']) ? $ssl['cert'] : NULL,
|
||||
isset($ssl['ca']) ? $ssl['ca'] : NULL,
|
||||
isset($ssl['capath']) ? $ssl['capath'] : NULL,
|
||||
isset($ssl['cipher']) ? $ssl['cipher'] : NULL
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->_mysqli->real_connect($hostname, $this->username, $this->password, $this->database, $port, $socket, $client_flags))
|
||||
{
|
||||
// Prior to version 5.7.3, MySQL silently downgrades to an unencrypted connection if SSL setup fails
|
||||
if (
|
||||
($client_flags & MYSQLI_CLIENT_SSL)
|
||||
&& version_compare($this->_mysqli->client_info, '5.7.3', '<=')
|
||||
&& empty($this->_mysqli->query("SHOW STATUS LIKE 'ssl_cipher'")->fetch_object()->Value)
|
||||
)
|
||||
{
|
||||
$this->_mysqli->close();
|
||||
$message = 'MySQLi was configured for an SSL connection, but got an unencrypted connection instead!';
|
||||
Logger::logError($message);
|
||||
return ($this->db->db_debug) ? $this->db->display_error($message, '', TRUE) : FALSE;
|
||||
}
|
||||
|
||||
return $this->_mysqli;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Reconnect
|
||||
*
|
||||
* Keep / reestablish the db connection if no queries have been
|
||||
* sent for a length of time exceeding the server's idle timeout
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function reconnect()
|
||||
{
|
||||
if ($this->conn_id !== FALSE && $this->conn_id->ping() === FALSE)
|
||||
{
|
||||
$this->conn_id = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Select the database
|
||||
*
|
||||
* @param string $database
|
||||
* @return bool
|
||||
*/
|
||||
public function db_select($database = '')
|
||||
{
|
||||
if ($database === '')
|
||||
{
|
||||
$database = $this->database;
|
||||
}
|
||||
|
||||
if ($this->conn_id->select_db($database))
|
||||
{
|
||||
$this->database = $database;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Set client character set
|
||||
*
|
||||
* @param string $charset
|
||||
* @return bool
|
||||
*/
|
||||
protected function _db_set_charset($charset)
|
||||
{
|
||||
return $this->conn_id->set_charset($charset);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Database version number
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function version()
|
||||
{
|
||||
if (isset($this->data_cache['version']))
|
||||
{
|
||||
return $this->data_cache['version'];
|
||||
}
|
||||
|
||||
return $this->data_cache['version'] = $this->conn_id->server_info;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Execute the query
|
||||
*
|
||||
* @param string $sql an SQL query
|
||||
* @return mixed
|
||||
*/
|
||||
protected function _execute($sql)
|
||||
{
|
||||
return $this->conn_id->query($this->_prep_query($sql));
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Prep the query
|
||||
*
|
||||
* If needed, each database adapter can prep the query string
|
||||
*
|
||||
* @param string $sql an SQL query
|
||||
* @return string
|
||||
*/
|
||||
protected function _prep_query($sql)
|
||||
{
|
||||
// mysqli_affected_rows() returns 0 for "DELETE FROM TABLE" queries. This hack
|
||||
// modifies the query so that it a proper number of affected rows is returned.
|
||||
if ($this->delete_hack === TRUE && preg_match('/^\s*DELETE\s+FROM\s+(\S+)\s*$/i', $sql))
|
||||
{
|
||||
return trim($sql).' WHERE 1=1';
|
||||
}
|
||||
|
||||
return $sql;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Begin Transaction
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function _trans_begin()
|
||||
{
|
||||
$this->conn_id->autocommit(FALSE);
|
||||
return Core::isPHP('5.5')
|
||||
? $this->conn_id->begin_transaction()
|
||||
: $this->simple_query('START TRANSACTION'); // can also be BEGIN or BEGIN WORK
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Commit Transaction
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function _trans_commit()
|
||||
{
|
||||
if ($this->conn_id->commit())
|
||||
{
|
||||
$this->conn_id->autocommit(TRUE);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Rollback Transaction
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function _trans_rollback()
|
||||
{
|
||||
if ($this->conn_id->rollback())
|
||||
{
|
||||
$this->conn_id->autocommit(TRUE);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Platform-dependant string escape
|
||||
*
|
||||
* @param string
|
||||
* @return string
|
||||
*/
|
||||
protected function _escape_str($str)
|
||||
{
|
||||
return $this->conn_id->real_escape_string($str);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Affected Rows
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function affected_rows()
|
||||
{
|
||||
return $this->conn_id->affected_rows;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Insert ID
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function insert_id()
|
||||
{
|
||||
return $this->conn_id->insert_id;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* List table query
|
||||
*
|
||||
* Generates a platform-specific query string so that the table names can be fetched
|
||||
*
|
||||
* @param bool $prefix_limit
|
||||
* @return string
|
||||
*/
|
||||
protected function _list_tables($prefix_limit = FALSE)
|
||||
{
|
||||
$sql = 'SHOW TABLES FROM '.$this->escape_identifiers($this->database);
|
||||
|
||||
if ($prefix_limit !== FALSE && $this->dbprefix !== '')
|
||||
{
|
||||
return $sql." LIKE '".$this->escape_like_str($this->dbprefix)."%'";
|
||||
}
|
||||
|
||||
return $sql;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Show column query
|
||||
*
|
||||
* Generates a platform-specific query string so that the column names can be fetched
|
||||
*
|
||||
* @param string $table
|
||||
* @return string
|
||||
*/
|
||||
protected function _list_columns($table = '')
|
||||
{
|
||||
return 'SHOW COLUMNS FROM '.$this->protect_identifiers($table, TRUE, NULL, FALSE);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Returns an object with field data
|
||||
*
|
||||
* @param string $table
|
||||
* @return array
|
||||
*/
|
||||
public function field_data($table)
|
||||
{
|
||||
if (($query = $this->query('SHOW COLUMNS FROM '.$this->protect_identifiers($table, TRUE, NULL, FALSE))) === FALSE)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
$query = $query->result_object();
|
||||
|
||||
$retval = array();
|
||||
for ($i = 0, $c = count($query); $i < $c; $i++)
|
||||
{
|
||||
$retval[$i] = new stdClass();
|
||||
$retval[$i]->name = $query[$i]->Field;
|
||||
|
||||
sscanf($query[$i]->Type, '%[a-z](%d)',
|
||||
$retval[$i]->type,
|
||||
$retval[$i]->max_length
|
||||
);
|
||||
|
||||
$retval[$i]->default = $query[$i]->Default;
|
||||
$retval[$i]->primary_key = (int) ($query[$i]->Key === 'PRI');
|
||||
}
|
||||
|
||||
return $retval;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Error
|
||||
*
|
||||
* Returns an array containing code and message of the last
|
||||
* database error that has occurred.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function error()
|
||||
{
|
||||
if ( ! empty($this->_mysqli->connect_errno))
|
||||
{
|
||||
return array(
|
||||
'code' => $this->_mysqli->connect_errno,
|
||||
'message' => Core::isPHP('5.2.9') ? $this->_mysqli->connect_error : mysqli_connect_error()
|
||||
);
|
||||
}
|
||||
|
||||
return array('code' => $this->conn_id->errno, 'message' => $this->conn_id->error);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* FROM tables
|
||||
*
|
||||
* Groups tables in FROM clauses if needed, so there is no confusion
|
||||
* about operator precedence.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function _from_tables()
|
||||
{
|
||||
if ( ! empty($this->qb_join) && count($this->qb_from) > 1)
|
||||
{
|
||||
return '('.implode(', ', $this->qb_from).')';
|
||||
}
|
||||
|
||||
return implode(', ', $this->qb_from);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Close DB Connection
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _close()
|
||||
{
|
||||
$this->conn_id->close();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,240 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2015 TechFuze
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 1.0.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* MySQLi Forge Class
|
||||
*
|
||||
* Converted from CodeIgniter.
|
||||
*
|
||||
* @package FuzeWorks
|
||||
* @subpackage Drivers
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
*/
|
||||
class FW_DB_mysqli_forge extends FW_DB_forge {
|
||||
|
||||
/**
|
||||
* CREATE DATABASE statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_create_database = 'CREATE DATABASE %s CHARACTER SET %s COLLATE %s';
|
||||
|
||||
/**
|
||||
* CREATE TABLE keys flag
|
||||
*
|
||||
* Whether table keys are created from within the
|
||||
* CREATE TABLE statement.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $_create_table_keys = TRUE;
|
||||
|
||||
/**
|
||||
* UNSIGNED support
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_unsigned = array(
|
||||
'TINYINT',
|
||||
'SMALLINT',
|
||||
'MEDIUMINT',
|
||||
'INT',
|
||||
'INTEGER',
|
||||
'BIGINT',
|
||||
'REAL',
|
||||
'DOUBLE',
|
||||
'DOUBLE PRECISION',
|
||||
'FLOAT',
|
||||
'DECIMAL',
|
||||
'NUMERIC'
|
||||
);
|
||||
|
||||
/**
|
||||
* NULL value representation in CREATE/ALTER TABLE statements
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_null = 'NULL';
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* CREATE TABLE attributes
|
||||
*
|
||||
* @param array $attributes Associative array of table attributes
|
||||
* @return string
|
||||
*/
|
||||
protected function _create_table_attr($attributes)
|
||||
{
|
||||
$sql = '';
|
||||
|
||||
foreach (array_keys($attributes) as $key)
|
||||
{
|
||||
if (is_string($key))
|
||||
{
|
||||
$sql .= ' '.strtoupper($key).' = '.$attributes[$key];
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! empty($this->db->char_set) && ! strpos($sql, 'CHARACTER SET') && ! strpos($sql, 'CHARSET'))
|
||||
{
|
||||
$sql .= ' DEFAULT CHARACTER SET = '.$this->db->char_set;
|
||||
}
|
||||
|
||||
if ( ! empty($this->db->dbcollat) && ! strpos($sql, 'COLLATE'))
|
||||
{
|
||||
$sql .= ' COLLATE = '.$this->db->dbcollat;
|
||||
}
|
||||
|
||||
return $sql;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* ALTER TABLE
|
||||
*
|
||||
* @param string $alter_type ALTER type
|
||||
* @param string $table Table name
|
||||
* @param mixed $field Column definition
|
||||
* @return string|string[]
|
||||
*/
|
||||
protected function _alter_table($alter_type, $table, $field)
|
||||
{
|
||||
if ($alter_type === 'DROP')
|
||||
{
|
||||
return parent::_alter_table($alter_type, $table, $field);
|
||||
}
|
||||
|
||||
$sql = 'ALTER TABLE '.$this->db->escape_identifiers($table);
|
||||
for ($i = 0, $c = count($field); $i < $c; $i++)
|
||||
{
|
||||
if ($field[$i]['_literal'] !== FALSE)
|
||||
{
|
||||
$field[$i] = ($alter_type === 'ADD')
|
||||
? "\n\tADD ".$field[$i]['_literal']
|
||||
: "\n\tMODIFY ".$field[$i]['_literal'];
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($alter_type === 'ADD')
|
||||
{
|
||||
$field[$i]['_literal'] = "\n\tADD ";
|
||||
}
|
||||
else
|
||||
{
|
||||
$field[$i]['_literal'] = empty($field[$i]['new_name']) ? "\n\tMODIFY " : "\n\tCHANGE ";
|
||||
}
|
||||
|
||||
$field[$i] = $field[$i]['_literal'].$this->_process_column($field[$i]);
|
||||
}
|
||||
}
|
||||
|
||||
return array($sql.implode(',', $field));
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Process column
|
||||
*
|
||||
* @param array $field
|
||||
* @return string
|
||||
*/
|
||||
protected function _process_column($field)
|
||||
{
|
||||
$extra_clause = isset($field['after'])
|
||||
? ' AFTER '.$this->db->escape_identifiers($field['after']) : '';
|
||||
|
||||
if (empty($extra_clause) && isset($field['first']) && $field['first'] === TRUE)
|
||||
{
|
||||
$extra_clause = ' FIRST';
|
||||
}
|
||||
|
||||
return $this->db->escape_identifiers($field['name'])
|
||||
.(empty($field['new_name']) ? '' : ' '.$this->db->escape_identifiers($field['new_name']))
|
||||
.' '.$field['type'].$field['length']
|
||||
.$field['unsigned']
|
||||
.$field['null']
|
||||
.$field['default']
|
||||
.$field['auto_increment']
|
||||
.$field['unique']
|
||||
.(empty($field['comment']) ? '' : ' COMMENT '.$field['comment'])
|
||||
.$extra_clause;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Process indexes
|
||||
*
|
||||
* @param string $table (ignored)
|
||||
* @return string
|
||||
*/
|
||||
protected function _process_indexes($table)
|
||||
{
|
||||
$sql = '';
|
||||
|
||||
for ($i = 0, $c = count($this->keys); $i < $c; $i++)
|
||||
{
|
||||
if (is_array($this->keys[$i]))
|
||||
{
|
||||
for ($i2 = 0, $c2 = count($this->keys[$i]); $i2 < $c2; $i2++)
|
||||
{
|
||||
if ( ! isset($this->fields[$this->keys[$i][$i2]]))
|
||||
{
|
||||
unset($this->keys[$i][$i2]);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
elseif ( ! isset($this->fields[$this->keys[$i]]))
|
||||
{
|
||||
unset($this->keys[$i]);
|
||||
continue;
|
||||
}
|
||||
|
||||
is_array($this->keys[$i]) OR $this->keys[$i] = array($this->keys[$i]);
|
||||
|
||||
$sql .= ",\n\tKEY ".$this->db->escape_identifiers(implode('_', $this->keys[$i]))
|
||||
.' ('.implode(', ', $this->db->escape_identifiers($this->keys[$i])).')';
|
||||
}
|
||||
|
||||
$this->keys = array();
|
||||
|
||||
return $sql;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,182 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2015 TechFuze
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 1.0.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* MySQLi Result Class
|
||||
*
|
||||
* This class extends the parent result class: FW_DB_result
|
||||
*
|
||||
* Converted from CodeIgniter.
|
||||
*
|
||||
* @package FuzeWorks
|
||||
* @subpackage Drivers
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
*/
|
||||
class FW_DB_mysqli_result extends FW_DB_result {
|
||||
|
||||
/**
|
||||
* Number of rows in the result set
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function num_rows()
|
||||
{
|
||||
return is_int($this->num_rows)
|
||||
? $this->num_rows
|
||||
: $this->num_rows = $this->result_id->num_rows;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Number of fields in the result set
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function num_fields()
|
||||
{
|
||||
return $this->result_id->field_count;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Fetch Field Names
|
||||
*
|
||||
* Generates an array of column names
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function list_fields()
|
||||
{
|
||||
$field_names = array();
|
||||
$this->result_id->field_seek(0);
|
||||
while ($field = $this->result_id->fetch_field())
|
||||
{
|
||||
$field_names[] = $field->name;
|
||||
}
|
||||
|
||||
return $field_names;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Field data
|
||||
*
|
||||
* Generates an array of objects containing field meta-data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function field_data()
|
||||
{
|
||||
$retval = array();
|
||||
$field_data = $this->result_id->fetch_fields();
|
||||
for ($i = 0, $c = count($field_data); $i < $c; $i++)
|
||||
{
|
||||
$retval[$i] = new stdClass();
|
||||
$retval[$i]->name = $field_data[$i]->name;
|
||||
$retval[$i]->type = $field_data[$i]->type;
|
||||
$retval[$i]->max_length = $field_data[$i]->max_length;
|
||||
$retval[$i]->primary_key = (int) ($field_data[$i]->flags & 2);
|
||||
$retval[$i]->default = $field_data[$i]->def;
|
||||
}
|
||||
|
||||
return $retval;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Free the result
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function free_result()
|
||||
{
|
||||
if (is_object($this->result_id))
|
||||
{
|
||||
$this->result_id->free();
|
||||
$this->result_id = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Data Seek
|
||||
*
|
||||
* Moves the internal pointer to the desired offset. We call
|
||||
* this internally before fetching results to make sure the
|
||||
* result set starts at zero.
|
||||
*
|
||||
* @param int $n
|
||||
* @return bool
|
||||
*/
|
||||
public function data_seek($n = 0)
|
||||
{
|
||||
return $this->result_id->data_seek($n);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Result - associative array
|
||||
*
|
||||
* Returns the result set as an array
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function _fetch_assoc()
|
||||
{
|
||||
return $this->result_id->fetch_assoc();
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Result - object
|
||||
*
|
||||
* Returns the result set as an object
|
||||
*
|
||||
* @param string $class_name
|
||||
* @return object
|
||||
*/
|
||||
protected function _fetch_object($class_name = 'stdClass')
|
||||
{
|
||||
return $this->result_id->fetch_object($class_name);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,209 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2015 TechFuze
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 1.0.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* MySQLi Utility Class
|
||||
*
|
||||
* Converted from CodeIgniter.
|
||||
*
|
||||
* @package FuzeWorks
|
||||
* @subpackage Drivers
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
*/
|
||||
class FW_DB_mysqli_utility extends FW_DB_utility {
|
||||
|
||||
/**
|
||||
* List databases statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_list_databases = 'SHOW DATABASES';
|
||||
|
||||
/**
|
||||
* OPTIMIZE TABLE statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_optimize_table = 'OPTIMIZE TABLE %s';
|
||||
|
||||
/**
|
||||
* REPAIR TABLE statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_repair_table = 'REPAIR TABLE %s';
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Export
|
||||
*
|
||||
* @param array $params Preferences
|
||||
* @return mixed
|
||||
*/
|
||||
protected function _backup($params = array())
|
||||
{
|
||||
if (count($params) === 0)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// Extract the prefs for simplicity
|
||||
extract($params);
|
||||
|
||||
// Build the output
|
||||
$output = '';
|
||||
|
||||
// Do we need to include a statement to disable foreign key checks?
|
||||
if ($foreign_key_checks === FALSE)
|
||||
{
|
||||
$output .= 'SET foreign_key_checks = 0;'.$newline;
|
||||
}
|
||||
|
||||
foreach ( (array) $tables as $table)
|
||||
{
|
||||
// Is the table in the "ignore" list?
|
||||
if (in_array($table, (array) $ignore, TRUE))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// Get the table schema
|
||||
$query = $this->db->query('SHOW CREATE TABLE '.$this->db->escape_identifiers($this->db->database.'.'.$table));
|
||||
|
||||
// No result means the table name was invalid
|
||||
if ($query === FALSE)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// Write out the table schema
|
||||
$output .= '#'.$newline.'# TABLE STRUCTURE FOR: '.$table.$newline.'#'.$newline.$newline;
|
||||
|
||||
if ($add_drop === TRUE)
|
||||
{
|
||||
$output .= 'DROP TABLE IF EXISTS '.$this->db->protect_identifiers($table).';'.$newline.$newline;
|
||||
}
|
||||
|
||||
$i = 0;
|
||||
$result = $query->result_array();
|
||||
foreach ($result[0] as $val)
|
||||
{
|
||||
if ($i++ % 2)
|
||||
{
|
||||
$output .= $val.';'.$newline.$newline;
|
||||
}
|
||||
}
|
||||
|
||||
// If inserts are not needed we're done...
|
||||
if ($add_insert === FALSE)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// Grab all the data from the current table
|
||||
$query = $this->db->query('SELECT * FROM '.$this->db->protect_identifiers($table));
|
||||
|
||||
if ($query->num_rows() === 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// Fetch the field names and determine if the field is an
|
||||
// integer type. We use this info to decide whether to
|
||||
// surround the data with quotes or not
|
||||
|
||||
$i = 0;
|
||||
$field_str = '';
|
||||
$is_int = array();
|
||||
while ($field = $query->result_id->fetch_field())
|
||||
{
|
||||
// Most versions of MySQL store timestamp as a string
|
||||
$is_int[$i] = in_array(strtolower($field->type),
|
||||
array('tinyint', 'smallint', 'mediumint', 'int', 'bigint'), //, 'timestamp'),
|
||||
TRUE);
|
||||
|
||||
// Create a string of field names
|
||||
$field_str .= $this->db->escape_identifiers($field->name).', ';
|
||||
$i++;
|
||||
}
|
||||
|
||||
// Trim off the end comma
|
||||
$field_str = preg_replace('/, $/' , '', $field_str);
|
||||
|
||||
// Build the insert string
|
||||
foreach ($query->result_array() as $row)
|
||||
{
|
||||
$val_str = '';
|
||||
|
||||
$i = 0;
|
||||
foreach ($row as $v)
|
||||
{
|
||||
// Is the value NULL?
|
||||
if ($v === NULL)
|
||||
{
|
||||
$val_str .= 'NULL';
|
||||
}
|
||||
else
|
||||
{
|
||||
// Escape the data if it's not an integer
|
||||
$val_str .= ($is_int[$i] === FALSE) ? $this->db->escape($v) : $v;
|
||||
}
|
||||
|
||||
// Append a comma
|
||||
$val_str .= ', ';
|
||||
$i++;
|
||||
}
|
||||
|
||||
// Remove the comma at the end of the string
|
||||
$val_str = preg_replace('/, $/' , '', $val_str);
|
||||
|
||||
// Build the INSERT string
|
||||
$output .= 'INSERT INTO '.$this->db->protect_identifiers($table).' ('.$field_str.') VALUES ('.$val_str.');'.$newline;
|
||||
}
|
||||
|
||||
$output .= $newline.$newline;
|
||||
}
|
||||
|
||||
// Do we need to include a statement to re-enable foreign key checks?
|
||||
if ($foreign_key_checks === FALSE)
|
||||
{
|
||||
$output .= 'SET foreign_key_checks = 1;'.$newline;
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,680 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2015 TechFuze
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 1.0.0
|
||||
*/
|
||||
|
||||
use FuzeWorks\Logger;
|
||||
use FuzeWorks\Core;
|
||||
|
||||
/**
|
||||
* oci8 Database Adapter Class
|
||||
*
|
||||
* Note: _DB is an extender class that the app controller
|
||||
* creates dynamically based on whether the query builder
|
||||
* class is being used or not.
|
||||
*
|
||||
* Converted from CodeIgniter.
|
||||
*
|
||||
* @package FuzeWorks
|
||||
* @subpackage Drivers
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
*/
|
||||
|
||||
/**
|
||||
* oci8 Database Adapter Class
|
||||
*
|
||||
* This is a modification of the DB_driver class to
|
||||
* permit access to oracle databases
|
||||
*
|
||||
* @author Kelly McArdle
|
||||
*/
|
||||
class FW_DB_oci8_driver extends FW_DB {
|
||||
|
||||
/**
|
||||
* Database driver
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $dbdriver = 'oci8';
|
||||
|
||||
/**
|
||||
* Statement ID
|
||||
*
|
||||
* @var resource
|
||||
*/
|
||||
public $stmt_id;
|
||||
|
||||
/**
|
||||
* Cursor ID
|
||||
*
|
||||
* @var resource
|
||||
*/
|
||||
public $curs_id;
|
||||
|
||||
/**
|
||||
* Commit mode flag
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
|
||||
/**
|
||||
* Limit used flag
|
||||
*
|
||||
* If we use LIMIT, we'll add a field that will
|
||||
* throw off num_fields later.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $limit_used;
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Reset $stmt_id flag
|
||||
*
|
||||
* Used by stored_procedure() to prevent _execute() from
|
||||
* re-setting the statement ID.
|
||||
*/
|
||||
protected $_reset_stmt_id = TRUE;
|
||||
|
||||
/**
|
||||
* List of reserved identifiers
|
||||
*
|
||||
* Identifiers that must NOT be escaped.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $_reserved_identifiers = array('*', 'rownum');
|
||||
|
||||
/**
|
||||
* ORDER BY random keyword
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_random_keyword = array('ASC', 'ASC'); // not currently supported
|
||||
|
||||
/**
|
||||
* COUNT string
|
||||
*
|
||||
* @used-by FW_DB_driver::count_all()
|
||||
* @used-by FW_DB_query_builder::count_all_results()
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_count_string = 'SELECT COUNT(1) AS ';
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param array $params
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($params)
|
||||
{
|
||||
parent::__construct($params);
|
||||
|
||||
$valid_dsns = array(
|
||||
'tns' => '/^\(DESCRIPTION=(\(.+\)){2,}\)$/', // TNS
|
||||
// Easy Connect string (Oracle 10g+)
|
||||
'ec' => '/^(\/\/)?[a-z0-9.:_-]+(:[1-9][0-9]{0,4})?(\/[a-z0-9$_]+)?(:[^\/])?(\/[a-z0-9$_]+)?$/i',
|
||||
'in' => '/^[a-z0-9$_]+$/i' // Instance name (defined in tnsnames.ora)
|
||||
);
|
||||
|
||||
/* Space characters don't have any effect when actually
|
||||
* connecting, but can be a hassle while validating the DSN.
|
||||
*/
|
||||
$this->dsn = str_replace(array("\n", "\r", "\t", ' '), '', $this->dsn);
|
||||
|
||||
if ($this->dsn !== '')
|
||||
{
|
||||
foreach ($valid_dsns as $regexp)
|
||||
{
|
||||
if (preg_match($regexp, $this->dsn))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Legacy support for TNS in the hostname configuration field
|
||||
$this->hostname = str_replace(array("\n", "\r", "\t", ' '), '', $this->hostname);
|
||||
if (preg_match($valid_dsns['tns'], $this->hostname))
|
||||
{
|
||||
$this->dsn = $this->hostname;
|
||||
return;
|
||||
}
|
||||
elseif ($this->hostname !== '' && strpos($this->hostname, '/') === FALSE && strpos($this->hostname, ':') === FALSE
|
||||
&& (( ! empty($this->port) && ctype_digit($this->port)) OR $this->database !== ''))
|
||||
{
|
||||
/* If the hostname field isn't empty, doesn't contain
|
||||
* ':' and/or '/' and if port and/or database aren't
|
||||
* empty, then the hostname field is most likely indeed
|
||||
* just a hostname. Therefore we'll try and build an
|
||||
* Easy Connect string from these 3 settings, assuming
|
||||
* that the database field is a service name.
|
||||
*/
|
||||
$this->dsn = $this->hostname
|
||||
.(( ! empty($this->port) && ctype_digit($this->port)) ? ':'.$this->port : '')
|
||||
.($this->database !== '' ? '/'.ltrim($this->database, '/') : '');
|
||||
|
||||
if (preg_match($valid_dsns['ec'], $this->dsn))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* At this point, we can only try and validate the hostname and
|
||||
* database fields separately as DSNs.
|
||||
*/
|
||||
if (preg_match($valid_dsns['ec'], $this->hostname) OR preg_match($valid_dsns['in'], $this->hostname))
|
||||
{
|
||||
$this->dsn = $this->hostname;
|
||||
return;
|
||||
}
|
||||
|
||||
$this->database = str_replace(array("\n", "\r", "\t", ' '), '', $this->database);
|
||||
foreach ($valid_dsns as $regexp)
|
||||
{
|
||||
if (preg_match($regexp, $this->database))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* Well - OK, an empty string should work as well.
|
||||
* PHP will try to use environment variables to
|
||||
* determine which Oracle instance to connect to.
|
||||
*/
|
||||
$this->dsn = '';
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Non-persistent database connection
|
||||
*
|
||||
* @param bool $persistent
|
||||
* @return resource
|
||||
*/
|
||||
public function db_connect($persistent = FALSE)
|
||||
{
|
||||
$func = ($persistent === TRUE) ? 'oci_pconnect' : 'oci_connect';
|
||||
return empty($this->char_set)
|
||||
? $func($this->username, $this->password, $this->dsn)
|
||||
: $func($this->username, $this->password, $this->dsn, $this->char_set);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Database version number
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function version()
|
||||
{
|
||||
if (isset($this->data_cache['version']))
|
||||
{
|
||||
return $this->data_cache['version'];
|
||||
}
|
||||
|
||||
if ( ! $this->conn_id OR ($version_string = oci_server_version($this->conn_id)) === FALSE)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
elseif (preg_match('#Release\s(\d+(?:\.\d+)+)#', $version_string, $match))
|
||||
{
|
||||
return $this->data_cache['version'] = $match[1];
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Execute the query
|
||||
*
|
||||
* @param string $sql an SQL query
|
||||
* @return resource
|
||||
*/
|
||||
protected function _execute($sql)
|
||||
{
|
||||
/* Oracle must parse the query before it is run. All of the actions with
|
||||
* the query are based on the statement id returned by oci_parse().
|
||||
*/
|
||||
if ($this->_reset_stmt_id === TRUE)
|
||||
{
|
||||
$this->stmt_id = oci_parse($this->conn_id, $sql);
|
||||
}
|
||||
|
||||
oci_set_prefetch($this->stmt_id, 1000);
|
||||
return oci_execute($this->stmt_id, $this->commit_mode);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Get cursor. Returns a cursor from the database
|
||||
*
|
||||
* @return resource
|
||||
*/
|
||||
public function get_cursor()
|
||||
{
|
||||
return $this->curs_id = oci_new_cursor($this->conn_id);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Stored Procedure. Executes a stored procedure
|
||||
*
|
||||
* @param string package name in which the stored procedure is in
|
||||
* @param string stored procedure name to execute
|
||||
* @param array parameters
|
||||
* @return mixed
|
||||
*
|
||||
* params array keys
|
||||
*
|
||||
* KEY OPTIONAL NOTES
|
||||
* name no the name of the parameter should be in :<param_name> format
|
||||
* value no the value of the parameter. If this is an OUT or IN OUT parameter,
|
||||
* this should be a reference to a variable
|
||||
* type yes the type of the parameter
|
||||
* length yes the max size of the parameter
|
||||
*/
|
||||
public function stored_procedure($package, $procedure, array $params)
|
||||
{
|
||||
if ($package === '' OR $procedure === '')
|
||||
{
|
||||
Logger::logError('Invalid query: '.$package.'.'.$procedure);
|
||||
return ($this->db_debug) ? $this->display_error('db_invalid_query') : FALSE;
|
||||
}
|
||||
|
||||
// Build the query string
|
||||
$sql = 'BEGIN '.$package.'.'.$procedure.'(';
|
||||
|
||||
$have_cursor = FALSE;
|
||||
foreach ($params as $param)
|
||||
{
|
||||
$sql .= $param['name'].',';
|
||||
|
||||
if (isset($param['type']) && $param['type'] === OCI_B_CURSOR)
|
||||
{
|
||||
$have_cursor = TRUE;
|
||||
}
|
||||
}
|
||||
$sql = trim($sql, ',').'); END;';
|
||||
|
||||
$this->_reset_stmt_id = FALSE;
|
||||
$this->stmt_id = oci_parse($this->conn_id, $sql);
|
||||
$this->_bind_params($params);
|
||||
$result = $this->query($sql, FALSE, $have_cursor);
|
||||
$this->_reset_stmt_id = TRUE;
|
||||
return $result;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Bind parameters
|
||||
*
|
||||
* @param array $params
|
||||
* @return void
|
||||
*/
|
||||
protected function _bind_params($params)
|
||||
{
|
||||
if ( ! is_array($params) OR ! is_resource($this->stmt_id))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($params as $param)
|
||||
{
|
||||
foreach (array('name', 'value', 'type', 'length') as $val)
|
||||
{
|
||||
if ( ! isset($param[$val]))
|
||||
{
|
||||
$param[$val] = '';
|
||||
}
|
||||
}
|
||||
|
||||
oci_bind_by_name($this->stmt_id, $param['name'], $param['value'], $param['length'], $param['type']);
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Begin Transaction
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function _trans_begin()
|
||||
{
|
||||
$this->commit_mode = Core::isPHP('5.3.2') ? OCI_NO_AUTO_COMMIT : OCI_DEFAULT;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Commit Transaction
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function _trans_commit()
|
||||
{
|
||||
$this->commit_mode = OCI_COMMIT_ON_SUCCESS;
|
||||
|
||||
return oci_commit($this->conn_id);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Rollback Transaction
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function _trans_rollback()
|
||||
{
|
||||
$this->commit_mode = OCI_COMMIT_ON_SUCCESS;
|
||||
return oci_rollback($this->conn_id);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Affected Rows
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function affected_rows()
|
||||
{
|
||||
return oci_num_rows($this->stmt_id);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Insert ID
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function insert_id()
|
||||
{
|
||||
// not supported in oracle
|
||||
return $this->display_error('db_unsupported_function');
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Show table query
|
||||
*
|
||||
* Generates a platform-specific query string so that the table names can be fetched
|
||||
*
|
||||
* @param bool $prefix_limit
|
||||
* @return string
|
||||
*/
|
||||
protected function _list_tables($prefix_limit = FALSE)
|
||||
{
|
||||
$sql = 'SELECT "TABLE_NAME" FROM "ALL_TABLES"';
|
||||
|
||||
if ($prefix_limit !== FALSE && $this->dbprefix !== '')
|
||||
{
|
||||
return $sql.' WHERE "TABLE_NAME" LIKE \''.$this->escape_like_str($this->dbprefix)."%' "
|
||||
.sprintf($this->_like_escape_str, $this->_like_escape_chr);
|
||||
}
|
||||
|
||||
return $sql;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Show column query
|
||||
*
|
||||
* Generates a platform-specific query string so that the column names can be fetched
|
||||
*
|
||||
* @param string $table
|
||||
* @return string
|
||||
*/
|
||||
protected function _list_columns($table = '')
|
||||
{
|
||||
if (strpos($table, '.') !== FALSE)
|
||||
{
|
||||
sscanf($table, '%[^.].%s', $owner, $table);
|
||||
}
|
||||
else
|
||||
{
|
||||
$owner = $this->username;
|
||||
}
|
||||
|
||||
return 'SELECT COLUMN_NAME FROM ALL_TAB_COLUMNS
|
||||
WHERE UPPER(OWNER) = '.$this->escape(strtoupper($owner)).'
|
||||
AND UPPER(TABLE_NAME) = '.$this->escape(strtoupper($table));
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Returns an object with field data
|
||||
*
|
||||
* @param string $table
|
||||
* @return array
|
||||
*/
|
||||
public function field_data($table)
|
||||
{
|
||||
if (strpos($table, '.') !== FALSE)
|
||||
{
|
||||
sscanf($table, '%[^.].%s', $owner, $table);
|
||||
}
|
||||
else
|
||||
{
|
||||
$owner = $this->username;
|
||||
}
|
||||
|
||||
$sql = 'SELECT COLUMN_NAME, DATA_TYPE, CHAR_LENGTH, DATA_PRECISION, DATA_LENGTH, DATA_DEFAULT, NULLABLE
|
||||
FROM ALL_TAB_COLUMNS
|
||||
WHERE UPPER(OWNER) = '.$this->escape(strtoupper($owner)).'
|
||||
AND UPPER(TABLE_NAME) = '.$this->escape(strtoupper($table));
|
||||
|
||||
if (($query = $this->query($sql)) === FALSE)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
$query = $query->result_object();
|
||||
|
||||
$retval = array();
|
||||
for ($i = 0, $c = count($query); $i < $c; $i++)
|
||||
{
|
||||
$retval[$i] = new stdClass();
|
||||
$retval[$i]->name = $query[$i]->COLUMN_NAME;
|
||||
$retval[$i]->type = $query[$i]->DATA_TYPE;
|
||||
|
||||
$length = ($query[$i]->CHAR_LENGTH > 0)
|
||||
? $query[$i]->CHAR_LENGTH : $query[$i]->DATA_PRECISION;
|
||||
if ($length === NULL)
|
||||
{
|
||||
$length = $query[$i]->DATA_LENGTH;
|
||||
}
|
||||
$retval[$i]->max_length = $length;
|
||||
|
||||
$default = $query[$i]->DATA_DEFAULT;
|
||||
if ($default === NULL && $query[$i]->NULLABLE === 'N')
|
||||
{
|
||||
$default = '';
|
||||
}
|
||||
$retval[$i]->default = $default;
|
||||
}
|
||||
|
||||
return $retval;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Error
|
||||
*
|
||||
* Returns an array containing code and message of the last
|
||||
* database error that has occured.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function error()
|
||||
{
|
||||
/* oci_error() returns an array that already contains the
|
||||
* 'code' and 'message' keys, so we can just return it.
|
||||
*/
|
||||
if (is_resource($this->curs_id))
|
||||
{
|
||||
return oci_error($this->curs_id);
|
||||
}
|
||||
elseif (is_resource($this->stmt_id))
|
||||
{
|
||||
return oci_error($this->stmt_id);
|
||||
}
|
||||
elseif (is_resource($this->conn_id))
|
||||
{
|
||||
return oci_error($this->conn_id);
|
||||
}
|
||||
|
||||
return oci_error();
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Insert batch statement
|
||||
*
|
||||
* Generates a platform-specific insert string from the supplied data
|
||||
*
|
||||
* @param string $table Table name
|
||||
* @param array $keys INSERT keys
|
||||
* @param array $values INSERT values
|
||||
* @return string
|
||||
*/
|
||||
protected function _insert_batch($table, $keys, $values)
|
||||
{
|
||||
$keys = implode(', ', $keys);
|
||||
$sql = "INSERT ALL\n";
|
||||
|
||||
for ($i = 0, $c = count($values); $i < $c; $i++)
|
||||
{
|
||||
$sql .= ' INTO '.$table.' ('.$keys.') VALUES '.$values[$i]."\n";
|
||||
}
|
||||
|
||||
return $sql.'SELECT * FROM dual';
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Truncate statement
|
||||
*
|
||||
* Generates a platform-specific truncate string from the supplied data
|
||||
*
|
||||
* If the database does not support the TRUNCATE statement,
|
||||
* then this method maps to 'DELETE FROM table'
|
||||
*
|
||||
* @param string $table
|
||||
* @return string
|
||||
*/
|
||||
protected function _truncate($table)
|
||||
{
|
||||
return 'TRUNCATE TABLE '.$table;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Delete statement
|
||||
*
|
||||
* Generates a platform-specific delete string from the supplied data
|
||||
*
|
||||
* @param string $table
|
||||
* @return string
|
||||
*/
|
||||
protected function _delete($table)
|
||||
{
|
||||
if ($this->qb_limit)
|
||||
{
|
||||
$this->where('rownum <= ',$this->qb_limit, FALSE);
|
||||
$this->qb_limit = FALSE;
|
||||
}
|
||||
|
||||
return parent::_delete($table);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* LIMIT
|
||||
*
|
||||
* Generates a platform-specific LIMIT clause
|
||||
*
|
||||
* @param string $sql SQL Query
|
||||
* @return string
|
||||
*/
|
||||
protected function _limit($sql)
|
||||
{
|
||||
if (version_compare($this->version(), '12.1', '>='))
|
||||
{
|
||||
// OFFSET-FETCH can be used only with the ORDER BY clause
|
||||
empty($this->qb_orderby) && $sql .= ' ORDER BY 1';
|
||||
|
||||
return $sql.' OFFSET '.(int) $this->qb_offset.' ROWS FETCH NEXT '.$this->qb_limit.' ROWS ONLY';
|
||||
}
|
||||
|
||||
$this->limit_used = TRUE;
|
||||
return 'SELECT * FROM (SELECT inner_query.*, rownum rnum FROM ('.$sql.') inner_query WHERE rownum < '.($this->qb_offset + $this->qb_limit + 1).')'
|
||||
.($this->qb_offset ? ' WHERE rnum >= '.($this->qb_offset + 1) : '');
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Close DB Connection
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _close()
|
||||
{
|
||||
oci_close($this->conn_id);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,146 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2015 TechFuze
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 1.0.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* Oracle Forge Class
|
||||
*
|
||||
* Converted from CodeIgniter.
|
||||
*
|
||||
* @package FuzeWorks
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
*/
|
||||
class FW_DB_oci8_forge extends FW_DB_forge {
|
||||
|
||||
/**
|
||||
* CREATE DATABASE statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_create_database = FALSE;
|
||||
|
||||
/**
|
||||
* DROP DATABASE statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_drop_database = FALSE;
|
||||
|
||||
/**
|
||||
* DROP TABLE IF statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_drop_table_if = FALSE;
|
||||
|
||||
/**
|
||||
* UNSIGNED support
|
||||
*
|
||||
* @var bool|array
|
||||
*/
|
||||
protected $_unsigned = FALSE;
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* ALTER TABLE
|
||||
*
|
||||
* @param string $alter_type ALTER type
|
||||
* @param string $table Table name
|
||||
* @param mixed $field Column definition
|
||||
* @return string|string[]
|
||||
*/
|
||||
protected function _alter_table($alter_type, $table, $field)
|
||||
{
|
||||
if ($alter_type === 'DROP')
|
||||
{
|
||||
return parent::_alter_table($alter_type, $table, $field);
|
||||
}
|
||||
elseif ($alter_type === 'CHANGE')
|
||||
{
|
||||
$alter_type = 'MODIFY';
|
||||
}
|
||||
|
||||
$sql = 'ALTER TABLE '.$this->db->escape_identifiers($table);
|
||||
$sqls = array();
|
||||
for ($i = 0, $c = count($field); $i < $c; $i++)
|
||||
{
|
||||
if ($field[$i]['_literal'] !== FALSE)
|
||||
{
|
||||
$field[$i] = "\n\t".$field[$i]['_literal'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$field[$i]['_literal'] = "\n\t".$this->_process_column($field[$i]);
|
||||
|
||||
if ( ! empty($field[$i]['comment']))
|
||||
{
|
||||
$sqls[] = 'COMMENT ON COLUMN '
|
||||
.$this->db->escape_identifiers($table).'.'.$this->db->escape_identifiers($field[$i]['name'])
|
||||
.' IS '.$field[$i]['comment'];
|
||||
}
|
||||
|
||||
if ($alter_type === 'MODIFY' && ! empty($field[$i]['new_name']))
|
||||
{
|
||||
$sqls[] = $sql.' RENAME COLUMN '.$this->db->escape_identifiers($field[$i]['name'])
|
||||
.' '.$this->db->escape_identifiers($field[$i]['new_name']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$sql .= ' '.$alter_type.' ';
|
||||
$sql .= (count($field) === 1)
|
||||
? $field[0]
|
||||
: '('.implode(',', $field).')';
|
||||
|
||||
// RENAME COLUMN must be executed after MODIFY
|
||||
array_unshift($sqls, $sql);
|
||||
return $sql;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Field attribute AUTO_INCREMENT
|
||||
*
|
||||
* @param array &$attributes
|
||||
* @param array &$field
|
||||
* @return void
|
||||
*/
|
||||
protected function _attr_auto_increment(&$attributes, &$field)
|
||||
{
|
||||
// Not supported - sequences and triggers must be used instead
|
||||
}
|
||||
|
||||
}
|
|
@ -1,226 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2015 TechFuze
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 1.0.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* oci8 Result Class
|
||||
*
|
||||
* This class extends the parent result class: FW_DB_result
|
||||
*
|
||||
* Converted from CodeIgniter.
|
||||
*
|
||||
* @package FuzeWorks
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
*/
|
||||
class FW_DB_oci8_result extends FW_DB_result {
|
||||
|
||||
/**
|
||||
* Statement ID
|
||||
*
|
||||
* @var resource
|
||||
*/
|
||||
public $stmt_id;
|
||||
|
||||
/**
|
||||
* Cursor ID
|
||||
*
|
||||
* @var resource
|
||||
*/
|
||||
public $curs_id;
|
||||
|
||||
/**
|
||||
* Limit used flag
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $limit_used;
|
||||
|
||||
/**
|
||||
* Commit mode flag
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $commit_mode;
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param object &$driver_object
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(&$driver_object)
|
||||
{
|
||||
parent::__construct($driver_object);
|
||||
|
||||
$this->stmt_id = $driver_object->stmt_id;
|
||||
$this->curs_id = $driver_object->curs_id;
|
||||
$this->limit_used = $driver_object->limit_used;
|
||||
$this->commit_mode =& $driver_object->commit_mode;
|
||||
$driver_object->stmt_id = FALSE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Number of fields in the result set
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function num_fields()
|
||||
{
|
||||
$count = oci_num_fields($this->stmt_id);
|
||||
|
||||
// if we used a limit we subtract it
|
||||
return ($this->limit_used) ? $count - 1 : $count;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Fetch Field Names
|
||||
*
|
||||
* Generates an array of column names
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function list_fields()
|
||||
{
|
||||
$field_names = array();
|
||||
for ($c = 1, $fieldCount = $this->num_fields(); $c <= $fieldCount; $c++)
|
||||
{
|
||||
$field_names[] = oci_field_name($this->stmt_id, $c);
|
||||
}
|
||||
return $field_names;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Field data
|
||||
*
|
||||
* Generates an array of objects containing field meta-data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function field_data()
|
||||
{
|
||||
$retval = array();
|
||||
for ($c = 1, $fieldCount = $this->num_fields(); $c <= $fieldCount; $c++)
|
||||
{
|
||||
$F = new stdClass();
|
||||
$F->name = oci_field_name($this->stmt_id, $c);
|
||||
$F->type = oci_field_type($this->stmt_id, $c);
|
||||
$F->max_length = oci_field_size($this->stmt_id, $c);
|
||||
|
||||
$retval[] = $F;
|
||||
}
|
||||
|
||||
return $retval;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Free the result
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function free_result()
|
||||
{
|
||||
if (is_resource($this->result_id))
|
||||
{
|
||||
oci_free_statement($this->result_id);
|
||||
$this->result_id = FALSE;
|
||||
}
|
||||
|
||||
if (is_resource($this->stmt_id))
|
||||
{
|
||||
oci_free_statement($this->stmt_id);
|
||||
}
|
||||
|
||||
if (is_resource($this->curs_id))
|
||||
{
|
||||
oci_cancel($this->curs_id);
|
||||
$this->curs_id = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Result - associative array
|
||||
*
|
||||
* Returns the result set as an array
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function _fetch_assoc()
|
||||
{
|
||||
$id = ($this->curs_id) ? $this->curs_id : $this->stmt_id;
|
||||
return oci_fetch_assoc($id);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Result - object
|
||||
*
|
||||
* Returns the result set as an object
|
||||
*
|
||||
* @param string $class_name
|
||||
* @return object
|
||||
*/
|
||||
protected function _fetch_object($class_name = 'stdClass')
|
||||
{
|
||||
$row = ($this->curs_id)
|
||||
? oci_fetch_object($this->curs_id)
|
||||
: oci_fetch_object($this->stmt_id);
|
||||
|
||||
if ($class_name === 'stdClass' OR ! $row)
|
||||
{
|
||||
return $row;
|
||||
}
|
||||
|
||||
$class_name = new $class_name();
|
||||
foreach ($row as $key => $value)
|
||||
{
|
||||
$class_name->$key = $value;
|
||||
}
|
||||
|
||||
return $class_name;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,65 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2015 TechFuze
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 1.0.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* Oracle Utility Class
|
||||
*
|
||||
* Converted from CodeIgniter.
|
||||
*
|
||||
* @package FuzeWorks
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
*/
|
||||
class FW_DB_oci8_utility extends FW_DB_utility {
|
||||
|
||||
/**
|
||||
* List databases statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_list_databases = 'SELECT username FROM dba_users'; // Schemas are actual usernames
|
||||
|
||||
/**
|
||||
* Export
|
||||
*
|
||||
* @param array $params Preferences
|
||||
* @return mixed
|
||||
*/
|
||||
protected function _backup($params = array())
|
||||
{
|
||||
// Currently unsupported
|
||||
return $this->db->display_error('db_unsupported_feature');
|
||||
}
|
||||
|
||||
}
|
|
@ -1,374 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2015 TechFuze
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 1.0.0
|
||||
*/
|
||||
|
||||
use FuzeWorks\Utf8;
|
||||
|
||||
/**
|
||||
* ODBC Database Adapter Class
|
||||
*
|
||||
* Note: _DB is an extender class that the app controller
|
||||
* creates dynamically based on whether the query builder
|
||||
* class is being used or not.
|
||||
*
|
||||
* Converted from CodeIgniter.
|
||||
*
|
||||
* @package FuzeWorks
|
||||
* @subpackage Drivers
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
*/
|
||||
class FW_DB_odbc_driver extends FW_DB {
|
||||
|
||||
/**
|
||||
* Database driver
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $dbdriver = 'odbc';
|
||||
|
||||
/**
|
||||
* Database schema
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $schema = 'public';
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Identifier escape character
|
||||
*
|
||||
* Must be empty for ODBC.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_escape_char = '';
|
||||
|
||||
/**
|
||||
* ESCAPE statement string
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_like_escape_str = " {escape '%s'} ";
|
||||
|
||||
/**
|
||||
* ORDER BY random keyword
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_random_keyword = array('RND()', 'RND(%d)');
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param array $params
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($params)
|
||||
{
|
||||
parent::__construct($params);
|
||||
|
||||
// Legacy support for DSN in the hostname field
|
||||
if (empty($this->dsn))
|
||||
{
|
||||
$this->dsn = $this->hostname;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Non-persistent database connection
|
||||
*
|
||||
* @param bool $persistent
|
||||
* @return resource
|
||||
*/
|
||||
public function db_connect($persistent = FALSE)
|
||||
{
|
||||
return ($persistent === TRUE)
|
||||
? odbc_pconnect($this->dsn, $this->username, $this->password)
|
||||
: odbc_connect($this->dsn, $this->username, $this->password);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Execute the query
|
||||
*
|
||||
* @param string $sql an SQL query
|
||||
* @return resource
|
||||
*/
|
||||
protected function _execute($sql)
|
||||
{
|
||||
return odbc_exec($this->conn_id, $sql);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Begin Transaction
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function _trans_begin()
|
||||
{
|
||||
return odbc_autocommit($this->conn_id, FALSE);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Commit Transaction
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function _trans_commit()
|
||||
{
|
||||
if (odbc_commit($this->conn_id))
|
||||
{
|
||||
odbc_autocommit($this->conn_id, TRUE);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Rollback Transaction
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function _trans_rollback()
|
||||
{
|
||||
if (odbc_rollback($this->conn_id))
|
||||
{
|
||||
odbc_autocommit($this->conn_id, TRUE);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Determines if a query is a "write" type.
|
||||
*
|
||||
* @param string An SQL query string
|
||||
* @return bool
|
||||
*/
|
||||
public function is_write_type($sql)
|
||||
{
|
||||
if (preg_match('#^(INSERT|UPDATE).*RETURNING\s.+(\,\s?.+)*$#i', $sql))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return parent::is_write_type($sql);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Platform-dependant string escape
|
||||
*
|
||||
* @param string
|
||||
* @return string
|
||||
*/
|
||||
protected function _escape_str($str)
|
||||
{
|
||||
return Utf8::remove_invisible_characters($str);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Affected Rows
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function affected_rows()
|
||||
{
|
||||
return odbc_num_rows($this->result_id);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Insert ID
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function insert_id()
|
||||
{
|
||||
return ($this->db->db_debug) ? $this->db->display_error('db_unsupported_feature') : FALSE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Show table query
|
||||
*
|
||||
* Generates a platform-specific query string so that the table names can be fetched
|
||||
*
|
||||
* @param bool $prefix_limit
|
||||
* @return string
|
||||
*/
|
||||
protected function _list_tables($prefix_limit = FALSE)
|
||||
{
|
||||
$sql = "SELECT table_name FROM information_schema.tables WHERE table_schema = '".$this->schema."'";
|
||||
|
||||
if ($prefix_limit !== FALSE && $this->dbprefix !== '')
|
||||
{
|
||||
return $sql." AND table_name LIKE '".$this->escape_like_str($this->dbprefix)."%' "
|
||||
.sprintf($this->_like_escape_str, $this->_like_escape_chr);
|
||||
}
|
||||
|
||||
return $sql;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Show column query
|
||||
*
|
||||
* Generates a platform-specific query string so that the column names can be fetched
|
||||
*
|
||||
* @param string $table
|
||||
* @return string
|
||||
*/
|
||||
protected function _list_columns($table = '')
|
||||
{
|
||||
return 'SHOW COLUMNS FROM '.$table;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Field data query
|
||||
*
|
||||
* Generates a platform-specific query so that the column data can be retrieved
|
||||
*
|
||||
* @param string $table
|
||||
* @return string
|
||||
*/
|
||||
protected function _field_data($table)
|
||||
{
|
||||
return 'SELECT TOP 1 FROM '.$table;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Error
|
||||
*
|
||||
* Returns an array containing code and message of the last
|
||||
* database error that has occured.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function error()
|
||||
{
|
||||
return array('code' => odbc_error($this->conn_id), 'message' => odbc_errormsg($this->conn_id));
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Update statement
|
||||
*
|
||||
* Generates a platform-specific update string from the supplied data
|
||||
*
|
||||
* @param string $table
|
||||
* @param array $values
|
||||
* @return string
|
||||
*/
|
||||
protected function _update($table, $values)
|
||||
{
|
||||
$this->qb_limit = FALSE;
|
||||
$this->qb_orderby = array();
|
||||
return parent::_update($table, $values);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Truncate statement
|
||||
*
|
||||
* Generates a platform-specific truncate string from the supplied data
|
||||
*
|
||||
* If the database does not support the TRUNCATE statement,
|
||||
* then this method maps to 'DELETE FROM table'
|
||||
*
|
||||
* @param string $table
|
||||
* @return string
|
||||
*/
|
||||
protected function _truncate($table)
|
||||
{
|
||||
return 'DELETE FROM '.$table;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Delete statement
|
||||
*
|
||||
* Generates a platform-specific delete string from the supplied data
|
||||
*
|
||||
* @param string $table
|
||||
* @return string
|
||||
*/
|
||||
protected function _delete($table)
|
||||
{
|
||||
$this->qb_limit = FALSE;
|
||||
return parent::_delete($table);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Close DB Connection
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _close()
|
||||
{
|
||||
odbc_close($this->conn_id);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,82 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2015 TechFuze
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 1.0.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* ODBC Forge Class
|
||||
*
|
||||
* Converted from CodeIgniter.
|
||||
*
|
||||
* @package FuzeWorks
|
||||
* @subpackage Drivers
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/database/
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
*/
|
||||
class FW_DB_odbc_forge extends FW_DB_forge {
|
||||
|
||||
/**
|
||||
* CREATE TABLE IF statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_create_table_if = FALSE;
|
||||
|
||||
/**
|
||||
* DROP TABLE IF statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_drop_table_if = FALSE;
|
||||
|
||||
/**
|
||||
* UNSIGNED support
|
||||
*
|
||||
* @var bool|array
|
||||
*/
|
||||
protected $_unsigned = FALSE;
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Field attribute AUTO_INCREMENT
|
||||
*
|
||||
* @param array &$attributes
|
||||
* @param array &$field
|
||||
* @return void
|
||||
*/
|
||||
protected function _attr_auto_increment(&$attributes, &$field)
|
||||
{
|
||||
// Not supported (in most databases at least)
|
||||
}
|
||||
|
||||
}
|
|
@ -1,264 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2015 TechFuze
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 1.0.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* ODBC Result Class
|
||||
*
|
||||
* This class extends the parent result class: FW_DB_result
|
||||
*
|
||||
* Converted from CodeIgniter.
|
||||
*
|
||||
* @package FuzeWorks
|
||||
* @subpackage Drivers
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
*/
|
||||
class FW_DB_odbc_result extends FW_DB_result {
|
||||
|
||||
/**
|
||||
* Number of rows in the result set
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function num_rows()
|
||||
{
|
||||
if (is_int($this->num_rows))
|
||||
{
|
||||
return $this->num_rows;
|
||||
}
|
||||
elseif (($this->num_rows = odbc_num_rows($this->result_id)) !== -1)
|
||||
{
|
||||
return $this->num_rows;
|
||||
}
|
||||
|
||||
// Work-around for ODBC subdrivers that don't support num_rows()
|
||||
if (count($this->result_array) > 0)
|
||||
{
|
||||
return $this->num_rows = count($this->result_array);
|
||||
}
|
||||
elseif (count($this->result_object) > 0)
|
||||
{
|
||||
return $this->num_rows = count($this->result_object);
|
||||
}
|
||||
|
||||
return $this->num_rows = count($this->result_array());
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Number of fields in the result set
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function num_fields()
|
||||
{
|
||||
return odbc_num_fields($this->result_id);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Fetch Field Names
|
||||
*
|
||||
* Generates an array of column names
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function list_fields()
|
||||
{
|
||||
$field_names = array();
|
||||
$num_fields = $this->num_fields();
|
||||
|
||||
if ($num_fields > 0)
|
||||
{
|
||||
for ($i = 1; $i <= $num_fields; $i++)
|
||||
{
|
||||
$field_names[] = odbc_field_name($this->result_id, $i);
|
||||
}
|
||||
}
|
||||
|
||||
return $field_names;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Field data
|
||||
*
|
||||
* Generates an array of objects containing field meta-data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function field_data()
|
||||
{
|
||||
$retval = array();
|
||||
for ($i = 0, $odbc_index = 1, $c = $this->num_fields(); $i < $c; $i++, $odbc_index++)
|
||||
{
|
||||
$retval[$i] = new stdClass();
|
||||
$retval[$i]->name = odbc_field_name($this->result_id, $odbc_index);
|
||||
$retval[$i]->type = odbc_field_type($this->result_id, $odbc_index);
|
||||
$retval[$i]->max_length = odbc_field_len($this->result_id, $odbc_index);
|
||||
$retval[$i]->primary_key = 0;
|
||||
$retval[$i]->default = '';
|
||||
}
|
||||
|
||||
return $retval;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Free the result
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function free_result()
|
||||
{
|
||||
if (is_resource($this->result_id))
|
||||
{
|
||||
odbc_free_result($this->result_id);
|
||||
$this->result_id = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Result - associative array
|
||||
*
|
||||
* Returns the result set as an array
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function _fetch_assoc()
|
||||
{
|
||||
return odbc_fetch_array($this->result_id);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Result - object
|
||||
*
|
||||
* Returns the result set as an object
|
||||
*
|
||||
* @param string $class_name
|
||||
* @return object
|
||||
*/
|
||||
protected function _fetch_object($class_name = 'stdClass')
|
||||
{
|
||||
$row = odbc_fetch_object($this->result_id);
|
||||
|
||||
if ($class_name === 'stdClass' OR ! $row)
|
||||
{
|
||||
return $row;
|
||||
}
|
||||
|
||||
$class_name = new $class_name();
|
||||
foreach ($row as $key => $value)
|
||||
{
|
||||
$class_name->$key = $value;
|
||||
}
|
||||
|
||||
return $class_name;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
if ( ! function_exists('odbc_fetch_array'))
|
||||
{
|
||||
/**
|
||||
* ODBC Fetch array
|
||||
*
|
||||
* Emulates the native odbc_fetch_array() function when
|
||||
* it is not available (odbc_fetch_array() requires unixODBC)
|
||||
*
|
||||
* @param resource &$result
|
||||
* @param int $rownumber
|
||||
* @return array
|
||||
*/
|
||||
function odbc_fetch_array(&$result, $rownumber = 1)
|
||||
{
|
||||
$rs = array();
|
||||
if ( ! odbc_fetch_into($result, $rs, $rownumber))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$rs_assoc = array();
|
||||
foreach ($rs as $k => $v)
|
||||
{
|
||||
$field_name = odbc_field_name($result, $k+1);
|
||||
$rs_assoc[$field_name] = $v;
|
||||
}
|
||||
|
||||
return $rs_assoc;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
if ( ! function_exists('odbc_fetch_object'))
|
||||
{
|
||||
/**
|
||||
* ODBC Fetch object
|
||||
*
|
||||
* Emulates the native odbc_fetch_object() function when
|
||||
* it is not available.
|
||||
*
|
||||
* @param resource &$result
|
||||
* @param int $rownumber
|
||||
* @return object
|
||||
*/
|
||||
function odbc_fetch_object(&$result, $rownumber = 1)
|
||||
{
|
||||
$rs = array();
|
||||
if ( ! odbc_fetch_into($result, $rs, $rownumber))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$rs_object = new stdClass();
|
||||
foreach ($rs as $k => $v)
|
||||
{
|
||||
$field_name = odbc_field_name($result, $k+1);
|
||||
$rs_object->$field_name = $v;
|
||||
}
|
||||
|
||||
return $rs_object;
|
||||
}
|
||||
}
|
|
@ -1,59 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2015 TechFuze
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 1.0.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* ODBC Utility Class
|
||||
*
|
||||
* Converted from CodeIgniter.
|
||||
*
|
||||
* @package FuzeWorks
|
||||
* @subpackage Drivers
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/database/
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
*/
|
||||
class FW_DB_odbc_utility extends FW_DB_utility {
|
||||
|
||||
/**
|
||||
* Export
|
||||
*
|
||||
* @param array $params Preferences
|
||||
* @return mixed
|
||||
*/
|
||||
protected function _backup($params = array())
|
||||
{
|
||||
// Currently unsupported
|
||||
return $this->db->display_error('db_unsupported_feature');
|
||||
}
|
||||
|
||||
}
|
|
@ -1,371 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2015 TechFuze
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 1.0.0
|
||||
*/
|
||||
|
||||
use FuzeWorks\Logger;
|
||||
use FuzeWorks\Exception\DatabaseException;
|
||||
|
||||
/**
|
||||
* PDO Database Adapter Class
|
||||
*
|
||||
* Note: _DB is an extender class that the app controller
|
||||
* creates dynamically based on whether the query builder
|
||||
* class is being used or not.
|
||||
*
|
||||
* Converted from CodeIgniter.
|
||||
*
|
||||
* @package FuzeWorks
|
||||
* @subpackage Drivers
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
*/
|
||||
class FW_DB_pdo_driver extends FW_DB {
|
||||
|
||||
/**
|
||||
* Database driver
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $dbdriver = 'pdo';
|
||||
|
||||
/**
|
||||
* PDO Options
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $options = array();
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* Validates the DSN string and/or detects the subdriver.
|
||||
*
|
||||
* @param array $params
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($params)
|
||||
{
|
||||
parent::__construct($params);
|
||||
|
||||
if (preg_match('/([^:]+):/', $this->dsn, $match) && count($match) === 2)
|
||||
{
|
||||
// If there is a minimum valid dsn string pattern found, we're done
|
||||
// This is for general PDO users, who tend to have a full DSN string.
|
||||
$this->subdriver = $match[1];
|
||||
return;
|
||||
}
|
||||
// Legacy support for DSN specified in the hostname field
|
||||
elseif (preg_match('/([^:]+):/', $this->hostname, $match) && count($match) === 2)
|
||||
{
|
||||
$this->dsn = $this->hostname;
|
||||
$this->hostname = NULL;
|
||||
$this->subdriver = $match[1];
|
||||
return;
|
||||
}
|
||||
elseif (in_array($this->subdriver, array('mssql', 'sybase'), TRUE))
|
||||
{
|
||||
$this->subdriver = 'dblib';
|
||||
}
|
||||
elseif ($this->subdriver === '4D')
|
||||
{
|
||||
$this->subdriver = '4d';
|
||||
}
|
||||
elseif ( ! in_array($this->subdriver, array('4d', 'cubrid', 'dblib', 'firebird', 'ibm', 'informix', 'mysql', 'oci', 'odbc', 'pgsql', 'sqlite', 'sqlsrv'), TRUE))
|
||||
{
|
||||
Logger::logError('PDO: Invalid or non-existent subdriver');
|
||||
|
||||
if ($this->db_debug)
|
||||
{
|
||||
throw new DatabaseException('Invalid or non-existent PDO subdriver', 1);
|
||||
}
|
||||
}
|
||||
|
||||
$this->dsn = NULL;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Database connection
|
||||
*
|
||||
* @param bool $persistent
|
||||
* @return object
|
||||
*/
|
||||
public function db_connect($persistent = FALSE)
|
||||
{
|
||||
$this->options[PDO::ATTR_PERSISTENT] = $persistent;
|
||||
|
||||
try
|
||||
{
|
||||
return new PDO($this->dsn, $this->username, $this->password, $this->options);
|
||||
}
|
||||
catch (PDOException $e)
|
||||
{
|
||||
if ($this->db_debug && empty($this->failover))
|
||||
{
|
||||
$this->display_error($e->getMessage(), '', TRUE);
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Database version number
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function version()
|
||||
{
|
||||
if (isset($this->data_cache['version']))
|
||||
{
|
||||
return $this->data_cache['version'];
|
||||
}
|
||||
|
||||
// Not all subdrivers support the getAttribute() method
|
||||
try
|
||||
{
|
||||
return $this->data_cache['version'] = $this->conn_id->getAttribute(PDO::ATTR_SERVER_VERSION);
|
||||
}
|
||||
catch (PDOException $e)
|
||||
{
|
||||
return parent::version();
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Execute the query
|
||||
*
|
||||
* @param string $sql SQL query
|
||||
* @return mixed
|
||||
*/
|
||||
protected function _execute($sql)
|
||||
{
|
||||
return $this->conn_id->query($sql);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Begin Transaction
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function _trans_begin()
|
||||
{
|
||||
return $this->conn_id->beginTransaction();
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Commit Transaction
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function _trans_commit()
|
||||
{
|
||||
return $this->conn_id->commit();
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Rollback Transaction
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function _trans_rollback()
|
||||
{
|
||||
return $this->conn_id->rollBack();
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Platform-dependant string escape
|
||||
*
|
||||
* @param string
|
||||
* @return string
|
||||
*/
|
||||
protected function _escape_str($str)
|
||||
{
|
||||
// Escape the string
|
||||
$str = $this->conn_id->quote($str);
|
||||
|
||||
// If there are duplicated quotes, trim them away
|
||||
return ($str[0] === "'")
|
||||
? substr($str, 1, -1)
|
||||
: $str;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Affected Rows
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function affected_rows()
|
||||
{
|
||||
return is_object($this->result_id) ? $this->result_id->rowCount() : 0;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Insert ID
|
||||
*
|
||||
* @param string $name
|
||||
* @return int
|
||||
*/
|
||||
public function insert_id($name = NULL)
|
||||
{
|
||||
return $this->conn_id->lastInsertId($name);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Field data query
|
||||
*
|
||||
* Generates a platform-specific query so that the column data can be retrieved
|
||||
*
|
||||
* @param string $table
|
||||
* @return string
|
||||
*/
|
||||
protected function _field_data($table)
|
||||
{
|
||||
return 'SELECT TOP 1 * FROM '.$this->protect_identifiers($table);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Error
|
||||
*
|
||||
* Returns an array containing code and message of the last
|
||||
* database error that has occured.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function error()
|
||||
{
|
||||
$error = array('code' => '00000', 'message' => '');
|
||||
$pdo_error = $this->conn_id->errorInfo();
|
||||
|
||||
if (empty($pdo_error[0]))
|
||||
{
|
||||
return $error;
|
||||
}
|
||||
|
||||
$error['code'] = isset($pdo_error[1]) ? $pdo_error[0].'/'.$pdo_error[1] : $pdo_error[0];
|
||||
if (isset($pdo_error[2]))
|
||||
{
|
||||
$error['message'] = $pdo_error[2];
|
||||
}
|
||||
|
||||
return $error;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Update_Batch statement
|
||||
*
|
||||
* Generates a platform-specific batch update string from the supplied data
|
||||
*
|
||||
* @param string $table Table name
|
||||
* @param array $values Update data
|
||||
* @param string $index WHERE key
|
||||
* @return string
|
||||
*/
|
||||
protected function _update_batch($table, $values, $index)
|
||||
{
|
||||
$ids = array();
|
||||
foreach ($values as $key => $val)
|
||||
{
|
||||
$ids[] = $val[$index];
|
||||
|
||||
foreach (array_keys($val) as $field)
|
||||
{
|
||||
if ($field !== $index)
|
||||
{
|
||||
$final[$field][] = 'WHEN '.$index.' = '.$val[$index].' THEN '.$val[$field];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$cases = '';
|
||||
foreach ($final as $k => $v)
|
||||
{
|
||||
$cases .= $k.' = CASE '."\n";
|
||||
|
||||
foreach ($v as $row)
|
||||
{
|
||||
$cases .= $row."\n";
|
||||
}
|
||||
|
||||
$cases .= 'ELSE '.$k.' END, ';
|
||||
}
|
||||
|
||||
$this->where($index.' IN('.implode(',', $ids).')', NULL, FALSE);
|
||||
|
||||
return 'UPDATE '.$table.' SET '.substr($cases, 0, -2).$this->_compile_wh('qb_where');
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Truncate statement
|
||||
*
|
||||
* Generates a platform-specific truncate string from the supplied data
|
||||
*
|
||||
* If the database does not support the TRUNCATE statement,
|
||||
* then this method maps to 'DELETE FROM table'
|
||||
*
|
||||
* @param string $table
|
||||
* @return string
|
||||
*/
|
||||
protected function _truncate($table)
|
||||
{
|
||||
return 'TRUNCATE TABLE '.$table;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,61 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2015 TechFuze
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 1.0.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* PDO Forge Class
|
||||
*
|
||||
* Converted from CodeIgniter.
|
||||
*
|
||||
* @package FuzeWorks
|
||||
* @subpackage Drivers
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/database/
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
*/
|
||||
class FW_DB_pdo_forge extends FW_DB_forge {
|
||||
|
||||
/**
|
||||
* CREATE TABLE IF statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_create_table_if = FALSE;
|
||||
|
||||
/**
|
||||
* DROP TABLE IF statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_drop_table_if = FALSE;
|
||||
|
||||
}
|
|
@ -1,194 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2015 TechFuze
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 1.0.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* PDO Result Class
|
||||
*
|
||||
* This class extends the parent result class: FW_DB_result
|
||||
*
|
||||
* Converted from CodeIgniter.
|
||||
*
|
||||
* @package FuzeWorks
|
||||
* @subpackage Drivers
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
*/
|
||||
class FW_DB_pdo_result extends FW_DB_result {
|
||||
|
||||
/**
|
||||
* Number of rows in the result set
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function num_rows()
|
||||
{
|
||||
if (is_int($this->num_rows))
|
||||
{
|
||||
return $this->num_rows;
|
||||
}
|
||||
elseif (count($this->result_array) > 0)
|
||||
{
|
||||
return $this->num_rows = count($this->result_array);
|
||||
}
|
||||
elseif (count($this->result_object) > 0)
|
||||
{
|
||||
return $this->num_rows = count($this->result_object);
|
||||
}
|
||||
elseif (($num_rows = $this->result_id->rowCount()) > 0)
|
||||
{
|
||||
return $this->num_rows = $num_rows;
|
||||
}
|
||||
|
||||
return $this->num_rows = count($this->result_array());
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Number of fields in the result set
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function num_fields()
|
||||
{
|
||||
return $this->result_id->columnCount();
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Fetch Field Names
|
||||
*
|
||||
* Generates an array of column names
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function list_fields()
|
||||
{
|
||||
$field_names = array();
|
||||
for ($i = 0, $c = $this->num_fields(); $i < $c; $i++)
|
||||
{
|
||||
// Might trigger an E_WARNING due to not all subdrivers
|
||||
// supporting getColumnMeta()
|
||||
$field_names[$i] = @$this->result_id->getColumnMeta($i);
|
||||
$field_names[$i] = $field_names[$i]['name'];
|
||||
}
|
||||
|
||||
return $field_names;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Field data
|
||||
*
|
||||
* Generates an array of objects containing field meta-data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function field_data()
|
||||
{
|
||||
try
|
||||
{
|
||||
$retval = array();
|
||||
|
||||
for ($i = 0, $c = $this->num_fields(); $i < $c; $i++)
|
||||
{
|
||||
$field = $this->result_id->getColumnMeta($i);
|
||||
|
||||
$retval[$i] = new stdClass();
|
||||
$retval[$i]->name = $field['name'];
|
||||
$retval[$i]->type = $field['native_type'];
|
||||
$retval[$i]->max_length = ($field['len'] > 0) ? $field['len'] : NULL;
|
||||
$retval[$i]->primary_key = (int) ( ! empty($field['flags']) && in_array('primary_key', $field['flags'], TRUE));
|
||||
}
|
||||
|
||||
return $retval;
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
if ($this->db->db_debug)
|
||||
{
|
||||
return $this->db->display_error('db_unsupported_feature');
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Free the result
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function free_result()
|
||||
{
|
||||
if (is_object($this->result_id))
|
||||
{
|
||||
$this->result_id = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Result - associative array
|
||||
*
|
||||
* Returns the result set as an array
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function _fetch_assoc()
|
||||
{
|
||||
return $this->result_id->fetch(PDO::FETCH_ASSOC);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Result - object
|
||||
*
|
||||
* Returns the result set as an object
|
||||
*
|
||||
* @param string $class_name
|
||||
* @return object
|
||||
*/
|
||||
protected function _fetch_object($class_name = 'stdClass')
|
||||
{
|
||||
return $this->result_id->fetchObject($class_name);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,59 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2015 TechFuze
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 1.0.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* PDO Utility Class
|
||||
*
|
||||
* Converted from CodeIgniter.
|
||||
*
|
||||
* @package FuzeWorks
|
||||
* @subpackage Drivers
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/database/
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
*/
|
||||
class FW_DB_pdo_utility extends FW_DB_utility {
|
||||
|
||||
/**
|
||||
* Export
|
||||
*
|
||||
* @param array $params Preferences
|
||||
* @return mixed
|
||||
*/
|
||||
protected function _backup($params = array())
|
||||
{
|
||||
// Currently unsupported
|
||||
return $this->db->display_error('db_unsupported_feature');
|
||||
}
|
||||
|
||||
}
|
|
@ -1,196 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2015 TechFuze
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 1.0.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* PDO 4D Database Adapter Class
|
||||
*
|
||||
* Note: _DB is an extender class that the app controller
|
||||
* creates dynamically based on whether the query builder
|
||||
* class is being used or not.
|
||||
*
|
||||
* Converted from CodeIgniter.
|
||||
*
|
||||
* @package FuzeWorks
|
||||
* @subpackage Drivers
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
*/
|
||||
class FW_DB_pdo_4d_driver extends FW_DB_pdo_driver {
|
||||
|
||||
/**
|
||||
* Sub-driver
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $subdriver = '4d';
|
||||
|
||||
/**
|
||||
* Identifier escape character
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $_escape_char = array('[', ']');
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* Builds the DSN if not already set.
|
||||
*
|
||||
* @param array $params
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($params)
|
||||
{
|
||||
parent::__construct($params);
|
||||
|
||||
if (empty($this->dsn))
|
||||
{
|
||||
$this->dsn = '4D:host='.(empty($this->hostname) ? '127.0.0.1' : $this->hostname);
|
||||
|
||||
empty($this->port) OR $this->dsn .= ';port='.$this->port;
|
||||
empty($this->database) OR $this->dsn .= ';dbname='.$this->database;
|
||||
empty($this->char_set) OR $this->dsn .= ';charset='.$this->char_set;
|
||||
}
|
||||
elseif ( ! empty($this->char_set) && strpos($this->dsn, 'charset=', 3) === FALSE)
|
||||
{
|
||||
$this->dsn .= ';charset='.$this->char_set;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Show table query
|
||||
*
|
||||
* Generates a platform-specific query string so that the table names can be fetched
|
||||
*
|
||||
* @param bool $prefix_limit
|
||||
* @return string
|
||||
*/
|
||||
protected function _list_tables($prefix_limit = FALSE)
|
||||
{
|
||||
$sql = 'SELECT '.$this->escape_identifiers('TABLE_NAME').' FROM '.$this->escape_identifiers('_USER_TABLES');
|
||||
|
||||
if ($prefix_limit === TRUE && $this->dbprefix !== '')
|
||||
{
|
||||
$sql .= ' WHERE '.$this->escape_identifiers('TABLE_NAME')." LIKE '".$this->escape_like_str($this->dbprefix)."%' "
|
||||
.sprintf($this->_like_escape_str, $this->_like_escape_chr);
|
||||
}
|
||||
|
||||
return $sql;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Show column query
|
||||
*
|
||||
* Generates a platform-specific query string so that the column names can be fetched
|
||||
*
|
||||
* @param string $table
|
||||
* @return string
|
||||
*/
|
||||
protected function _list_columns($table = '')
|
||||
{
|
||||
return 'SELECT '.$this->escape_identifiers('COLUMN_NAME').' FROM '.$this->escape_identifiers('_USER_COLUMNS')
|
||||
.' WHERE '.$this->escape_identifiers('TABLE_NAME').' = '.$this->escape($table);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Field data query
|
||||
*
|
||||
* Generates a platform-specific query so that the column data can be retrieved
|
||||
*
|
||||
* @param string $table
|
||||
* @return string
|
||||
*/
|
||||
protected function _field_data($table)
|
||||
{
|
||||
return 'SELECT * FROM '.$this->protect_identifiers($table, TRUE, NULL, FALSE).' LIMIT 1';
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Update statement
|
||||
*
|
||||
* Generates a platform-specific update string from the supplied data
|
||||
*
|
||||
* @param string $table
|
||||
* @param array $values
|
||||
* @return string
|
||||
*/
|
||||
protected function _update($table, $values)
|
||||
{
|
||||
$this->qb_limit = FALSE;
|
||||
$this->qb_orderby = array();
|
||||
return parent::_update($table, $values);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Delete statement
|
||||
*
|
||||
* Generates a platform-specific delete string from the supplied data
|
||||
*
|
||||
* @param string $table
|
||||
* @return string
|
||||
*/
|
||||
protected function _delete($table)
|
||||
{
|
||||
$this->qb_limit = FALSE;
|
||||
return parent::_delete($table);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* LIMIT
|
||||
*
|
||||
* Generates a platform-specific LIMIT clause
|
||||
*
|
||||
* @param string $sql SQL Query
|
||||
* @return string
|
||||
*/
|
||||
protected function _limit($sql)
|
||||
{
|
||||
return $sql.' LIMIT '.$this->qb_limit.($this->qb_offset ? ' OFFSET '.$this->qb_offset : '');
|
||||
}
|
||||
|
||||
}
|
|
@ -1,214 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2015 TechFuze
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 1.0.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* PDO 4D Forge Class
|
||||
*
|
||||
* Converted from CodeIgniter.
|
||||
*
|
||||
* @package FuzeWorks
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
*/
|
||||
class FW_DB_pdo_4d_forge extends FW_DB_pdo_forge {
|
||||
|
||||
/**
|
||||
* CREATE DATABASE statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_create_database = 'CREATE SCHEMA %s';
|
||||
|
||||
/**
|
||||
* DROP DATABASE statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_drop_database = 'DROP SCHEMA %s';
|
||||
|
||||
/**
|
||||
* CREATE TABLE IF statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_create_table_if = 'CREATE TABLE IF NOT EXISTS';
|
||||
|
||||
/**
|
||||
* RENAME TABLE statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_rename_table = FALSE;
|
||||
|
||||
/**
|
||||
* DROP TABLE IF statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_drop_table_if = 'DROP TABLE IF EXISTS';
|
||||
|
||||
/**
|
||||
* UNSIGNED support
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_unsigned = array(
|
||||
'INT16' => 'INT',
|
||||
'SMALLINT' => 'INT',
|
||||
'INT' => 'INT64',
|
||||
'INT32' => 'INT64'
|
||||
);
|
||||
|
||||
/**
|
||||
* DEFAULT value representation in CREATE/ALTER TABLE statements
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_default = FALSE;
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* ALTER TABLE
|
||||
*
|
||||
* @param string $alter_type ALTER type
|
||||
* @param string $table Table name
|
||||
* @param mixed $field Column definition
|
||||
* @return string|string[]
|
||||
*/
|
||||
protected function _alter_table($alter_type, $table, $field)
|
||||
{
|
||||
if (in_array($alter_type, array('ADD', 'DROP'), TRUE))
|
||||
{
|
||||
return parent::_alter_table($alter_type, $table, $field);
|
||||
}
|
||||
|
||||
// No method of modifying columns is supported
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Process column
|
||||
*
|
||||
* @param array $field
|
||||
* @return string
|
||||
*/
|
||||
protected function _process_column($field)
|
||||
{
|
||||
return $this->db->escape_identifiers($field['name'])
|
||||
.' '.$field['type'].$field['length']
|
||||
.$field['null']
|
||||
.$field['unique']
|
||||
.$field['auto_increment'];
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Field attribute TYPE
|
||||
*
|
||||
* Performs a data type mapping between different databases.
|
||||
*
|
||||
* @param array &$attributes
|
||||
* @return void
|
||||
*/
|
||||
protected function _attr_type(&$attributes)
|
||||
{
|
||||
switch (strtoupper($attributes['TYPE']))
|
||||
{
|
||||
case 'TINYINT':
|
||||
$attributes['TYPE'] = 'SMALLINT';
|
||||
$attributes['UNSIGNED'] = FALSE;
|
||||
return;
|
||||
case 'MEDIUMINT':
|
||||
$attributes['TYPE'] = 'INTEGER';
|
||||
$attributes['UNSIGNED'] = FALSE;
|
||||
return;
|
||||
case 'INTEGER':
|
||||
$attributes['TYPE'] = 'INT';
|
||||
return;
|
||||
case 'BIGINT':
|
||||
$attributes['TYPE'] = 'INT64';
|
||||
return;
|
||||
default: return;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Field attribute UNIQUE
|
||||
*
|
||||
* @param array &$attributes
|
||||
* @param array &$field
|
||||
* @return void
|
||||
*/
|
||||
protected function _attr_unique(&$attributes, &$field)
|
||||
{
|
||||
if ( ! empty($attributes['UNIQUE']) && $attributes['UNIQUE'] === TRUE)
|
||||
{
|
||||
$field['unique'] = ' UNIQUE';
|
||||
|
||||
// UNIQUE must be used with NOT NULL
|
||||
$field['null'] = ' NOT NULL';
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Field attribute AUTO_INCREMENT
|
||||
*
|
||||
* @param array &$attributes
|
||||
* @param array &$field
|
||||
* @return void
|
||||
*/
|
||||
protected function _attr_auto_increment(&$attributes, &$field)
|
||||
{
|
||||
if ( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE)
|
||||
{
|
||||
if (stripos($field['type'], 'int') !== FALSE)
|
||||
{
|
||||
$field['auto_increment'] = ' AUTO_INCREMENT';
|
||||
}
|
||||
elseif (strcasecmp($field['type'], 'UUID') === 0)
|
||||
{
|
||||
$field['auto_increment'] = ' AUTO_GENERATE';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,246 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2015 TechFuze
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 1.0.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* PDO CUBRID Database Adapter Class
|
||||
*
|
||||
* Note: _DB is an extender class that the app controller
|
||||
* creates dynamically based on whether the query builder
|
||||
* class is being used or not.
|
||||
*
|
||||
* Converted from CodeIgniter.
|
||||
*
|
||||
* @package FuzeWorks
|
||||
* @subpackage Drivers
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
*/
|
||||
class FW_DB_pdo_cubrid_driver extends FW_DB_pdo_driver {
|
||||
|
||||
/**
|
||||
* Sub-driver
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $subdriver = 'cubrid';
|
||||
|
||||
/**
|
||||
* Identifier escape character
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_escape_char = '`';
|
||||
|
||||
/**
|
||||
* ORDER BY random keyword
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_random_keyword = array('RANDOM()', 'RANDOM(%d)');
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* Builds the DSN if not already set.
|
||||
*
|
||||
* @param array $params
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($params)
|
||||
{
|
||||
parent::__construct($params);
|
||||
|
||||
if (empty($this->dsn))
|
||||
{
|
||||
$this->dsn = 'cubrid:host='.(empty($this->hostname) ? '127.0.0.1' : $this->hostname);
|
||||
|
||||
empty($this->port) OR $this->dsn .= ';port='.$this->port;
|
||||
empty($this->database) OR $this->dsn .= ';dbname='.$this->database;
|
||||
empty($this->char_set) OR $this->dsn .= ';charset='.$this->char_set;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Show table query
|
||||
*
|
||||
* Generates a platform-specific query string so that the table names can be fetched
|
||||
*
|
||||
* @param bool $prefix_limit
|
||||
* @return string
|
||||
*/
|
||||
protected function _list_tables($prefix_limit = FALSE)
|
||||
{
|
||||
$sql = 'SHOW TABLES';
|
||||
|
||||
if ($prefix_limit === TRUE && $this->dbprefix !== '')
|
||||
{
|
||||
return $sql." LIKE '".$this->escape_like_str($this->dbprefix)."%'";
|
||||
}
|
||||
|
||||
return $sql;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Show column query
|
||||
*
|
||||
* Generates a platform-specific query string so that the column names can be fetched
|
||||
*
|
||||
* @param string $table
|
||||
* @return string
|
||||
*/
|
||||
protected function _list_columns($table = '')
|
||||
{
|
||||
return 'SHOW COLUMNS FROM '.$this->protect_identifiers($table, TRUE, NULL, FALSE);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Returns an object with field data
|
||||
*
|
||||
* @param string $table
|
||||
* @return array
|
||||
*/
|
||||
public function field_data($table)
|
||||
{
|
||||
if (($query = $this->query('SHOW COLUMNS FROM '.$this->protect_identifiers($table, TRUE, NULL, FALSE))) === FALSE)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
$query = $query->result_object();
|
||||
|
||||
$retval = array();
|
||||
for ($i = 0, $c = count($query); $i < $c; $i++)
|
||||
{
|
||||
$retval[$i] = new stdClass();
|
||||
$retval[$i]->name = $query[$i]->Field;
|
||||
|
||||
sscanf($query[$i]->Type, '%[a-z](%d)',
|
||||
$retval[$i]->type,
|
||||
$retval[$i]->max_length
|
||||
);
|
||||
|
||||
$retval[$i]->default = $query[$i]->Default;
|
||||
$retval[$i]->primary_key = (int) ($query[$i]->Key === 'PRI');
|
||||
}
|
||||
|
||||
return $retval;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Update_Batch statement
|
||||
*
|
||||
* Generates a platform-specific batch update string from the supplied data
|
||||
*
|
||||
* @param string $table Table name
|
||||
* @param array $values Update data
|
||||
* @param string $index WHERE key
|
||||
* @return string
|
||||
*/
|
||||
protected function _update_batch($table, $values, $index)
|
||||
{
|
||||
$ids = array();
|
||||
foreach ($values as $key => $val)
|
||||
{
|
||||
$ids[] = $val[$index];
|
||||
|
||||
foreach (array_keys($val) as $field)
|
||||
{
|
||||
if ($field !== $index)
|
||||
{
|
||||
$final[$field][] = 'WHEN '.$index.' = '.$val[$index].' THEN '.$val[$field];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$cases = '';
|
||||
foreach ($final as $k => $v)
|
||||
{
|
||||
$cases .= $k." = CASE \n"
|
||||
.implode("\n", $v)."\n"
|
||||
.'ELSE '.$k.' END), ';
|
||||
}
|
||||
|
||||
$this->where($index.' IN('.implode(',', $ids).')', NULL, FALSE);
|
||||
|
||||
return 'UPDATE '.$table.' SET '.substr($cases, 0, -2).$this->_compile_wh('qb_where');
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Truncate statement
|
||||
*
|
||||
* Generates a platform-specific truncate string from the supplied data
|
||||
*
|
||||
* If the database does not support the TRUNCATE statement,
|
||||
* then this method maps to 'DELETE FROM table'
|
||||
*
|
||||
* @param string $table
|
||||
* @return string
|
||||
*/
|
||||
protected function _truncate($table)
|
||||
{
|
||||
return 'TRUNCATE '.$table;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* FROM tables
|
||||
*
|
||||
* Groups tables in FROM clauses if needed, so there is no confusion
|
||||
* about operator precedence.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function _from_tables()
|
||||
{
|
||||
if ( ! empty($this->qb_join) && count($this->qb_from) > 1)
|
||||
{
|
||||
return '('.implode(', ', $this->qb_from).')';
|
||||
}
|
||||
|
||||
return implode(', ', $this->qb_from);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,224 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2015 TechFuze
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 1.0.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* PDO CUBRID Forge Class
|
||||
*
|
||||
* Converted from CodeIgniter.
|
||||
*
|
||||
* @package FuzeWorks
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
*/
|
||||
class FW_DB_pdo_cubrid_forge extends FW_DB_pdo_forge {
|
||||
|
||||
/**
|
||||
* CREATE DATABASE statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_create_database = FALSE;
|
||||
|
||||
/**
|
||||
* DROP DATABASE statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_drop_database = FALSE;
|
||||
|
||||
/**
|
||||
* CREATE TABLE keys flag
|
||||
*
|
||||
* Whether table keys are created from within the
|
||||
* CREATE TABLE statement.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $_create_table_keys = TRUE;
|
||||
|
||||
/**
|
||||
* DROP TABLE IF statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_drop_table_if = 'DROP TABLE IF EXISTS';
|
||||
|
||||
/**
|
||||
* UNSIGNED support
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_unsigned = array(
|
||||
'SHORT' => 'INTEGER',
|
||||
'SMALLINT' => 'INTEGER',
|
||||
'INT' => 'BIGINT',
|
||||
'INTEGER' => 'BIGINT',
|
||||
'BIGINT' => 'NUMERIC',
|
||||
'FLOAT' => 'DOUBLE',
|
||||
'REAL' => 'DOUBLE'
|
||||
);
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* ALTER TABLE
|
||||
*
|
||||
* @param string $alter_type ALTER type
|
||||
* @param string $table Table name
|
||||
* @param mixed $field Column definition
|
||||
* @return string|string[]
|
||||
*/
|
||||
protected function _alter_table($alter_type, $table, $field)
|
||||
{
|
||||
if (in_array($alter_type, array('DROP', 'ADD'), TRUE))
|
||||
{
|
||||
return parent::_alter_table($alter_type, $table, $field);
|
||||
}
|
||||
|
||||
$sql = 'ALTER TABLE '.$this->db->escape_identifiers($table);
|
||||
$sqls = array();
|
||||
for ($i = 0, $c = count($field); $i < $c; $i++)
|
||||
{
|
||||
if ($field[$i]['_literal'] !== FALSE)
|
||||
{
|
||||
$sqls[] = $sql.' CHANGE '.$field[$i]['_literal'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$alter_type = empty($field[$i]['new_name']) ? ' MODIFY ' : ' CHANGE ';
|
||||
$sqls[] = $sql.$alter_type.$this->_process_column($field[$i]);
|
||||
}
|
||||
}
|
||||
|
||||
return $sqls;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Process column
|
||||
*
|
||||
* @param array $field
|
||||
* @return string
|
||||
*/
|
||||
protected function _process_column($field)
|
||||
{
|
||||
$extra_clause = isset($field['after'])
|
||||
? ' AFTER '.$this->db->escape_identifiers($field['after']) : '';
|
||||
|
||||
if (empty($extra_clause) && isset($field['first']) && $field['first'] === TRUE)
|
||||
{
|
||||
$extra_clause = ' FIRST';
|
||||
}
|
||||
|
||||
return $this->db->escape_identifiers($field['name'])
|
||||
.(empty($field['new_name']) ? '' : ' '.$this->db->escape_identifiers($field['new_name']))
|
||||
.' '.$field['type'].$field['length']
|
||||
.$field['unsigned']
|
||||
.$field['null']
|
||||
.$field['default']
|
||||
.$field['auto_increment']
|
||||
.$field['unique']
|
||||
.$extra_clause;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Field attribute TYPE
|
||||
*
|
||||
* Performs a data type mapping between different databases.
|
||||
*
|
||||
* @param array &$attributes
|
||||
* @return void
|
||||
*/
|
||||
protected function _attr_type(&$attributes)
|
||||
{
|
||||
switch (strtoupper($attributes['TYPE']))
|
||||
{
|
||||
case 'TINYINT':
|
||||
$attributes['TYPE'] = 'SMALLINT';
|
||||
$attributes['UNSIGNED'] = FALSE;
|
||||
return;
|
||||
case 'MEDIUMINT':
|
||||
$attributes['TYPE'] = 'INTEGER';
|
||||
$attributes['UNSIGNED'] = FALSE;
|
||||
return;
|
||||
default: return;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Process indexes
|
||||
*
|
||||
* @param string $table (ignored)
|
||||
* @return string
|
||||
*/
|
||||
protected function _process_indexes($table)
|
||||
{
|
||||
$sql = '';
|
||||
|
||||
for ($i = 0, $c = count($this->keys); $i < $c; $i++)
|
||||
{
|
||||
if (is_array($this->keys[$i]))
|
||||
{
|
||||
for ($i2 = 0, $c2 = count($this->keys[$i]); $i2 < $c2; $i2++)
|
||||
{
|
||||
if ( ! isset($this->fields[$this->keys[$i][$i2]]))
|
||||
{
|
||||
unset($this->keys[$i][$i2]);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
elseif ( ! isset($this->fields[$this->keys[$i]]))
|
||||
{
|
||||
unset($this->keys[$i]);
|
||||
continue;
|
||||
}
|
||||
|
||||
is_array($this->keys[$i]) OR $this->keys[$i] = array($this->keys[$i]);
|
||||
|
||||
$sql .= ",\n\tKEY ".$this->db->escape_identifiers(implode('_', $this->keys[$i]))
|
||||
.' ('.implode(', ', $this->db->escape_identifiers($this->keys[$i])).')';
|
||||
}
|
||||
|
||||
$this->keys = array();
|
||||
|
||||
return $sql;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,328 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2015 TechFuze
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 1.0.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* PDO DBLIB Database Adapter Class
|
||||
*
|
||||
* Note: _DB is an extender class that the app controller
|
||||
* creates dynamically based on whether the query builder
|
||||
* class is being used or not.
|
||||
*
|
||||
* Converted from CodeIgniter.
|
||||
*
|
||||
* @package FuzeWorks
|
||||
* @subpackage Drivers
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
*/
|
||||
class FW_DB_pdo_dblib_driver extends FW_DB_pdo_driver {
|
||||
|
||||
/**
|
||||
* Sub-driver
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $subdriver = 'dblib';
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* ORDER BY random keyword
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_random_keyword = array('NEWID()', 'RAND(%d)');
|
||||
|
||||
/**
|
||||
* Quoted identifier flag
|
||||
*
|
||||
* Whether to use SQL-92 standard quoted identifier
|
||||
* (double quotes) or brackets for identifier escaping.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $_quoted_identifier;
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* Builds the DSN if not already set.
|
||||
*
|
||||
* @param array $params
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($params)
|
||||
{
|
||||
parent::__construct($params);
|
||||
|
||||
if (empty($this->dsn))
|
||||
{
|
||||
$this->dsn = $params['subdriver'].':host='.(empty($this->hostname) ? '127.0.0.1' : $this->hostname);
|
||||
|
||||
if ( ! empty($this->port))
|
||||
{
|
||||
$this->dsn .= (DIRECTORY_SEPARATOR === '\\' ? ',' : ':').$this->port;
|
||||
}
|
||||
|
||||
empty($this->database) OR $this->dsn .= ';dbname='.$this->database;
|
||||
empty($this->char_set) OR $this->dsn .= ';charset='.$this->char_set;
|
||||
empty($this->appname) OR $this->dsn .= ';appname='.$this->appname;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( ! empty($this->char_set) && strpos($this->dsn, 'charset=', 6) === FALSE)
|
||||
{
|
||||
$this->dsn .= ';charset='.$this->char_set;
|
||||
}
|
||||
|
||||
$this->subdriver = 'dblib';
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Database connection
|
||||
*
|
||||
* @param bool $persistent
|
||||
* @return object
|
||||
*/
|
||||
public function db_connect($persistent = FALSE)
|
||||
{
|
||||
$this->conn_id = parent::db_connect($persistent);
|
||||
|
||||
if ( ! is_object($this->conn_id))
|
||||
{
|
||||
return $this->conn_id;
|
||||
}
|
||||
|
||||
// Determine how identifiers are escaped
|
||||
$query = $this->query('SELECT CASE WHEN (@@OPTIONS | 256) = @@OPTIONS THEN 1 ELSE 0 END AS qi');
|
||||
$query = $query->row_array();
|
||||
$this->_quoted_identifier = empty($query) ? FALSE : (bool) $query['qi'];
|
||||
$this->_escape_char = ($this->_quoted_identifier) ? '"' : array('[', ']');
|
||||
|
||||
return $this->conn_id;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Show table query
|
||||
*
|
||||
* Generates a platform-specific query string so that the table names can be fetched
|
||||
*
|
||||
* @param bool $prefix_limit
|
||||
* @return string
|
||||
*/
|
||||
protected function _list_tables($prefix_limit = FALSE)
|
||||
{
|
||||
$sql = 'SELECT '.$this->escape_identifiers('name')
|
||||
.' FROM '.$this->escape_identifiers('sysobjects')
|
||||
.' WHERE '.$this->escape_identifiers('type')." = 'U'";
|
||||
|
||||
if ($prefix_limit === TRUE && $this->dbprefix !== '')
|
||||
{
|
||||
$sql .= ' AND '.$this->escape_identifiers('name')." LIKE '".$this->escape_like_str($this->dbprefix)."%' "
|
||||
.sprintf($this->_like_escape_str, $this->_like_escape_chr);
|
||||
}
|
||||
|
||||
return $sql.' ORDER BY '.$this->escape_identifiers('name');
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Show column query
|
||||
*
|
||||
* Generates a platform-specific query string so that the column names can be fetched
|
||||
*
|
||||
* @param string $table
|
||||
* @return string
|
||||
*/
|
||||
protected function _list_columns($table = '')
|
||||
{
|
||||
return 'SELECT COLUMN_NAME
|
||||
FROM INFORMATION_SCHEMA.Columns
|
||||
WHERE UPPER(TABLE_NAME) = '.$this->escape(strtoupper($table));
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Returns an object with field data
|
||||
*
|
||||
* @param string $table
|
||||
* @return array
|
||||
*/
|
||||
public function field_data($table)
|
||||
{
|
||||
$sql = 'SELECT COLUMN_NAME, DATA_TYPE, CHARACTER_MAXIMUM_LENGTH, NUMERIC_PRECISION, COLUMN_DEFAULT
|
||||
FROM INFORMATION_SCHEMA.Columns
|
||||
WHERE UPPER(TABLE_NAME) = '.$this->escape(strtoupper($table));
|
||||
|
||||
if (($query = $this->query($sql)) === FALSE)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
$query = $query->result_object();
|
||||
|
||||
$retval = array();
|
||||
for ($i = 0, $c = count($query); $i < $c; $i++)
|
||||
{
|
||||
$retval[$i] = new stdClass();
|
||||
$retval[$i]->name = $query[$i]->COLUMN_NAME;
|
||||
$retval[$i]->type = $query[$i]->DATA_TYPE;
|
||||
$retval[$i]->max_length = ($query[$i]->CHARACTER_MAXIMUM_LENGTH > 0) ? $query[$i]->CHARACTER_MAXIMUM_LENGTH : $query[$i]->NUMERIC_PRECISION;
|
||||
$retval[$i]->default = $query[$i]->COLUMN_DEFAULT;
|
||||
}
|
||||
|
||||
return $retval;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Update statement
|
||||
*
|
||||
* Generates a platform-specific update string from the supplied data
|
||||
*
|
||||
* @param string $table
|
||||
* @param array $values
|
||||
* @return string
|
||||
*/
|
||||
protected function _update($table, $values)
|
||||
{
|
||||
$this->qb_limit = FALSE;
|
||||
$this->qb_orderby = array();
|
||||
return parent::_update($table, $values);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Delete statement
|
||||
*
|
||||
* Generates a platform-specific delete string from the supplied data
|
||||
*
|
||||
* @param string $table
|
||||
* @return string
|
||||
*/
|
||||
protected function _delete($table)
|
||||
{
|
||||
if ($this->qb_limit)
|
||||
{
|
||||
return 'WITH fw_delete AS (SELECT TOP '.$this->qb_limit.' * FROM '.$table.$this->_compile_wh('qb_where').') DELETE FROM fw_delete';
|
||||
}
|
||||
|
||||
return parent::_delete($table);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* LIMIT
|
||||
*
|
||||
* Generates a platform-specific LIMIT clause
|
||||
*
|
||||
* @param string $sql SQL Query
|
||||
* @return string
|
||||
*/
|
||||
protected function _limit($sql)
|
||||
{
|
||||
$limit = $this->qb_offset + $this->qb_limit;
|
||||
|
||||
// As of SQL Server 2005 (9.0.*) ROW_NUMBER() is supported,
|
||||
// however an ORDER BY clause is required for it to work
|
||||
if (version_compare($this->version(), '9', '>=') && $this->qb_offset && ! empty($this->qb_orderby))
|
||||
{
|
||||
$orderby = $this->_compile_order_by();
|
||||
|
||||
// We have to strip the ORDER BY clause
|
||||
$sql = trim(substr($sql, 0, strrpos($sql, $orderby)));
|
||||
|
||||
// Get the fields to select from our subquery, so that we can avoid FW_rownum appearing in the actual results
|
||||
if (count($this->qb_select) === 0)
|
||||
{
|
||||
$select = '*'; // Inevitable
|
||||
}
|
||||
else
|
||||
{
|
||||
// Use only field names and their aliases, everything else is out of our scope.
|
||||
$select = array();
|
||||
$field_regexp = ($this->_quoted_identifier)
|
||||
? '("[^\"]+")' : '(\[[^\]]+\])';
|
||||
for ($i = 0, $c = count($this->qb_select); $i < $c; $i++)
|
||||
{
|
||||
$select[] = preg_match('/(?:\s|\.)'.$field_regexp.'$/i', $this->qb_select[$i], $m)
|
||||
? $m[1] : $this->qb_select[$i];
|
||||
}
|
||||
$select = implode(', ', $select);
|
||||
}
|
||||
|
||||
return 'SELECT '.$select." FROM (\n\n"
|
||||
.preg_replace('/^(SELECT( DISTINCT)?)/i', '\\1 ROW_NUMBER() OVER('.trim($orderby).') AS '.$this->escape_identifiers('FW_rownum').', ', $sql)
|
||||
."\n\n) ".$this->escape_identifiers('FW_subquery')
|
||||
."\nWHERE ".$this->escape_identifiers('FW_rownum').' BETWEEN '.($this->qb_offset + 1).' AND '.$limit;
|
||||
}
|
||||
|
||||
return preg_replace('/(^\SELECT (DISTINCT)?)/i','\\1 TOP '.$limit.' ', $sql);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Insert batch statement
|
||||
*
|
||||
* Generates a platform-specific insert string from the supplied data.
|
||||
*
|
||||
* @param string $table Table name
|
||||
* @param array $keys INSERT keys
|
||||
* @param array $values INSERT values
|
||||
* @return string|bool
|
||||
*/
|
||||
protected function _insert_batch($table, $keys, $values)
|
||||
{
|
||||
// Multiple-value inserts are only supported as of SQL Server 2008
|
||||
if (version_compare($this->version(), '10', '>='))
|
||||
{
|
||||
return parent::_insert_batch($table, $keys, $values);
|
||||
}
|
||||
|
||||
return ($this->db->db_debug) ? $this->db->display_error('db_unsupported_feature') : FALSE;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,141 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2015 TechFuze
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 1.0.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* PDO DBLIB Forge Class
|
||||
*
|
||||
* Converted from CodeIgniter.
|
||||
*
|
||||
* @package FuzeWorks
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
*/
|
||||
class FW_DB_pdo_dblib_forge extends FW_DB_pdo_forge {
|
||||
|
||||
/**
|
||||
* CREATE TABLE IF statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_create_table_if = "IF NOT EXISTS (SELECT * FROM sysobjects WHERE ID = object_id(N'%s') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)\nCREATE TABLE";
|
||||
|
||||
/**
|
||||
* DROP TABLE IF statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_drop_table_if = "IF EXISTS (SELECT * FROM sysobjects WHERE ID = object_id(N'%s') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)\nDROP TABLE";
|
||||
|
||||
/**
|
||||
* UNSIGNED support
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_unsigned = array(
|
||||
'TINYINT' => 'SMALLINT',
|
||||
'SMALLINT' => 'INT',
|
||||
'INT' => 'BIGINT',
|
||||
'REAL' => 'FLOAT'
|
||||
);
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* ALTER TABLE
|
||||
*
|
||||
* @param string $alter_type ALTER type
|
||||
* @param string $table Table name
|
||||
* @param mixed $field Column definition
|
||||
* @return string|string[]
|
||||
*/
|
||||
protected function _alter_table($alter_type, $table, $field)
|
||||
{
|
||||
if (in_array($alter_type, array('ADD', 'DROP'), TRUE))
|
||||
{
|
||||
return parent::_alter_table($alter_type, $table, $field);
|
||||
}
|
||||
|
||||
$sql = 'ALTER TABLE '.$this->db->escape_identifiers($table).' ALTER COLUMN ';
|
||||
$sqls = array();
|
||||
for ($i = 0, $c = count($field); $i < $c; $i++)
|
||||
{
|
||||
$sqls[] = $sql.$this->_process_column($field[$i]);
|
||||
}
|
||||
|
||||
return $sqls;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Field attribute TYPE
|
||||
*
|
||||
* Performs a data type mapping between different databases.
|
||||
*
|
||||
* @param array &$attributes
|
||||
* @return void
|
||||
*/
|
||||
protected function _attr_type(&$attributes)
|
||||
{
|
||||
switch (strtoupper($attributes['TYPE']))
|
||||
{
|
||||
case 'MEDIUMINT':
|
||||
$attributes['TYPE'] = 'INTEGER';
|
||||
$attributes['UNSIGNED'] = FALSE;
|
||||
return;
|
||||
case 'INTEGER':
|
||||
$attributes['TYPE'] = 'INT';
|
||||
return;
|
||||
default: return;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Field attribute AUTO_INCREMENT
|
||||
*
|
||||
* @param array &$attributes
|
||||
* @param array &$field
|
||||
* @return void
|
||||
*/
|
||||
protected function _attr_auto_increment(&$attributes, &$field)
|
||||
{
|
||||
if ( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE && stripos($field['type'], 'int') !== FALSE)
|
||||
{
|
||||
$field['auto_increment'] = ' IDENTITY(1,1)';
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,259 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2015 TechFuze
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 1.0.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* PDO Firebird Database Adapter Class
|
||||
*
|
||||
* Note: _DB is an extender class that the app controller
|
||||
* creates dynamically based on whether the query builder
|
||||
* class is being used or not.
|
||||
*
|
||||
* Converted from CodeIgniter.
|
||||
*
|
||||
* @package FuzeWorks
|
||||
* @subpackage Drivers
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
*/
|
||||
class FW_DB_pdo_firebird_driver extends FW_DB_pdo_driver {
|
||||
|
||||
/**
|
||||
* Sub-driver
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $subdriver = 'firebird';
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* ORDER BY random keyword
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_random_keyword = array('RAND()', 'RAND()');
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* Builds the DSN if not already set.
|
||||
*
|
||||
* @param array $params
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($params)
|
||||
{
|
||||
parent::__construct($params);
|
||||
|
||||
if (empty($this->dsn))
|
||||
{
|
||||
$this->dsn = 'firebird:';
|
||||
|
||||
if ( ! empty($this->database))
|
||||
{
|
||||
$this->dsn .= 'dbname='.$this->database;
|
||||
}
|
||||
elseif ( ! empty($this->hostname))
|
||||
{
|
||||
$this->dsn .= 'dbname='.$this->hostname;
|
||||
}
|
||||
|
||||
empty($this->char_set) OR $this->dsn .= ';charset='.$this->char_set;
|
||||
empty($this->role) OR $this->dsn .= ';role='.$this->role;
|
||||
}
|
||||
elseif ( ! empty($this->char_set) && strpos($this->dsn, 'charset=', 9) === FALSE)
|
||||
{
|
||||
$this->dsn .= ';charset='.$this->char_set;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Show table query
|
||||
*
|
||||
* Generates a platform-specific query string so that the table names can be fetched
|
||||
*
|
||||
* @param bool $prefix_limit
|
||||
* @return string
|
||||
*/
|
||||
protected function _list_tables($prefix_limit = FALSE)
|
||||
{
|
||||
$sql = 'SELECT "RDB$RELATION_NAME" FROM "RDB$RELATIONS" WHERE "RDB$RELATION_NAME" NOT LIKE \'RDB$%\' AND "RDB$RELATION_NAME" NOT LIKE \'MON$%\'';
|
||||
|
||||
if ($prefix_limit === TRUE && $this->dbprefix !== '')
|
||||
{
|
||||
return $sql.' AND "RDB$RELATION_NAME" LIKE \''.$this->escape_like_str($this->dbprefix)."%' "
|
||||
.sprintf($this->_like_escape_str, $this->_like_escape_chr);
|
||||
}
|
||||
|
||||
return $sql;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Show column query
|
||||
*
|
||||
* Generates a platform-specific query string so that the column names can be fetched
|
||||
*
|
||||
* @param string $table
|
||||
* @return string
|
||||
*/
|
||||
protected function _list_columns($table = '')
|
||||
{
|
||||
return 'SELECT "RDB$FIELD_NAME" FROM "RDB$RELATION_FIELDS" WHERE "RDB$RELATION_NAME" = '.$this->escape($table);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Returns an object with field data
|
||||
*
|
||||
* @param string $table
|
||||
* @return array
|
||||
*/
|
||||
public function field_data($table)
|
||||
{
|
||||
$sql = 'SELECT "rfields"."RDB$FIELD_NAME" AS "name",
|
||||
CASE "fields"."RDB$FIELD_TYPE"
|
||||
WHEN 7 THEN \'SMALLINT\'
|
||||
WHEN 8 THEN \'INTEGER\'
|
||||
WHEN 9 THEN \'QUAD\'
|
||||
WHEN 10 THEN \'FLOAT\'
|
||||
WHEN 11 THEN \'DFLOAT\'
|
||||
WHEN 12 THEN \'DATE\'
|
||||
WHEN 13 THEN \'TIME\'
|
||||
WHEN 14 THEN \'CHAR\'
|
||||
WHEN 16 THEN \'INT64\'
|
||||
WHEN 27 THEN \'DOUBLE\'
|
||||
WHEN 35 THEN \'TIMESTAMP\'
|
||||
WHEN 37 THEN \'VARCHAR\'
|
||||
WHEN 40 THEN \'CSTRING\'
|
||||
WHEN 261 THEN \'BLOB\'
|
||||
ELSE NULL
|
||||
END AS "type",
|
||||
"fields"."RDB$FIELD_LENGTH" AS "max_length",
|
||||
"rfields"."RDB$DEFAULT_VALUE" AS "default"
|
||||
FROM "RDB$RELATION_FIELDS" "rfields"
|
||||
JOIN "RDB$FIELDS" "fields" ON "rfields"."RDB$FIELD_SOURCE" = "fields"."RDB$FIELD_NAME"
|
||||
WHERE "rfields"."RDB$RELATION_NAME" = '.$this->escape($table).'
|
||||
ORDER BY "rfields"."RDB$FIELD_POSITION"';
|
||||
|
||||
return (($query = $this->query($sql)) !== FALSE)
|
||||
? $query->result_object()
|
||||
: FALSE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Update statement
|
||||
*
|
||||
* Generates a platform-specific update string from the supplied data
|
||||
*
|
||||
* @param string $table
|
||||
* @param array $values
|
||||
* @return string
|
||||
*/
|
||||
protected function _update($table, $values)
|
||||
{
|
||||
$this->qb_limit = FALSE;
|
||||
return parent::_update($table, $values);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Truncate statement
|
||||
*
|
||||
* Generates a platform-specific truncate string from the supplied data
|
||||
*
|
||||
* If the database does not support the TRUNCATE statement,
|
||||
* then this method maps to 'DELETE FROM table'
|
||||
*
|
||||
* @param string $table
|
||||
* @return string
|
||||
*/
|
||||
protected function _truncate($table)
|
||||
{
|
||||
return 'DELETE FROM '.$table;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Delete statement
|
||||
*
|
||||
* Generates a platform-specific delete string from the supplied data
|
||||
*
|
||||
* @param string $table
|
||||
* @return string
|
||||
*/
|
||||
protected function _delete($table)
|
||||
{
|
||||
$this->qb_limit = FALSE;
|
||||
return parent::_delete($table);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* LIMIT
|
||||
*
|
||||
* Generates a platform-specific LIMIT clause
|
||||
*
|
||||
* @param string $sql SQL Query
|
||||
* @return string
|
||||
*/
|
||||
protected function _limit($sql)
|
||||
{
|
||||
// Limit clause depends on if Interbase or Firebird
|
||||
if (stripos($this->version(), 'firebird') !== FALSE)
|
||||
{
|
||||
$select = 'FIRST '.$this->qb_limit
|
||||
.($this->qb_offset > 0 ? ' SKIP '.$this->qb_offset : '');
|
||||
}
|
||||
else
|
||||
{
|
||||
$select = 'ROWS '
|
||||
.($this->qb_offset > 0 ? $this->qb_offset.' TO '.($this->qb_limit + $this->qb_offset) : $this->qb_limit);
|
||||
}
|
||||
|
||||
return preg_replace('`SELECT`i', 'SELECT '.$select, $sql);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,234 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2015 TechFuze
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 1.0.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* PDO Firebird Forge Class
|
||||
*
|
||||
* Converted from CodeIgniter.
|
||||
*
|
||||
* @package FuzeWorks
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
*/
|
||||
class FW_DB_pdo_firebird_forge extends FW_DB_pdo_forge {
|
||||
|
||||
/**
|
||||
* RENAME TABLE statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_rename_table = FALSE;
|
||||
|
||||
/**
|
||||
* UNSIGNED support
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_unsigned = array(
|
||||
'SMALLINT' => 'INTEGER',
|
||||
'INTEGER' => 'INT64',
|
||||
'FLOAT' => 'DOUBLE PRECISION'
|
||||
);
|
||||
|
||||
/**
|
||||
* NULL value representation in CREATE/ALTER TABLE statements
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_null = 'NULL';
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Create database
|
||||
*
|
||||
* @param string $db_name
|
||||
* @return string
|
||||
*/
|
||||
public function create_database($db_name)
|
||||
{
|
||||
// Firebird databases are flat files, so a path is required
|
||||
|
||||
// Hostname is needed for remote access
|
||||
empty($this->db->hostname) OR $db_name = $this->hostname.':'.$db_name;
|
||||
|
||||
return parent::create_database('"'.$db_name.'"');
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Drop database
|
||||
*
|
||||
* @param string $db_name (ignored)
|
||||
* @return bool
|
||||
*/
|
||||
public function drop_database($db_name = '')
|
||||
{
|
||||
if ( ! ibase_drop_db($this->conn_id))
|
||||
{
|
||||
return ($this->db->db_debug) ? $this->db->display_error('db_unable_to_drop') : FALSE;
|
||||
}
|
||||
elseif ( ! empty($this->db->data_cache['db_names']))
|
||||
{
|
||||
$key = array_search(strtolower($this->db->database), array_map('strtolower', $this->db->data_cache['db_names']), TRUE);
|
||||
if ($key !== FALSE)
|
||||
{
|
||||
unset($this->db->data_cache['db_names'][$key]);
|
||||
}
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* ALTER TABLE
|
||||
*
|
||||
* @param string $alter_type ALTER type
|
||||
* @param string $table Table name
|
||||
* @param mixed $field Column definition
|
||||
* @return string|string[]
|
||||
*/
|
||||
protected function _alter_table($alter_type, $table, $field)
|
||||
{
|
||||
if (in_array($alter_type, array('DROP', 'ADD'), TRUE))
|
||||
{
|
||||
return parent::_alter_table($alter_type, $table, $field);
|
||||
}
|
||||
|
||||
$sql = 'ALTER TABLE '.$this->db->escape_identifiers($table);
|
||||
$sqls = array();
|
||||
for ($i = 0, $c = count($field); $i < $c; $i++)
|
||||
{
|
||||
if ($field[$i]['_literal'] !== FALSE)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (isset($field[$i]['type']))
|
||||
{
|
||||
$sqls[] = $sql.' ALTER COLUMN '.$this->db->escape_identifiers($field[$i]['name'])
|
||||
.' TYPE '.$field[$i]['type'].$field[$i]['length'];
|
||||
}
|
||||
|
||||
if ( ! empty($field[$i]['default']))
|
||||
{
|
||||
$sqls[] = $sql.' ALTER COLUMN '.$this->db->escape_identifiers($field[$i]['name'])
|
||||
.' SET DEFAULT '.$field[$i]['default'];
|
||||
}
|
||||
|
||||
if (isset($field[$i]['null']))
|
||||
{
|
||||
$sqls[] = 'UPDATE "RDB$RELATION_FIELDS" SET "RDB$NULL_FLAG" = '
|
||||
.($field[$i]['null'] === TRUE ? 'NULL' : '1')
|
||||
.' WHERE "RDB$FIELD_NAME" = '.$this->db->escape($field[$i]['name'])
|
||||
.' AND "RDB$RELATION_NAME" = '.$this->db->escape($table);
|
||||
}
|
||||
|
||||
if ( ! empty($field[$i]['new_name']))
|
||||
{
|
||||
$sqls[] = $sql.' ALTER COLUMN '.$this->db->escape_identifiers($field[$i]['name'])
|
||||
.' TO '.$this->db->escape_identifiers($field[$i]['new_name']);
|
||||
}
|
||||
}
|
||||
|
||||
return $sqls;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Process column
|
||||
*
|
||||
* @param array $field
|
||||
* @return string
|
||||
*/
|
||||
protected function _process_column($field)
|
||||
{
|
||||
return $this->db->escape_identifiers($field['name'])
|
||||
.' '.$field['type'].$field['length']
|
||||
.$field['null']
|
||||
.$field['unique']
|
||||
.$field['default'];
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Field attribute TYPE
|
||||
*
|
||||
* Performs a data type mapping between different databases.
|
||||
*
|
||||
* @param array &$attributes
|
||||
* @return void
|
||||
*/
|
||||
protected function _attr_type(&$attributes)
|
||||
{
|
||||
switch (strtoupper($attributes['TYPE']))
|
||||
{
|
||||
case 'TINYINT':
|
||||
$attributes['TYPE'] = 'SMALLINT';
|
||||
$attributes['UNSIGNED'] = FALSE;
|
||||
return;
|
||||
case 'MEDIUMINT':
|
||||
$attributes['TYPE'] = 'INTEGER';
|
||||
$attributes['UNSIGNED'] = FALSE;
|
||||
return;
|
||||
case 'INT':
|
||||
$attributes['TYPE'] = 'INTEGER';
|
||||
return;
|
||||
case 'BIGINT':
|
||||
$attributes['TYPE'] = 'INT64';
|
||||
return;
|
||||
default: return;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Field attribute AUTO_INCREMENT
|
||||
*
|
||||
* @param array &$attributes
|
||||
* @param array &$field
|
||||
* @return void
|
||||
*/
|
||||
protected function _attr_auto_increment(&$attributes, &$field)
|
||||
{
|
||||
// Not supported
|
||||
}
|
||||
|
||||
}
|
|
@ -1,240 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2015 TechFuze
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 1.0.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* PDO IBM DB2 Database Adapter Class
|
||||
*
|
||||
* Note: _DB is an extender class that the app controller
|
||||
* creates dynamically based on whether the query builder
|
||||
* class is being used or not.
|
||||
*
|
||||
* Converted from CodeIgniter.
|
||||
*
|
||||
* @package FuzeWorks
|
||||
* @subpackage Drivers
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
*/
|
||||
class FW_DB_pdo_ibm_driver extends FW_DB_pdo_driver {
|
||||
|
||||
/**
|
||||
* Sub-driver
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $subdriver = 'ibm';
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* Builds the DSN if not already set.
|
||||
*
|
||||
* @param array $params
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($params)
|
||||
{
|
||||
parent::__construct($params);
|
||||
|
||||
if (empty($this->dsn))
|
||||
{
|
||||
$this->dsn = 'ibm:';
|
||||
|
||||
// Pre-defined DSN
|
||||
if (empty($this->hostname) && empty($this->HOSTNAME) && empty($this->port) && empty($this->PORT))
|
||||
{
|
||||
if (isset($this->DSN))
|
||||
{
|
||||
$this->dsn .= 'DSN='.$this->DSN;
|
||||
}
|
||||
elseif ( ! empty($this->database))
|
||||
{
|
||||
$this->dsn .= 'DSN='.$this->database;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->dsn .= 'DRIVER='.(isset($this->DRIVER) ? '{'.$this->DRIVER.'}' : '{IBM DB2 ODBC DRIVER}').';';
|
||||
|
||||
if (isset($this->DATABASE))
|
||||
{
|
||||
$this->dsn .= 'DATABASE='.$this->DATABASE.';';
|
||||
}
|
||||
elseif ( ! empty($this->database))
|
||||
{
|
||||
$this->dsn .= 'DATABASE='.$this->database.';';
|
||||
}
|
||||
|
||||
if (isset($this->HOSTNAME))
|
||||
{
|
||||
$this->dsn .= 'HOSTNAME='.$this->HOSTNAME.';';
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->dsn .= 'HOSTNAME='.(empty($this->hostname) ? '127.0.0.1;' : $this->hostname.';');
|
||||
}
|
||||
|
||||
if (isset($this->PORT))
|
||||
{
|
||||
$this->dsn .= 'PORT='.$this->port.';';
|
||||
}
|
||||
elseif ( ! empty($this->port))
|
||||
{
|
||||
$this->dsn .= ';PORT='.$this->port.';';
|
||||
}
|
||||
|
||||
$this->dsn .= 'PROTOCOL='.(isset($this->PROTOCOL) ? $this->PROTOCOL.';' : 'TCPIP;');
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Show table query
|
||||
*
|
||||
* Generates a platform-specific query string so that the table names can be fetched
|
||||
*
|
||||
* @param bool $prefix_limit
|
||||
* @return string
|
||||
*/
|
||||
protected function _list_tables($prefix_limit = FALSE)
|
||||
{
|
||||
$sql = 'SELECT "tabname" FROM "syscat"."tables"
|
||||
WHERE "type" = \'T\' AND LOWER("tabschema") = '.$this->escape(strtolower($this->database));
|
||||
|
||||
if ($prefix_limit === TRUE && $this->dbprefix !== '')
|
||||
{
|
||||
$sql .= ' AND "tabname" LIKE \''.$this->escape_like_str($this->dbprefix)."%' "
|
||||
.sprintf($this->_like_escape_str, $this->_like_escape_chr);
|
||||
}
|
||||
|
||||
return $sql;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Show column query
|
||||
*
|
||||
* Generates a platform-specific query string so that the column names can be fetched
|
||||
*
|
||||
* @param string $table
|
||||
* @return array
|
||||
*/
|
||||
protected function _list_columns($table = '')
|
||||
{
|
||||
return 'SELECT "colname" FROM "syscat"."columns"
|
||||
WHERE LOWER("tabschema") = '.$this->escape(strtolower($this->database)).'
|
||||
AND LOWER("tabname") = '.$this->escape(strtolower($table));
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Returns an object with field data
|
||||
*
|
||||
* @param string $table
|
||||
* @return array
|
||||
*/
|
||||
public function field_data($table)
|
||||
{
|
||||
$sql = 'SELECT "colname" AS "name", "typename" AS "type", "default" AS "default", "length" AS "max_length",
|
||||
CASE "keyseq" WHEN NULL THEN 0 ELSE 1 END AS "primary_key"
|
||||
FROM "syscat"."columns"
|
||||
WHERE LOWER("tabschema") = '.$this->escape(strtolower($this->database)).'
|
||||
AND LOWER("tabname") = '.$this->escape(strtolower($table)).'
|
||||
ORDER BY "colno"';
|
||||
|
||||
return (($query = $this->query($sql)) !== FALSE)
|
||||
? $query->result_object()
|
||||
: FALSE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Update statement
|
||||
*
|
||||
* Generates a platform-specific update string from the supplied data
|
||||
*
|
||||
* @param string $table
|
||||
* @param array $values
|
||||
* @return string
|
||||
*/
|
||||
protected function _update($table, $values)
|
||||
{
|
||||
$this->qb_limit = FALSE;
|
||||
$this->qb_orderby = array();
|
||||
return parent::_update($table, $values);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Delete statement
|
||||
*
|
||||
* Generates a platform-specific delete string from the supplied data
|
||||
*
|
||||
* @param string $table
|
||||
* @return string
|
||||
*/
|
||||
protected function _delete($table)
|
||||
{
|
||||
$this->qb_limit = FALSE;
|
||||
return parent::_delete($table);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* LIMIT
|
||||
*
|
||||
* Generates a platform-specific LIMIT clause
|
||||
*
|
||||
* @param string $sql SQL Query
|
||||
* @return string
|
||||
*/
|
||||
protected function _limit($sql)
|
||||
{
|
||||
$sql .= ' FETCH FIRST '.($this->qb_limit + $this->qb_offset).' ROWS ONLY';
|
||||
|
||||
return ($this->qb_offset)
|
||||
? 'SELECT * FROM ('.$sql.') WHERE rownum > '.$this->qb_offset
|
||||
: $sql;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,151 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2015 TechFuze
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 1.0.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* PDO IBM DB2 Forge Class
|
||||
*
|
||||
* Converted from CodeIgniter.
|
||||
*
|
||||
* @package FuzeWorks
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
*/
|
||||
class FW_DB_pdo_ibm_forge extends FW_DB_pdo_forge {
|
||||
|
||||
/**
|
||||
* RENAME TABLE IF statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_rename_table = 'RENAME TABLE %s TO %s';
|
||||
|
||||
/**
|
||||
* UNSIGNED support
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_unsigned = array(
|
||||
'SMALLINT' => 'INTEGER',
|
||||
'INT' => 'BIGINT',
|
||||
'INTEGER' => 'BIGINT'
|
||||
);
|
||||
|
||||
/**
|
||||
* DEFAULT value representation in CREATE/ALTER TABLE statements
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_default = FALSE;
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* ALTER TABLE
|
||||
*
|
||||
* @param string $alter_type ALTER type
|
||||
* @param string $table Table name
|
||||
* @param mixed $field Column definition
|
||||
* @return string|string[]
|
||||
*/
|
||||
protected function _alter_table($alter_type, $table, $field)
|
||||
{
|
||||
if ($alter_type === 'CHANGE')
|
||||
{
|
||||
$alter_type = 'MODIFY';
|
||||
}
|
||||
|
||||
return parent::_alter_table($alter_type, $table, $field);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Field attribute TYPE
|
||||
*
|
||||
* Performs a data type mapping between different databases.
|
||||
*
|
||||
* @param array &$attributes
|
||||
* @return void
|
||||
*/
|
||||
protected function _attr_type(&$attributes)
|
||||
{
|
||||
switch (strtoupper($attributes['TYPE']))
|
||||
{
|
||||
case 'TINYINT':
|
||||
$attributes['TYPE'] = 'SMALLINT';
|
||||
$attributes['UNSIGNED'] = FALSE;
|
||||
return;
|
||||
case 'MEDIUMINT':
|
||||
$attributes['TYPE'] = 'INTEGER';
|
||||
$attributes['UNSIGNED'] = FALSE;
|
||||
return;
|
||||
default: return;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Field attribute UNIQUE
|
||||
*
|
||||
* @param array &$attributes
|
||||
* @param array &$field
|
||||
* @return void
|
||||
*/
|
||||
protected function _attr_unique(&$attributes, &$field)
|
||||
{
|
||||
if ( ! empty($attributes['UNIQUE']) && $attributes['UNIQUE'] === TRUE)
|
||||
{
|
||||
$field['unique'] = ' UNIQUE';
|
||||
|
||||
// UNIQUE must be used with NOT NULL
|
||||
$field['null'] = ' NOT NULL';
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Field attribute AUTO_INCREMENT
|
||||
*
|
||||
* @param array &$attributes
|
||||
* @param array &$field
|
||||
* @return void
|
||||
*/
|
||||
protected function _attr_auto_increment(&$attributes, &$field)
|
||||
{
|
||||
// Not supported
|
||||
}
|
||||
|
||||
}
|
|
@ -1,305 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2015 TechFuze
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 1.0.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* PDO Informix Database Adapter Class
|
||||
*
|
||||
* Note: _DB is an extender class that the app controller
|
||||
* creates dynamically based on whether the query builder
|
||||
* class is being used or not.
|
||||
*
|
||||
* Converted from CodeIgniter.
|
||||
*
|
||||
* @package FuzeWorks
|
||||
* @subpackage Drivers
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
*/
|
||||
class FW_DB_pdo_informix_driver extends FW_DB_pdo_driver {
|
||||
|
||||
/**
|
||||
* Sub-driver
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $subdriver = 'informix';
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* ORDER BY random keyword
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_random_keyword = array('ASC', 'ASC'); // Currently not supported
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* Builds the DSN if not already set.
|
||||
*
|
||||
* @param array $params
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($params)
|
||||
{
|
||||
parent::__construct($params);
|
||||
|
||||
if (empty($this->dsn))
|
||||
{
|
||||
$this->dsn = 'informix:';
|
||||
|
||||
// Pre-defined DSN
|
||||
if (empty($this->hostname) && empty($this->host) && empty($this->port) && empty($this->service))
|
||||
{
|
||||
if (isset($this->DSN))
|
||||
{
|
||||
$this->dsn .= 'DSN='.$this->DSN;
|
||||
}
|
||||
elseif ( ! empty($this->database))
|
||||
{
|
||||
$this->dsn .= 'DSN='.$this->database;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (isset($this->host))
|
||||
{
|
||||
$this->dsn .= 'host='.$this->host;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->dsn .= 'host='.(empty($this->hostname) ? '127.0.0.1' : $this->hostname);
|
||||
}
|
||||
|
||||
if (isset($this->service))
|
||||
{
|
||||
$this->dsn .= '; service='.$this->service;
|
||||
}
|
||||
elseif ( ! empty($this->port))
|
||||
{
|
||||
$this->dsn .= '; service='.$this->port;
|
||||
}
|
||||
|
||||
empty($this->database) OR $this->dsn .= '; database='.$this->database;
|
||||
empty($this->server) OR $this->dsn .= '; server='.$this->server;
|
||||
|
||||
$this->dsn .= '; protocol='.(isset($this->protocol) ? $this->protocol : 'onsoctcp')
|
||||
.'; EnableScrollableCursors=1';
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Show table query
|
||||
*
|
||||
* Generates a platform-specific query string so that the table names can be fetched
|
||||
*
|
||||
* @param bool $prefix_limit
|
||||
* @return string
|
||||
*/
|
||||
protected function _list_tables($prefix_limit = FALSE)
|
||||
{
|
||||
$sql = 'SELECT "tabname" FROM "systables"
|
||||
WHERE "tabid" > 99 AND "tabtype" = \'T\' AND LOWER("owner") = '.$this->escape(strtolower($this->username));
|
||||
|
||||
if ($prefix_limit === TRUE && $this->dbprefix !== '')
|
||||
{
|
||||
$sql .= ' AND "tabname" LIKE \''.$this->escape_like_str($this->dbprefix)."%' "
|
||||
.sprintf($this->_like_escape_str, $this->_like_escape_chr);
|
||||
}
|
||||
|
||||
return $sql;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Show column query
|
||||
*
|
||||
* Generates a platform-specific query string so that the column names can be fetched
|
||||
*
|
||||
* @param string $table
|
||||
* @return string
|
||||
*/
|
||||
protected function _list_columns($table = '')
|
||||
{
|
||||
if (strpos($table, '.') !== FALSE)
|
||||
{
|
||||
sscanf($table, '%[^.].%s', $owner, $table);
|
||||
}
|
||||
else
|
||||
{
|
||||
$owner = $this->username;
|
||||
}
|
||||
|
||||
return 'SELECT "colname" FROM "systables", "syscolumns"
|
||||
WHERE "systables"."tabid" = "syscolumns"."tabid"
|
||||
AND "systables"."tabtype" = \'T\'
|
||||
AND LOWER("systables"."owner") = '.$this->escape(strtolower($owner)).'
|
||||
AND LOWER("systables"."tabname") = '.$this->escape(strtolower($table));
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Returns an object with field data
|
||||
*
|
||||
* @param string $table
|
||||
* @return array
|
||||
*/
|
||||
public function field_data($table)
|
||||
{
|
||||
$sql = 'SELECT "syscolumns"."colname" AS "name",
|
||||
CASE "syscolumns"."coltype"
|
||||
WHEN 0 THEN \'CHAR\'
|
||||
WHEN 1 THEN \'SMALLINT\'
|
||||
WHEN 2 THEN \'INTEGER\'
|
||||
WHEN 3 THEN \'FLOAT\'
|
||||
WHEN 4 THEN \'SMALLFLOAT\'
|
||||
WHEN 5 THEN \'DECIMAL\'
|
||||
WHEN 6 THEN \'SERIAL\'
|
||||
WHEN 7 THEN \'DATE\'
|
||||
WHEN 8 THEN \'MONEY\'
|
||||
WHEN 9 THEN \'NULL\'
|
||||
WHEN 10 THEN \'DATETIME\'
|
||||
WHEN 11 THEN \'BYTE\'
|
||||
WHEN 12 THEN \'TEXT\'
|
||||
WHEN 13 THEN \'VARCHAR\'
|
||||
WHEN 14 THEN \'INTERVAL\'
|
||||
WHEN 15 THEN \'NCHAR\'
|
||||
WHEN 16 THEN \'NVARCHAR\'
|
||||
WHEN 17 THEN \'INT8\'
|
||||
WHEN 18 THEN \'SERIAL8\'
|
||||
WHEN 19 THEN \'SET\'
|
||||
WHEN 20 THEN \'MULTISET\'
|
||||
WHEN 21 THEN \'LIST\'
|
||||
WHEN 22 THEN \'Unnamed ROW\'
|
||||
WHEN 40 THEN \'LVARCHAR\'
|
||||
WHEN 41 THEN \'BLOB/CLOB/BOOLEAN\'
|
||||
WHEN 4118 THEN \'Named ROW\'
|
||||
ELSE "syscolumns"."coltype"
|
||||
END AS "type",
|
||||
"syscolumns"."collength" as "max_length",
|
||||
CASE "sysdefaults"."type"
|
||||
WHEN \'L\' THEN "sysdefaults"."default"
|
||||
ELSE NULL
|
||||
END AS "default"
|
||||
FROM "syscolumns", "systables", "sysdefaults"
|
||||
WHERE "syscolumns"."tabid" = "systables"."tabid"
|
||||
AND "systables"."tabid" = "sysdefaults"."tabid"
|
||||
AND "syscolumns"."colno" = "sysdefaults"."colno"
|
||||
AND "systables"."tabtype" = \'T\'
|
||||
AND LOWER("systables"."owner") = '.$this->escape(strtolower($this->username)).'
|
||||
AND LOWER("systables"."tabname") = '.$this->escape(strtolower($table)).'
|
||||
ORDER BY "syscolumns"."colno"';
|
||||
|
||||
return (($query = $this->query($sql)) !== FALSE)
|
||||
? $query->result_object()
|
||||
: FALSE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Update statement
|
||||
*
|
||||
* Generates a platform-specific update string from the supplied data
|
||||
*
|
||||
* @param string $table
|
||||
* @param array $values
|
||||
* @return string
|
||||
*/
|
||||
protected function _update($table, $values)
|
||||
{
|
||||
$this->qb_limit = FALSE;
|
||||
$this->qb_orderby = array();
|
||||
return parent::_update($table, $values);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Truncate statement
|
||||
*
|
||||
* Generates a platform-specific truncate string from the supplied data
|
||||
*
|
||||
* If the database does not support the TRUNCATE statement,
|
||||
* then this method maps to 'DELETE FROM table'
|
||||
*
|
||||
* @param string $table
|
||||
* @return string
|
||||
*/
|
||||
protected function _truncate($table)
|
||||
{
|
||||
return 'TRUNCATE TABLE ONLY '.$table;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Delete statement
|
||||
*
|
||||
* Generates a platform-specific delete string from the supplied data
|
||||
*
|
||||
* @param string $table
|
||||
* @return string
|
||||
*/
|
||||
protected function _delete($table)
|
||||
{
|
||||
$this->qb_limit = FALSE;
|
||||
return parent::_delete($table);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* LIMIT
|
||||
*
|
||||
* Generates a platform-specific LIMIT clause
|
||||
*
|
||||
* @param string $sql $SQL Query
|
||||
* @return string
|
||||
*/
|
||||
protected function _limit($sql)
|
||||
{
|
||||
$select = 'SELECT '.($this->qb_offset ? 'SKIP '.$this->qb_offset : '').'FIRST '.$this->qb_limit.' ';
|
||||
return preg_replace('/^(SELECT\s)/i', $select, $sql, 1);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,160 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2015 TechFuze
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 1.0.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* PDO Informix Forge Class
|
||||
*
|
||||
* Converted from CodeIgniter.
|
||||
*
|
||||
* @package FuzeWorks
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
*/
|
||||
class FW_DB_pdo_informix_forge extends FW_DB_pdo_forge {
|
||||
|
||||
/**
|
||||
* RENAME TABLE statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_rename_table = 'RENAME TABLE %s TO %s';
|
||||
|
||||
/**
|
||||
* UNSIGNED support
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_unsigned = array(
|
||||
'SMALLINT' => 'INTEGER',
|
||||
'INT' => 'BIGINT',
|
||||
'INTEGER' => 'BIGINT',
|
||||
'REAL' => 'DOUBLE PRECISION',
|
||||
'SMALLFLOAT' => 'DOUBLE PRECISION'
|
||||
);
|
||||
|
||||
/**
|
||||
* DEFAULT value representation in CREATE/ALTER TABLE statements
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_default = ', ';
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* ALTER TABLE
|
||||
*
|
||||
* @param string $alter_type ALTER type
|
||||
* @param string $table Table name
|
||||
* @param mixed $field Column definition
|
||||
* @return string|string[]
|
||||
*/
|
||||
protected function _alter_table($alter_type, $table, $field)
|
||||
{
|
||||
if ($alter_type === 'CHANGE')
|
||||
{
|
||||
$alter_type = 'MODIFY';
|
||||
}
|
||||
|
||||
return parent::_alter_table($alter_type, $table, $field);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Field attribute TYPE
|
||||
*
|
||||
* Performs a data type mapping between different databases.
|
||||
*
|
||||
* @param array &$attributes
|
||||
* @return void
|
||||
*/
|
||||
protected function _attr_type(&$attributes)
|
||||
{
|
||||
switch (strtoupper($attributes['TYPE']))
|
||||
{
|
||||
case 'TINYINT':
|
||||
$attributes['TYPE'] = 'SMALLINT';
|
||||
$attributes['UNSIGNED'] = FALSE;
|
||||
return;
|
||||
case 'MEDIUMINT':
|
||||
$attributes['TYPE'] = 'INTEGER';
|
||||
$attributes['UNSIGNED'] = FALSE;
|
||||
return;
|
||||
case 'BYTE':
|
||||
case 'TEXT':
|
||||
case 'BLOB':
|
||||
case 'CLOB':
|
||||
$attributes['UNIQUE'] = FALSE;
|
||||
if (isset($attributes['DEFAULT']))
|
||||
{
|
||||
unset($attributes['DEFAULT']);
|
||||
}
|
||||
return;
|
||||
default: return;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Field attribute UNIQUE
|
||||
*
|
||||
* @param array &$attributes
|
||||
* @param array &$field
|
||||
* @return void
|
||||
*/
|
||||
protected function _attr_unique(&$attributes, &$field)
|
||||
{
|
||||
if ( ! empty($attributes['UNIQUE']) && $attributes['UNIQUE'] === TRUE)
|
||||
{
|
||||
$field['unique'] = ' UNIQUE CONSTRAINT '.$this->db->escape_identifiers($field['name']);
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Field attribute AUTO_INCREMENT
|
||||
*
|
||||
* @param array &$attributes
|
||||
* @param array &$field
|
||||
* @return void
|
||||
*/
|
||||
protected function _attr_auto_increment(&$attributes, &$field)
|
||||
{
|
||||
// Not supported
|
||||
}
|
||||
|
||||
}
|
|
@ -1,335 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2015 TechFuze
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 1.0.0
|
||||
*/
|
||||
|
||||
use FuzeWorks\Logger;
|
||||
use FuzeWorks\Core;
|
||||
|
||||
/**
|
||||
* PDO MySQL Database Adapter Class
|
||||
*
|
||||
* Note: _DB is an extender class that the app controller
|
||||
* creates dynamically based on whether the query builder
|
||||
* class is being used or not.
|
||||
*
|
||||
* Converted from CodeIgniter.
|
||||
*
|
||||
* @package FuzeWorks
|
||||
* @subpackage Drivers
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
*/
|
||||
class FW_DB_pdo_mysql_driver extends FW_DB_pdo_driver {
|
||||
|
||||
/**
|
||||
* Sub-driver
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $subdriver = 'mysql';
|
||||
|
||||
/**
|
||||
* Compression flag
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $compress = FALSE;
|
||||
|
||||
/**
|
||||
* Strict ON flag
|
||||
*
|
||||
* Whether we're running in strict SQL mode.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $stricton;
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Identifier escape character
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_escape_char = '`';
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* Builds the DSN if not already set.
|
||||
*
|
||||
* @param array $params
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($params)
|
||||
{
|
||||
parent::__construct($params);
|
||||
|
||||
if (empty($this->dsn))
|
||||
{
|
||||
$this->dsn = 'mysql:host='.(empty($this->hostname) ? '127.0.0.1' : $this->hostname);
|
||||
|
||||
empty($this->port) OR $this->dsn .= ';port='.$this->port;
|
||||
empty($this->database) OR $this->dsn .= ';dbname='.$this->database;
|
||||
empty($this->char_set) OR $this->dsn .= ';charset='.$this->char_set;
|
||||
}
|
||||
elseif ( ! empty($this->char_set) && strpos($this->dsn, 'charset=', 6) === FALSE && Core::isPHP('5.3.6'))
|
||||
{
|
||||
$this->dsn .= ';charset='.$this->char_set;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Database connection
|
||||
*
|
||||
* @param bool $persistent
|
||||
* @return object
|
||||
*/
|
||||
public function db_connect($persistent = FALSE)
|
||||
{
|
||||
/* Prior to PHP 5.3.6, even if the charset was supplied in the DSN
|
||||
* on connect - it was ignored. This is a work-around for the issue.
|
||||
*
|
||||
* Reference: http://www.php.net/manual/en/ref.pdo-mysql.connection.php
|
||||
*/
|
||||
if ( ! Core::isPHP('5.3.6') && ! empty($this->char_set))
|
||||
{
|
||||
$this->options[PDO::MYSQL_ATTR_INIT_COMMAND] = 'SET NAMES '.$this->char_set
|
||||
.(empty($this->dbcollat) ? '' : ' COLLATE '.$this->dbcollat);
|
||||
}
|
||||
|
||||
if (isset($this->stricton))
|
||||
{
|
||||
if ($this->stricton)
|
||||
{
|
||||
$sql = 'CONCAT(@@sql_mode, ",", "STRICT_ALL_TABLES")';
|
||||
}
|
||||
else
|
||||
{
|
||||
$sql = 'REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(
|
||||
@@sql_mode,
|
||||
"STRICT_ALL_TABLES,", ""),
|
||||
",STRICT_ALL_TABLES", ""),
|
||||
"STRICT_ALL_TABLES", ""),
|
||||
"STRICT_TRANS_TABLES,", ""),
|
||||
",STRICT_TRANS_TABLES", ""),
|
||||
"STRICT_TRANS_TABLES", "")';
|
||||
}
|
||||
|
||||
if ( ! empty($sql))
|
||||
{
|
||||
if (empty($this->options[PDO::MYSQL_ATTR_INIT_COMMAND]))
|
||||
{
|
||||
$this->options[PDO::MYSQL_ATTR_INIT_COMMAND] = 'SET SESSION sql_mode = '.$sql;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->options[PDO::MYSQL_ATTR_INIT_COMMAND] .= ', @@session.sql_mode = '.$sql;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->compress === TRUE)
|
||||
{
|
||||
$this->options[PDO::MYSQL_ATTR_COMPRESS] = TRUE;
|
||||
}
|
||||
|
||||
// SSL support was added to PDO_MYSQL in PHP 5.3.7
|
||||
if (is_array($this->encrypt) && Core::isPHP('5.3.7'))
|
||||
{
|
||||
$ssl = array();
|
||||
empty($this->encrypt['ssl_key']) OR $ssl[PDO::MYSQL_ATTR_SSL_KEY] = $this->encrypt['ssl_key'];
|
||||
empty($this->encrypt['ssl_cert']) OR $ssl[PDO::MYSQL_ATTR_SSL_CERT] = $this->encrypt['ssl_cert'];
|
||||
empty($this->encrypt['ssl_ca']) OR $ssl[PDO::MYSQL_ATTR_SSL_CA] = $this->encrypt['ssl_ca'];
|
||||
empty($this->encrypt['ssl_capath']) OR $ssl[PDO::MYSQL_ATTR_SSL_CAPATH] = $this->encrypt['ssl_capath'];
|
||||
empty($this->encrypt['ssl_cipher']) OR $ssl[PDO::MYSQL_ATTR_SSL_CIPHER] = $this->encrypt['ssl_cipher'];
|
||||
|
||||
// DO NOT use array_merge() here!
|
||||
// It re-indexes numeric keys and the PDO_MYSQL_ATTR_SSL_* constants are integers.
|
||||
empty($ssl) OR $this->options += $ssl;
|
||||
}
|
||||
|
||||
// Prior to version 5.7.3, MySQL silently downgrades to an unencrypted connection if SSL setup fails
|
||||
if (
|
||||
($pdo = parent::db_connect($persistent)) !== FALSE
|
||||
&& ! empty($ssl)
|
||||
&& version_compare($pdo->getAttribute(PDO::ATTR_CLIENT_VERSION), '5.7.3', '<=')
|
||||
&& empty($pdo->query("SHOW STATUS LIKE 'ssl_cipher'")->fetchObject()->Value)
|
||||
)
|
||||
{
|
||||
$message = 'PDO_MYSQL was configured for an SSL connection, but got an unencrypted connection instead!';
|
||||
Logger::logError($message);
|
||||
return ($this->db->db_debug) ? $this->db->display_error($message, '', TRUE) : FALSE;
|
||||
}
|
||||
|
||||
return $pdo;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Select the database
|
||||
*
|
||||
* @param string $database
|
||||
* @return bool
|
||||
*/
|
||||
public function db_select($database = '')
|
||||
{
|
||||
if ($database === '')
|
||||
{
|
||||
$database = $this->database;
|
||||
}
|
||||
|
||||
if (FALSE !== $this->simple_query('USE '.$this->escape_identifiers($database)))
|
||||
{
|
||||
$this->database = $database;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Show table query
|
||||
*
|
||||
* Generates a platform-specific query string so that the table names can be fetched
|
||||
*
|
||||
* @param bool $prefix_limit
|
||||
* @return string
|
||||
*/
|
||||
protected function _list_tables($prefix_limit = FALSE)
|
||||
{
|
||||
$sql = 'SHOW TABLES';
|
||||
|
||||
if ($prefix_limit === TRUE && $this->dbprefix !== '')
|
||||
{
|
||||
return $sql." LIKE '".$this->escape_like_str($this->dbprefix)."%'";
|
||||
}
|
||||
|
||||
return $sql;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Show column query
|
||||
*
|
||||
* Generates a platform-specific query string so that the column names can be fetched
|
||||
*
|
||||
* @param string $table
|
||||
* @return string
|
||||
*/
|
||||
protected function _list_columns($table = '')
|
||||
{
|
||||
return 'SHOW COLUMNS FROM '.$this->protect_identifiers($table, TRUE, NULL, FALSE);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Returns an object with field data
|
||||
*
|
||||
* @param string $table
|
||||
* @return array
|
||||
*/
|
||||
public function field_data($table)
|
||||
{
|
||||
if (($query = $this->query('SHOW COLUMNS FROM '.$this->protect_identifiers($table, TRUE, NULL, FALSE))) === FALSE)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
$query = $query->result_object();
|
||||
|
||||
$retval = array();
|
||||
for ($i = 0, $c = count($query); $i < $c; $i++)
|
||||
{
|
||||
$retval[$i] = new stdClass();
|
||||
$retval[$i]->name = $query[$i]->Field;
|
||||
|
||||
sscanf($query[$i]->Type, '%[a-z](%d)',
|
||||
$retval[$i]->type,
|
||||
$retval[$i]->max_length
|
||||
);
|
||||
|
||||
$retval[$i]->default = $query[$i]->Default;
|
||||
$retval[$i]->primary_key = (int) ($query[$i]->Key === 'PRI');
|
||||
}
|
||||
|
||||
return $retval;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Truncate statement
|
||||
*
|
||||
* Generates a platform-specific truncate string from the supplied data
|
||||
*
|
||||
* If the database does not support the TRUNCATE statement,
|
||||
* then this method maps to 'DELETE FROM table'
|
||||
*
|
||||
* @param string $table
|
||||
* @return string
|
||||
*/
|
||||
protected function _truncate($table)
|
||||
{
|
||||
return 'TRUNCATE '.$table;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* FROM tables
|
||||
*
|
||||
* Groups tables in FROM clauses if needed, so there is no confusion
|
||||
* about operator precedence.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function _from_tables()
|
||||
{
|
||||
if ( ! empty($this->qb_join) && count($this->qb_from) > 1)
|
||||
{
|
||||
return '('.implode(', ', $this->qb_from).')';
|
||||
}
|
||||
|
||||
return implode(', ', $this->qb_from);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,253 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2015 TechFuze
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 1.0.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* PDO MySQL Forge Class
|
||||
*
|
||||
* Converted from CodeIgniter.
|
||||
*
|
||||
* @package FuzeWorks
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
*/
|
||||
class FW_DB_pdo_mysql_forge extends FW_DB_pdo_forge {
|
||||
|
||||
/**
|
||||
* CREATE DATABASE statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_create_database = 'CREATE DATABASE %s CHARACTER SET %s COLLATE %s';
|
||||
|
||||
/**
|
||||
* CREATE TABLE IF statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_create_table_if = 'CREATE TABLE IF NOT EXISTS';
|
||||
|
||||
/**
|
||||
* CREATE TABLE keys flag
|
||||
*
|
||||
* Whether table keys are created from within the
|
||||
* CREATE TABLE statement.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $_create_table_keys = TRUE;
|
||||
|
||||
/**
|
||||
* DROP TABLE IF statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_drop_table_if = 'DROP TABLE IF EXISTS';
|
||||
|
||||
/**
|
||||
* UNSIGNED support
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_unsigned = array(
|
||||
'TINYINT',
|
||||
'SMALLINT',
|
||||
'MEDIUMINT',
|
||||
'INT',
|
||||
'INTEGER',
|
||||
'BIGINT',
|
||||
'REAL',
|
||||
'DOUBLE',
|
||||
'DOUBLE PRECISION',
|
||||
'FLOAT',
|
||||
'DECIMAL',
|
||||
'NUMERIC'
|
||||
);
|
||||
|
||||
/**
|
||||
* NULL value representation in CREATE/ALTER TABLE statements
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_null = 'NULL';
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* CREATE TABLE attributes
|
||||
*
|
||||
* @param array $attributes Associative array of table attributes
|
||||
* @return string
|
||||
*/
|
||||
protected function _create_table_attr($attributes)
|
||||
{
|
||||
$sql = '';
|
||||
|
||||
foreach (array_keys($attributes) as $key)
|
||||
{
|
||||
if (is_string($key))
|
||||
{
|
||||
$sql .= ' '.strtoupper($key).' = '.$attributes[$key];
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! empty($this->db->char_set) && ! strpos($sql, 'CHARACTER SET') && ! strpos($sql, 'CHARSET'))
|
||||
{
|
||||
$sql .= ' DEFAULT CHARACTER SET = '.$this->db->char_set;
|
||||
}
|
||||
|
||||
if ( ! empty($this->db->dbcollat) && ! strpos($sql, 'COLLATE'))
|
||||
{
|
||||
$sql .= ' COLLATE = '.$this->db->dbcollat;
|
||||
}
|
||||
|
||||
return $sql;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* ALTER TABLE
|
||||
*
|
||||
* @param string $alter_type ALTER type
|
||||
* @param string $table Table name
|
||||
* @param mixed $field Column definition
|
||||
* @return string|string[]
|
||||
*/
|
||||
protected function _alter_table($alter_type, $table, $field)
|
||||
{
|
||||
if ($alter_type === 'DROP')
|
||||
{
|
||||
return parent::_alter_table($alter_type, $table, $field);
|
||||
}
|
||||
|
||||
$sql = 'ALTER TABLE '.$this->db->escape_identifiers($table);
|
||||
for ($i = 0, $c = count($field); $i < $c; $i++)
|
||||
{
|
||||
if ($field[$i]['_literal'] !== FALSE)
|
||||
{
|
||||
$field[$i] = ($alter_type === 'ADD')
|
||||
? "\n\tADD ".$field[$i]['_literal']
|
||||
: "\n\tMODIFY ".$field[$i]['_literal'];
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($alter_type === 'ADD')
|
||||
{
|
||||
$field[$i]['_literal'] = "\n\tADD ";
|
||||
}
|
||||
else
|
||||
{
|
||||
$field[$i]['_literal'] = empty($field[$i]['new_name']) ? "\n\tMODIFY " : "\n\tCHANGE ";
|
||||
}
|
||||
|
||||
$field[$i] = $field[$i]['_literal'].$this->_process_column($field[$i]);
|
||||
}
|
||||
}
|
||||
|
||||
return array($sql.implode(',', $field));
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Process column
|
||||
*
|
||||
* @param array $field
|
||||
* @return string
|
||||
*/
|
||||
protected function _process_column($field)
|
||||
{
|
||||
$extra_clause = isset($field['after'])
|
||||
? ' AFTER '.$this->db->escape_identifiers($field['after']) : '';
|
||||
|
||||
if (empty($extra_clause) && isset($field['first']) && $field['first'] === TRUE)
|
||||
{
|
||||
$extra_clause = ' FIRST';
|
||||
}
|
||||
|
||||
return $this->db->escape_identifiers($field['name'])
|
||||
.(empty($field['new_name']) ? '' : ' '.$this->db->escape_identifiers($field['new_name']))
|
||||
.' '.$field['type'].$field['length']
|
||||
.$field['unsigned']
|
||||
.$field['null']
|
||||
.$field['default']
|
||||
.$field['auto_increment']
|
||||
.$field['unique']
|
||||
.(empty($field['comment']) ? '' : ' COMMENT '.$field['comment'])
|
||||
.$extra_clause;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Process indexes
|
||||
*
|
||||
* @param string $table (ignored)
|
||||
* @return string
|
||||
*/
|
||||
protected function _process_indexes($table)
|
||||
{
|
||||
$sql = '';
|
||||
|
||||
for ($i = 0, $c = count($this->keys); $i < $c; $i++)
|
||||
{
|
||||
if (is_array($this->keys[$i]))
|
||||
{
|
||||
for ($i2 = 0, $c2 = count($this->keys[$i]); $i2 < $c2; $i2++)
|
||||
{
|
||||
if ( ! isset($this->fields[$this->keys[$i][$i2]]))
|
||||
{
|
||||
unset($this->keys[$i][$i2]);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
elseif ( ! isset($this->fields[$this->keys[$i]]))
|
||||
{
|
||||
unset($this->keys[$i]);
|
||||
continue;
|
||||
}
|
||||
|
||||
is_array($this->keys[$i]) OR $this->keys[$i] = array($this->keys[$i]);
|
||||
|
||||
$sql .= ",\n\tKEY ".$this->db->escape_identifiers(implode('_', $this->keys[$i]))
|
||||
.' ('.implode(', ', $this->db->escape_identifiers($this->keys[$i])).')';
|
||||
}
|
||||
|
||||
$this->keys = array();
|
||||
|
||||
return $sql;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,322 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2015 TechFuze
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 1.0.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* PDO Oracle Database Adapter Class
|
||||
*
|
||||
* Note: _DB is an extender class that the app controller
|
||||
* creates dynamically based on whether the query builder
|
||||
* class is being used or not.
|
||||
*
|
||||
* Converted from CodeIgniter.
|
||||
*
|
||||
* @package FuzeWorks
|
||||
* @subpackage Drivers
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
*/
|
||||
class FW_DB_pdo_oci_driver extends FW_DB_pdo_driver {
|
||||
|
||||
/**
|
||||
* Sub-driver
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $subdriver = 'oci';
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* List of reserved identifiers
|
||||
*
|
||||
* Identifiers that must NOT be escaped.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $_reserved_identifiers = array('*', 'rownum');
|
||||
|
||||
/**
|
||||
* ORDER BY random keyword
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_random_keyword = array('ASC', 'ASC'); // Currently not supported
|
||||
|
||||
/**
|
||||
* COUNT string
|
||||
*
|
||||
* @used-by FW_DB_driver::count_all()
|
||||
* @used-by FW_DB_query_builder::count_all_results()
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_count_string = 'SELECT COUNT(1) AS ';
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* Builds the DSN if not already set.
|
||||
*
|
||||
* @param array $params
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($params)
|
||||
{
|
||||
parent::__construct($params);
|
||||
|
||||
if (empty($this->dsn))
|
||||
{
|
||||
$this->dsn = 'oci:dbname=';
|
||||
|
||||
// Oracle has a slightly different PDO DSN format (Easy Connect),
|
||||
// which also supports pre-defined DSNs.
|
||||
if (empty($this->hostname) && empty($this->port))
|
||||
{
|
||||
$this->dsn .= $this->database;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->dsn .= '//'.(empty($this->hostname) ? '127.0.0.1' : $this->hostname)
|
||||
.(empty($this->port) ? '' : ':'.$this->port).'/';
|
||||
|
||||
empty($this->database) OR $this->dsn .= $this->database;
|
||||
}
|
||||
|
||||
empty($this->char_set) OR $this->dsn .= ';charset='.$this->char_set;
|
||||
}
|
||||
elseif ( ! empty($this->char_set) && strpos($this->dsn, 'charset=', 4) === FALSE)
|
||||
{
|
||||
$this->dsn .= ';charset='.$this->char_set;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Database version number
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function version()
|
||||
{
|
||||
if (isset($this->data_cache['version']))
|
||||
{
|
||||
return $this->data_cache['version'];
|
||||
}
|
||||
|
||||
$version_string = parent::version();
|
||||
if (preg_match('#Release\s(?<version>\d+(?:\.\d+)+)#', $version_string, $match))
|
||||
{
|
||||
return $this->data_cache['version'] = $match[1];
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Show table query
|
||||
*
|
||||
* Generates a platform-specific query string so that the table names can be fetched
|
||||
*
|
||||
* @param bool $prefix_limit
|
||||
* @return string
|
||||
*/
|
||||
protected function _list_tables($prefix_limit = FALSE)
|
||||
{
|
||||
$sql = 'SELECT "TABLE_NAME" FROM "ALL_TABLES"';
|
||||
|
||||
if ($prefix_limit === TRUE && $this->dbprefix !== '')
|
||||
{
|
||||
return $sql.' WHERE "TABLE_NAME" LIKE \''.$this->escape_like_str($this->dbprefix)."%' "
|
||||
.sprintf($this->_like_escape_str, $this->_like_escape_chr);
|
||||
}
|
||||
|
||||
return $sql;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Show column query
|
||||
*
|
||||
* Generates a platform-specific query string so that the column names can be fetched
|
||||
*
|
||||
* @param string $table
|
||||
* @return string
|
||||
*/
|
||||
protected function _list_columns($table = '')
|
||||
{
|
||||
if (strpos($table, '.') !== FALSE)
|
||||
{
|
||||
sscanf($table, '%[^.].%s', $owner, $table);
|
||||
}
|
||||
else
|
||||
{
|
||||
$owner = $this->username;
|
||||
}
|
||||
|
||||
return 'SELECT COLUMN_NAME FROM ALL_TAB_COLUMNS
|
||||
WHERE UPPER(OWNER) = '.$this->escape(strtoupper($owner)).'
|
||||
AND UPPER(TABLE_NAME) = '.$this->escape(strtoupper($table));
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Returns an object with field data
|
||||
*
|
||||
* @param string $table
|
||||
* @return array
|
||||
*/
|
||||
public function field_data($table)
|
||||
{
|
||||
if (strpos($table, '.') !== FALSE)
|
||||
{
|
||||
sscanf($table, '%[^.].%s', $owner, $table);
|
||||
}
|
||||
else
|
||||
{
|
||||
$owner = $this->username;
|
||||
}
|
||||
|
||||
$sql = 'SELECT COLUMN_NAME, DATA_TYPE, CHAR_LENGTH, DATA_PRECISION, DATA_LENGTH, DATA_DEFAULT, NULLABLE
|
||||
FROM ALL_TAB_COLUMNS
|
||||
WHERE UPPER(OWNER) = '.$this->escape(strtoupper($owner)).'
|
||||
AND UPPER(TABLE_NAME) = '.$this->escape(strtoupper($table));
|
||||
|
||||
if (($query = $this->query($sql)) === FALSE)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
$query = $query->result_object();
|
||||
|
||||
$retval = array();
|
||||
for ($i = 0, $c = count($query); $i < $c; $i++)
|
||||
{
|
||||
$retval[$i] = new stdClass();
|
||||
$retval[$i]->name = $query[$i]->COLUMN_NAME;
|
||||
$retval[$i]->type = $query[$i]->DATA_TYPE;
|
||||
|
||||
$length = ($query[$i]->CHAR_LENGTH > 0)
|
||||
? $query[$i]->CHAR_LENGTH : $query[$i]->DATA_PRECISION;
|
||||
if ($length === NULL)
|
||||
{
|
||||
$length = $query[$i]->DATA_LENGTH;
|
||||
}
|
||||
$retval[$i]->max_length = $length;
|
||||
|
||||
$default = $query[$i]->DATA_DEFAULT;
|
||||
if ($default === NULL && $query[$i]->NULLABLE === 'N')
|
||||
{
|
||||
$default = '';
|
||||
}
|
||||
$retval[$i]->default = $query[$i]->COLUMN_DEFAULT;
|
||||
}
|
||||
|
||||
return $retval;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Insert batch statement
|
||||
*
|
||||
* @param string $table Table name
|
||||
* @param array $keys INSERT keys
|
||||
* @param array $values INSERT values
|
||||
* @return string
|
||||
*/
|
||||
protected function _insert_batch($table, $keys, $values)
|
||||
{
|
||||
$keys = implode(', ', $keys);
|
||||
$sql = "INSERT ALL\n";
|
||||
|
||||
for ($i = 0, $c = count($values); $i < $c; $i++)
|
||||
{
|
||||
$sql .= ' INTO '.$table.' ('.$keys.') VALUES '.$values[$i]."\n";
|
||||
}
|
||||
|
||||
return $sql.'SELECT * FROM dual';
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Delete statement
|
||||
*
|
||||
* Generates a platform-specific delete string from the supplied data
|
||||
*
|
||||
* @param string $table
|
||||
* @return string
|
||||
*/
|
||||
protected function _delete($table)
|
||||
{
|
||||
if ($this->qb_limit)
|
||||
{
|
||||
$this->where('rownum <= ',$this->qb_limit, FALSE);
|
||||
$this->qb_limit = FALSE;
|
||||
}
|
||||
|
||||
return parent::_delete($table);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* LIMIT
|
||||
*
|
||||
* Generates a platform-specific LIMIT clause
|
||||
*
|
||||
* @param string $sql SQL Query
|
||||
* @return string
|
||||
*/
|
||||
protected function _limit($sql)
|
||||
{
|
||||
if (version_compare($this->version(), '12.1', '>='))
|
||||
{
|
||||
// OFFSET-FETCH can be used only with the ORDER BY clause
|
||||
empty($this->qb_orderby) && $sql .= ' ORDER BY 1';
|
||||
|
||||
return $sql.' OFFSET '.(int) $this->qb_offset.' ROWS FETCH NEXT '.$this->qb_limit.' ROWS ONLY';
|
||||
}
|
||||
|
||||
return 'SELECT * FROM (SELECT inner_query.*, rownum rnum FROM ('.$sql.') inner_query WHERE rownum < '.($this->qb_offset + $this->qb_limit + 1).')'
|
||||
.($this->qb_offset ? ' WHERE rnum >= '.($this->qb_offset + 1): '');
|
||||
}
|
||||
|
||||
}
|
|
@ -1,146 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2015 TechFuze
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 1.0.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* PDO Oracle Forge Class
|
||||
*
|
||||
* Converted from CodeIgniter.
|
||||
*
|
||||
* @package FuzeWorks
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
*/
|
||||
class FW_DB_pdo_oci_forge extends FW_DB_pdo_forge {
|
||||
|
||||
/**
|
||||
* CREATE DATABASE statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_create_database = FALSE;
|
||||
|
||||
/**
|
||||
* DROP DATABASE statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_drop_database = FALSE;
|
||||
|
||||
/**
|
||||
* CREATE TABLE IF statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_create_table_if = 'CREATE TABLE IF NOT EXISTS';
|
||||
|
||||
/**
|
||||
* UNSIGNED support
|
||||
*
|
||||
* @var bool|array
|
||||
*/
|
||||
protected $_unsigned = FALSE;
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* ALTER TABLE
|
||||
*
|
||||
* @param string $alter_type ALTER type
|
||||
* @param string $table Table name
|
||||
* @param mixed $field Column definition
|
||||
* @return string|string[]
|
||||
*/
|
||||
protected function _alter_table($alter_type, $table, $field)
|
||||
{
|
||||
if ($alter_type === 'DROP')
|
||||
{
|
||||
return parent::_alter_table($alter_type, $table, $field);
|
||||
}
|
||||
elseif ($alter_type === 'CHANGE')
|
||||
{
|
||||
$alter_type = 'MODIFY';
|
||||
}
|
||||
|
||||
$sql = 'ALTER TABLE '.$this->db->escape_identifiers($table);
|
||||
$sqls = array();
|
||||
for ($i = 0, $c = count($field); $i < $c; $i++)
|
||||
{
|
||||
if ($field[$i]['_literal'] !== FALSE)
|
||||
{
|
||||
$field[$i] = "\n\t".$field[$i]['_literal'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$field[$i]['_literal'] = "\n\t".$this->_process_column($field[$i]);
|
||||
|
||||
if ( ! empty($field[$i]['comment']))
|
||||
{
|
||||
$sqls[] = 'COMMENT ON COLUMN '
|
||||
.$this->db->escape_identifiers($table).'.'.$this->db->escape_identifiers($field[$i]['name'])
|
||||
.' IS '.$field[$i]['comment'];
|
||||
}
|
||||
|
||||
if ($alter_type === 'MODIFY' && ! empty($field[$i]['new_name']))
|
||||
{
|
||||
$sqls[] = $sql.' RENAME COLUMN '.$this->db->escape_identifiers($field[$i]['name'])
|
||||
.' '.$this->db->escape_identifiers($field[$i]['new_name']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$sql .= ' '.$alter_type.' ';
|
||||
$sql .= (count($field) === 1)
|
||||
? $field[0]
|
||||
: '('.implode(',', $field).')';
|
||||
|
||||
// RENAME COLUMN must be executed after MODIFY
|
||||
array_unshift($sqls, $sql);
|
||||
return $sql;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Field attribute AUTO_INCREMENT
|
||||
*
|
||||
* @param array &$attributes
|
||||
* @param array &$field
|
||||
* @return void
|
||||
*/
|
||||
protected function _attr_auto_increment(&$attributes, &$field)
|
||||
{
|
||||
// Not supported - sequences and triggers must be used instead
|
||||
}
|
||||
|
||||
}
|
|
@ -1,280 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2015 TechFuze
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 1.0.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* PDO ODBC Database Adapter Class
|
||||
*
|
||||
* Note: _DB is an extender class that the app controller
|
||||
* creates dynamically based on whether the query builder
|
||||
* class is being used or not.
|
||||
*
|
||||
* Converted from CodeIgniter.
|
||||
*
|
||||
* @package FuzeWorks
|
||||
* @subpackage Drivers
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
*/
|
||||
class FW_DB_pdo_odbc_driver extends FW_DB_pdo_driver {
|
||||
|
||||
/**
|
||||
* Sub-driver
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $subdriver = 'odbc';
|
||||
|
||||
/**
|
||||
* Database schema
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $schema = 'public';
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Identifier escape character
|
||||
*
|
||||
* Must be empty for ODBC.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_escape_char = '';
|
||||
|
||||
/**
|
||||
* ESCAPE statement string
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_like_escape_str = " {escape '%s'} ";
|
||||
|
||||
/**
|
||||
* ORDER BY random keyword
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_random_keyword = array('RND()', 'RND(%d)');
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* Builds the DSN if not already set.
|
||||
*
|
||||
* @param array $params
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($params)
|
||||
{
|
||||
parent::__construct($params);
|
||||
|
||||
if (empty($this->dsn))
|
||||
{
|
||||
$this->dsn = 'odbc:';
|
||||
|
||||
// Pre-defined DSN
|
||||
if (empty($this->hostname) && empty($this->HOSTNAME) && empty($this->port) && empty($this->PORT))
|
||||
{
|
||||
if (isset($this->DSN))
|
||||
{
|
||||
$this->dsn .= 'DSN='.$this->DSN;
|
||||
}
|
||||
elseif ( ! empty($this->database))
|
||||
{
|
||||
$this->dsn .= 'DSN='.$this->database;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// If the DSN is not pre-configured - try to build an IBM DB2 connection string
|
||||
$this->dsn .= 'DRIVER='.(isset($this->DRIVER) ? '{'.$this->DRIVER.'}' : '{IBM DB2 ODBC DRIVER}').';';
|
||||
|
||||
if (isset($this->DATABASE))
|
||||
{
|
||||
$this->dsn .= 'DATABASE='.$this->DATABASE.';';
|
||||
}
|
||||
elseif ( ! empty($this->database))
|
||||
{
|
||||
$this->dsn .= 'DATABASE='.$this->database.';';
|
||||
}
|
||||
|
||||
if (isset($this->HOSTNAME))
|
||||
{
|
||||
$this->dsn .= 'HOSTNAME='.$this->HOSTNAME.';';
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->dsn .= 'HOSTNAME='.(empty($this->hostname) ? '127.0.0.1;' : $this->hostname.';');
|
||||
}
|
||||
|
||||
if (isset($this->PORT))
|
||||
{
|
||||
$this->dsn .= 'PORT='.$this->port.';';
|
||||
}
|
||||
elseif ( ! empty($this->port))
|
||||
{
|
||||
$this->dsn .= ';PORT='.$this->port.';';
|
||||
}
|
||||
|
||||
$this->dsn .= 'PROTOCOL='.(isset($this->PROTOCOL) ? $this->PROTOCOL.';' : 'TCPIP;');
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Determines if a query is a "write" type.
|
||||
*
|
||||
* @param string An SQL query string
|
||||
* @return bool
|
||||
*/
|
||||
public function is_write_type($sql)
|
||||
{
|
||||
if (preg_match('#^(INSERT|UPDATE).*RETURNING\s.+(\,\s?.+)*$#i', $sql))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return parent::is_write_type($sql);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Show table query
|
||||
*
|
||||
* Generates a platform-specific query string so that the table names can be fetched
|
||||
*
|
||||
* @param bool $prefix_limit
|
||||
* @return string
|
||||
*/
|
||||
protected function _list_tables($prefix_limit = FALSE)
|
||||
{
|
||||
$sql = "SELECT table_name FROM information_schema.tables WHERE table_schema = '".$this->schema."'";
|
||||
|
||||
if ($prefix_limit !== FALSE && $this->dbprefix !== '')
|
||||
{
|
||||
return $sql." AND table_name LIKE '".$this->escape_like_str($this->dbprefix)."%' "
|
||||
.sprintf($this->_like_escape_str, $this->_like_escape_chr);
|
||||
}
|
||||
|
||||
return $sql;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Show column query
|
||||
*
|
||||
* Generates a platform-specific query string so that the column names can be fetched
|
||||
*
|
||||
* @param string $table
|
||||
* @return string
|
||||
*/
|
||||
protected function _list_columns($table = '')
|
||||
{
|
||||
return 'SELECT column_name FROM information_schema.columns WHERE table_name = '.$this->escape($table);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Update statement
|
||||
*
|
||||
* Generates a platform-specific update string from the supplied data
|
||||
*
|
||||
* @param string $table
|
||||
* @param array $values
|
||||
* @return string
|
||||
*/
|
||||
protected function _update($table, $values)
|
||||
{
|
||||
$this->qb_limit = FALSE;
|
||||
$this->qb_orderby = array();
|
||||
return parent::_update($table, $values);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Truncate statement
|
||||
*
|
||||
* Generates a platform-specific truncate string from the supplied data
|
||||
*
|
||||
* If the database does not support the TRUNCATE statement,
|
||||
* then this method maps to 'DELETE FROM table'
|
||||
*
|
||||
* @param string $table
|
||||
* @return string
|
||||
*/
|
||||
protected function _truncate($table)
|
||||
{
|
||||
return 'DELETE FROM '.$table;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Delete statement
|
||||
*
|
||||
* Generates a platform-specific delete string from the supplied data
|
||||
*
|
||||
* @param string the table name
|
||||
* @return string
|
||||
*/
|
||||
protected function _delete($table)
|
||||
{
|
||||
$this->qb_limit = FALSE;
|
||||
return parent::_delete($table);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* LIMIT
|
||||
*
|
||||
* Generates a platform-specific LIMIT clause
|
||||
*
|
||||
* @param string $sql SQL Query
|
||||
* @return string
|
||||
*/
|
||||
protected function _limit($sql)
|
||||
{
|
||||
return preg_replace('/(^\SELECT (DISTINCT)?)/i','\\1 TOP '.$this->qb_limit.' ', $sql);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,67 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2015 TechFuze
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 1.0.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* PDO ODBC Forge Class
|
||||
*
|
||||
* Converted from CodeIgniter.
|
||||
*
|
||||
* @package FuzeWorks
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/database/
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
*/
|
||||
class FW_DB_pdo_odbc_forge extends FW_DB_pdo_forge {
|
||||
|
||||
/**
|
||||
* UNSIGNED support
|
||||
*
|
||||
* @var bool|array
|
||||
*/
|
||||
protected $_unsigned = FALSE;
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Field attribute AUTO_INCREMENT
|
||||
*
|
||||
* @param array &$attributes
|
||||
* @param array &$field
|
||||
* @return void
|
||||
*/
|
||||
protected function _attr_auto_increment(&$attributes, &$field)
|
||||
{
|
||||
// Not supported (in most databases at least)
|
||||
}
|
||||
|
||||
}
|
|
@ -1,380 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2015 TechFuze
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 1.0.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* PDO PostgreSQL Database Adapter Class
|
||||
*
|
||||
* Note: _DB is an extender class that the app controller
|
||||
* creates dynamically based on whether the query builder
|
||||
* class is being used or not.
|
||||
*
|
||||
* Converted from CodeIgniter.
|
||||
*
|
||||
* @package FuzeWorks
|
||||
* @subpackage Drivers
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
*/
|
||||
class FW_DB_pdo_pgsql_driver extends FW_DB_pdo_driver {
|
||||
|
||||
/**
|
||||
* Sub-driver
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $subdriver = 'pgsql';
|
||||
|
||||
/**
|
||||
* Database schema
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $schema = 'public';
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* ORDER BY random keyword
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_random_keyword = array('RANDOM()', 'RANDOM()');
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* Builds the DSN if not already set.
|
||||
*
|
||||
* @param array $params
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($params)
|
||||
{
|
||||
parent::__construct($params);
|
||||
|
||||
if (empty($this->dsn))
|
||||
{
|
||||
$this->dsn = 'pgsql:host='.(empty($this->hostname) ? '127.0.0.1' : $this->hostname);
|
||||
|
||||
empty($this->port) OR $this->dsn .= ';port='.$this->port;
|
||||
empty($this->database) OR $this->dsn .= ';dbname='.$this->database;
|
||||
|
||||
if ( ! empty($this->username))
|
||||
{
|
||||
$this->dsn .= ';username='.$this->username;
|
||||
empty($this->password) OR $this->dsn .= ';password='.$this->password;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Database connection
|
||||
*
|
||||
* @param bool $persistent
|
||||
* @return object
|
||||
*/
|
||||
public function db_connect($persistent = FALSE)
|
||||
{
|
||||
$this->conn_id = parent::db_connect($persistent);
|
||||
|
||||
if (is_object($this->conn_id) && ! empty($this->schema))
|
||||
{
|
||||
$this->simple_query('SET search_path TO '.$this->schema.',public');
|
||||
}
|
||||
|
||||
return $this->conn_id;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Insert ID
|
||||
*
|
||||
* @param string $name
|
||||
* @return int
|
||||
*/
|
||||
public function insert_id($name = NULL)
|
||||
{
|
||||
if ($name === NULL && version_compare($this->version(), '8.1', '>='))
|
||||
{
|
||||
$query = $this->query('SELECT LASTVAL() AS ins_id');
|
||||
$query = $query->row();
|
||||
return $query->ins_id;
|
||||
}
|
||||
|
||||
return $this->conn_id->lastInsertId($name);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Determines if a query is a "write" type.
|
||||
*
|
||||
* @param string An SQL query string
|
||||
* @return bool
|
||||
*/
|
||||
public function is_write_type($sql)
|
||||
{
|
||||
if (preg_match('#^(INSERT|UPDATE).*RETURNING\s.+(\,\s?.+)*$#i', $sql))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return parent::is_write_type($sql);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* "Smart" Escape String
|
||||
*
|
||||
* Escapes data based on type
|
||||
*
|
||||
* @param string $str
|
||||
* @return mixed
|
||||
*/
|
||||
public function escape($str)
|
||||
{
|
||||
if (is_bool($str))
|
||||
{
|
||||
return ($str) ? 'TRUE' : 'FALSE';
|
||||
}
|
||||
|
||||
return parent::escape($str);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* ORDER BY
|
||||
*
|
||||
* @param string $orderby
|
||||
* @param string $direction ASC, DESC or RANDOM
|
||||
* @param bool $escape
|
||||
* @return object
|
||||
*/
|
||||
public function order_by($orderby, $direction = '', $escape = NULL)
|
||||
{
|
||||
$direction = strtoupper(trim($direction));
|
||||
if ($direction === 'RANDOM')
|
||||
{
|
||||
if ( ! is_float($orderby) && ctype_digit((string) $orderby))
|
||||
{
|
||||
$orderby = ($orderby > 1)
|
||||
? (float) '0.'.$orderby
|
||||
: (float) $orderby;
|
||||
}
|
||||
|
||||
if (is_float($orderby))
|
||||
{
|
||||
$this->simple_query('SET SEED '.$orderby);
|
||||
}
|
||||
|
||||
$orderby = $this->_random_keyword[0];
|
||||
$direction = '';
|
||||
$escape = FALSE;
|
||||
}
|
||||
|
||||
return parent::order_by($orderby, $direction, $escape);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Show table query
|
||||
*
|
||||
* Generates a platform-specific query string so that the table names can be fetched
|
||||
*
|
||||
* @param bool $prefix_limit
|
||||
* @return string
|
||||
*/
|
||||
protected function _list_tables($prefix_limit = FALSE)
|
||||
{
|
||||
$sql = 'SELECT "table_name" FROM "information_schema"."tables" WHERE "table_schema" = \''.$this->schema."'";
|
||||
|
||||
if ($prefix_limit === TRUE && $this->dbprefix !== '')
|
||||
{
|
||||
return $sql.' AND "table_name" LIKE \''
|
||||
.$this->escape_like_str($this->dbprefix)."%' "
|
||||
.sprintf($this->_like_escape_str, $this->_like_escape_chr);
|
||||
}
|
||||
|
||||
return $sql;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* List column query
|
||||
*
|
||||
* Generates a platform-specific query string so that the column names can be fetched
|
||||
*
|
||||
* @param string $table
|
||||
* @return string
|
||||
*/
|
||||
protected function _list_columns($table = '')
|
||||
{
|
||||
return 'SELECT "column_name"
|
||||
FROM "information_schema"."columns"
|
||||
WHERE LOWER("table_name") = '.$this->escape(strtolower($table));
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Returns an object with field data
|
||||
*
|
||||
* @param string $table
|
||||
* @return array
|
||||
*/
|
||||
public function field_data($table)
|
||||
{
|
||||
$sql = 'SELECT "column_name", "data_type", "character_maximum_length", "numeric_precision", "column_default"
|
||||
FROM "information_schema"."columns"
|
||||
WHERE LOWER("table_name") = '.$this->escape(strtolower($table));
|
||||
|
||||
if (($query = $this->query($sql)) === FALSE)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
$query = $query->result_object();
|
||||
|
||||
$retval = array();
|
||||
for ($i = 0, $c = count($query); $i < $c; $i++)
|
||||
{
|
||||
$retval[$i] = new stdClass();
|
||||
$retval[$i]->name = $query[$i]->column_name;
|
||||
$retval[$i]->type = $query[$i]->data_type;
|
||||
$retval[$i]->max_length = ($query[$i]->character_maximum_length > 0) ? $query[$i]->character_maximum_length : $query[$i]->numeric_precision;
|
||||
$retval[$i]->default = $query[$i]->column_default;
|
||||
}
|
||||
|
||||
return $retval;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Update statement
|
||||
*
|
||||
* Generates a platform-specific update string from the supplied data
|
||||
*
|
||||
* @param string $table
|
||||
* @param array $values
|
||||
* @return string
|
||||
*/
|
||||
protected function _update($table, $values)
|
||||
{
|
||||
$this->qb_limit = FALSE;
|
||||
$this->qb_orderby = array();
|
||||
return parent::_update($table, $values);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Update_Batch statement
|
||||
*
|
||||
* Generates a platform-specific batch update string from the supplied data
|
||||
*
|
||||
* @param string $table Table name
|
||||
* @param array $values Update data
|
||||
* @param string $index WHERE key
|
||||
* @return string
|
||||
*/
|
||||
protected function _update_batch($table, $values, $index)
|
||||
{
|
||||
$ids = array();
|
||||
foreach ($values as $key => $val)
|
||||
{
|
||||
$ids[] = $val[$index];
|
||||
|
||||
foreach (array_keys($val) as $field)
|
||||
{
|
||||
if ($field !== $index)
|
||||
{
|
||||
$final[$field][] = 'WHEN '.$val[$index].' THEN '.$val[$field];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$cases = '';
|
||||
foreach ($final as $k => $v)
|
||||
{
|
||||
$cases .= $k.' = (CASE '.$index."\n"
|
||||
.implode("\n", $v)."\n"
|
||||
.'ELSE '.$k.' END), ';
|
||||
}
|
||||
|
||||
$this->where($index.' IN('.implode(',', $ids).')', NULL, FALSE);
|
||||
|
||||
return 'UPDATE '.$table.' SET '.substr($cases, 0, -2).$this->_compile_wh('qb_where');
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Delete statement
|
||||
*
|
||||
* Generates a platform-specific delete string from the supplied data
|
||||
*
|
||||
* @param string $table
|
||||
* @return string
|
||||
*/
|
||||
protected function _delete($table)
|
||||
{
|
||||
$this->qb_limit = FALSE;
|
||||
return parent::_delete($table);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* LIMIT
|
||||
*
|
||||
* Generates a platform-specific LIMIT clause
|
||||
*
|
||||
* @param string $sql SQL Query
|
||||
* @return string
|
||||
*/
|
||||
protected function _limit($sql)
|
||||
{
|
||||
return $sql.' LIMIT '.$this->qb_limit.($this->qb_offset ? ' OFFSET '.$this->qb_offset : '');
|
||||
}
|
||||
|
||||
}
|
|
@ -1,207 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2015 TechFuze
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 1.0.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* PDO PostgreSQL Forge Class
|
||||
*
|
||||
* Converted from CodeIgniter.
|
||||
*
|
||||
* @package FuzeWorks
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
*/
|
||||
class FW_DB_pdo_pgsql_forge extends FW_DB_pdo_forge {
|
||||
|
||||
/**
|
||||
* DROP TABLE IF statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_drop_table_if = 'DROP TABLE IF EXISTS';
|
||||
|
||||
/**
|
||||
* UNSIGNED support
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_unsigned = array(
|
||||
'INT2' => 'INTEGER',
|
||||
'SMALLINT' => 'INTEGER',
|
||||
'INT' => 'BIGINT',
|
||||
'INT4' => 'BIGINT',
|
||||
'INTEGER' => 'BIGINT',
|
||||
'INT8' => 'NUMERIC',
|
||||
'BIGINT' => 'NUMERIC',
|
||||
'REAL' => 'DOUBLE PRECISION',
|
||||
'FLOAT' => 'DOUBLE PRECISION'
|
||||
);
|
||||
|
||||
/**
|
||||
* NULL value representation in CREATE/ALTER TABLE statements
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_null = 'NULL';
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param object &$db Database object
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(&$db)
|
||||
{
|
||||
parent::__construct($db);
|
||||
|
||||
if (version_compare($this->db->version(), '9.0', '>'))
|
||||
{
|
||||
$this->create_table_if = 'CREATE TABLE IF NOT EXISTS';
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* ALTER TABLE
|
||||
*
|
||||
* @param string $alter_type ALTER type
|
||||
* @param string $table Table name
|
||||
* @param mixed $field Column definition
|
||||
* @return string|string[]
|
||||
*/
|
||||
protected function _alter_table($alter_type, $table, $field)
|
||||
{
|
||||
if (in_array($alter_type, array('DROP', 'ADD'), TRUE))
|
||||
{
|
||||
return parent::_alter_table($alter_type, $table, $field);
|
||||
}
|
||||
|
||||
$sql = 'ALTER TABLE '.$this->db->escape_identifiers($table);
|
||||
$sqls = array();
|
||||
for ($i = 0, $c = count($field); $i < $c; $i++)
|
||||
{
|
||||
if ($field[$i]['_literal'] !== FALSE)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (version_compare($this->db->version(), '8', '>=') && isset($field[$i]['type']))
|
||||
{
|
||||
$sqls[] = $sql.' ALTER COLUMN '.$this->db->escape_identifiers($field[$i]['name'])
|
||||
.' TYPE '.$field[$i]['type'].$field[$i]['length'];
|
||||
}
|
||||
|
||||
if ( ! empty($field[$i]['default']))
|
||||
{
|
||||
$sqls[] = $sql.' ALTER COLUMN '.$this->db->escape_identifiers($field[$i]['name'])
|
||||
.' SET DEFAULT '.$field[$i]['default'];
|
||||
}
|
||||
|
||||
if (isset($field[$i]['null']))
|
||||
{
|
||||
$sqls[] = $sql.' ALTER COLUMN '.$this->db->escape_identifiers($field[$i]['name'])
|
||||
.($field[$i]['null'] === TRUE ? ' DROP NOT NULL' : ' SET NOT NULL');
|
||||
}
|
||||
|
||||
if ( ! empty($field[$i]['new_name']))
|
||||
{
|
||||
$sqls[] = $sql.' RENAME COLUMN '.$this->db->escape_identifiers($field[$i]['name'])
|
||||
.' TO '.$this->db->escape_identifiers($field[$i]['new_name']);
|
||||
}
|
||||
|
||||
if ( ! empty($field[$i]['comment']))
|
||||
{
|
||||
$sqls[] = 'COMMENT ON COLUMN '
|
||||
.$this->db->escape_identifiers($table).'.'.$this->db->escape_identifiers($field[$i]['name'])
|
||||
.' IS '.$field[$i]['comment'];
|
||||
}
|
||||
}
|
||||
|
||||
return $sqls;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Field attribute TYPE
|
||||
*
|
||||
* Performs a data type mapping between different databases.
|
||||
*
|
||||
* @param array &$attributes
|
||||
* @return void
|
||||
*/
|
||||
protected function _attr_type(&$attributes)
|
||||
{
|
||||
// Reset field lenghts for data types that don't support it
|
||||
if (isset($attributes['CONSTRAINT']) && stripos($attributes['TYPE'], 'int') !== FALSE)
|
||||
{
|
||||
$attributes['CONSTRAINT'] = NULL;
|
||||
}
|
||||
|
||||
switch (strtoupper($attributes['TYPE']))
|
||||
{
|
||||
case 'TINYINT':
|
||||
$attributes['TYPE'] = 'SMALLINT';
|
||||
$attributes['UNSIGNED'] = FALSE;
|
||||
return;
|
||||
case 'MEDIUMINT':
|
||||
$attributes['TYPE'] = 'INTEGER';
|
||||
$attributes['UNSIGNED'] = FALSE;
|
||||
return;
|
||||
default: return;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Field attribute AUTO_INCREMENT
|
||||
*
|
||||
* @param array &$attributes
|
||||
* @param array &$field
|
||||
* @return void
|
||||
*/
|
||||
protected function _attr_auto_increment(&$attributes, &$field)
|
||||
{
|
||||
if ( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE)
|
||||
{
|
||||
$field['type'] = ($field['type'] === 'NUMERIC')
|
||||
? 'BIGSERIAL'
|
||||
: 'SERIAL';
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,215 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2015 TechFuze
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 1.0.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* PDO SQLite Database Adapter Class
|
||||
*
|
||||
* Note: _DB is an extender class that the app controller
|
||||
* creates dynamically based on whether the query builder
|
||||
* class is being used or not.
|
||||
*
|
||||
* Converted from CodeIgniter.
|
||||
*
|
||||
* @package FuzeWorks
|
||||
* @subpackage Drivers
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
*/
|
||||
class FW_DB_pdo_sqlite_driver extends FW_DB_pdo_driver {
|
||||
|
||||
/**
|
||||
* Sub-driver
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $subdriver = 'sqlite';
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* ORDER BY random keyword
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_random_keyword = ' RANDOM()';
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* Builds the DSN if not already set.
|
||||
*
|
||||
* @param array $params
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($params)
|
||||
{
|
||||
parent::__construct($params);
|
||||
|
||||
if (empty($this->dsn))
|
||||
{
|
||||
$this->dsn = 'sqlite:';
|
||||
|
||||
if (empty($this->database) && empty($this->hostname))
|
||||
{
|
||||
$this->database = ':memory:';
|
||||
}
|
||||
|
||||
$this->database = empty($this->database) ? $this->hostname : $this->database;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Show table query
|
||||
*
|
||||
* Generates a platform-specific query string so that the table names can be fetched
|
||||
*
|
||||
* @param bool $prefix_limit
|
||||
* @return string
|
||||
*/
|
||||
protected function _list_tables($prefix_limit = FALSE)
|
||||
{
|
||||
$sql = 'SELECT "NAME" FROM "SQLITE_MASTER" WHERE "TYPE" = \'table\'';
|
||||
|
||||
if ($prefix_limit === TRUE && $this->dbprefix !== '')
|
||||
{
|
||||
return $sql.' AND "NAME" LIKE \''.$this->escape_like_str($this->dbprefix)."%' "
|
||||
.sprintf($this->_like_escape_str, $this->_like_escape_chr);
|
||||
}
|
||||
|
||||
return $sql;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Fetch Field Names
|
||||
*
|
||||
* @param string $table Table name
|
||||
* @return array
|
||||
*/
|
||||
public function list_fields($table)
|
||||
{
|
||||
// Is there a cached result?
|
||||
if (isset($this->data_cache['field_names'][$table]))
|
||||
{
|
||||
return $this->data_cache['field_names'][$table];
|
||||
}
|
||||
|
||||
if (($result = $this->query('PRAGMA TABLE_INFO('.$this->protect_identifiers($table, TRUE, NULL, FALSE).')')) === FALSE)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$this->data_cache['field_names'][$table] = array();
|
||||
foreach ($result->result_array() as $row)
|
||||
{
|
||||
$this->data_cache['field_names'][$table][] = $row['name'];
|
||||
}
|
||||
|
||||
return $this->data_cache['field_names'][$table];
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Returns an object with field data
|
||||
*
|
||||
* @param string $table
|
||||
* @return array
|
||||
*/
|
||||
public function field_data($table)
|
||||
{
|
||||
if (($query = $this->query('PRAGMA TABLE_INFO('.$this->protect_identifiers($table, TRUE, NULL, FALSE).')')) === FALSE)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$query = $query->result_array();
|
||||
if (empty($query))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$retval = array();
|
||||
for ($i = 0, $c = count($query); $i < $c; $i++)
|
||||
{
|
||||
$retval[$i] = new stdClass();
|
||||
$retval[$i]->name = $query[$i]['name'];
|
||||
$retval[$i]->type = $query[$i]['type'];
|
||||
$retval[$i]->max_length = NULL;
|
||||
$retval[$i]->default = $query[$i]['dflt_value'];
|
||||
$retval[$i]->primary_key = isset($query[$i]['pk']) ? (int) $query[$i]['pk'] : 0;
|
||||
}
|
||||
|
||||
return $retval;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Replace statement
|
||||
*
|
||||
* @param string $table Table name
|
||||
* @param array $keys INSERT keys
|
||||
* @param array $values INSERT values
|
||||
* @return string
|
||||
*/
|
||||
protected function _replace($table, $keys, $values)
|
||||
{
|
||||
return 'INSERT OR '.parent::_replace($table, $keys, $values);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Truncate statement
|
||||
*
|
||||
* Generates a platform-specific truncate string from the supplied data
|
||||
*
|
||||
* If the database does not support the TRUNCATE statement,
|
||||
* then this method maps to 'DELETE FROM table'
|
||||
*
|
||||
* @param string $table
|
||||
* @return string
|
||||
*/
|
||||
protected function _truncate($table)
|
||||
{
|
||||
return 'DELETE FROM '.$table;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,235 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2015 TechFuze
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 1.0.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* PDO SQLite Forge Class
|
||||
*
|
||||
* Converted from CodeIgniter.
|
||||
*
|
||||
* @package FuzeWorks
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
*/
|
||||
class FW_DB_pdo_sqlite_forge extends FW_DB_pdo_forge {
|
||||
|
||||
/**
|
||||
* CREATE TABLE IF statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_create_table_if = 'CREATE TABLE IF NOT EXISTS';
|
||||
|
||||
/**
|
||||
* DROP TABLE IF statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_drop_table_if = 'DROP TABLE IF EXISTS';
|
||||
|
||||
/**
|
||||
* UNSIGNED support
|
||||
*
|
||||
* @var bool|array
|
||||
*/
|
||||
protected $_unsigned = FALSE;
|
||||
|
||||
/**
|
||||
* NULL value representation in CREATE/ALTER TABLE statements
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_null = 'NULL';
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param object &$db Database object
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(&$db)
|
||||
{
|
||||
parent::__construct($db);
|
||||
|
||||
if (version_compare($this->db->version(), '3.3', '<'))
|
||||
{
|
||||
$this->_create_table_if = FALSE;
|
||||
$this->_drop_table_if = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Create database
|
||||
*
|
||||
* @param string $db_name (ignored)
|
||||
* @return bool
|
||||
*/
|
||||
public function create_database($db_name = '')
|
||||
{
|
||||
// In SQLite, a database is created when you connect to the database.
|
||||
// We'll return TRUE so that an error isn't generated
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Drop database
|
||||
*
|
||||
* @param string $db_name (ignored)
|
||||
* @return bool
|
||||
*/
|
||||
public function drop_database($db_name = '')
|
||||
{
|
||||
// In SQLite, a database is dropped when we delete a file
|
||||
if (file_exists($this->db->database))
|
||||
{
|
||||
// We need to close the pseudo-connection first
|
||||
$this->db->close();
|
||||
if ( ! @unlink($this->db->database))
|
||||
{
|
||||
return $this->db->db_debug ? $this->db->display_error('db_unable_to_drop') : FALSE;
|
||||
}
|
||||
elseif ( ! empty($this->db->data_cache['db_names']))
|
||||
{
|
||||
$key = array_search(strtolower($this->db->database), array_map('strtolower', $this->db->data_cache['db_names']), TRUE);
|
||||
if ($key !== FALSE)
|
||||
{
|
||||
unset($this->db->data_cache['db_names'][$key]);
|
||||
}
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return $this->db->db_debug ? $this->db->display_error('db_unable_to_drop') : FALSE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* ALTER TABLE
|
||||
*
|
||||
* @param string $alter_type ALTER type
|
||||
* @param string $table Table name
|
||||
* @param mixed $field Column definition
|
||||
* @return string|string[]
|
||||
*/
|
||||
protected function _alter_table($alter_type, $table, $field)
|
||||
{
|
||||
if ($alter_type === 'DROP' OR $alter_type === 'CHANGE')
|
||||
{
|
||||
// drop_column():
|
||||
// BEGIN TRANSACTION;
|
||||
// CREATE TEMPORARY TABLE t1_backup(a,b);
|
||||
// INSERT INTO t1_backup SELECT a,b FROM t1;
|
||||
// DROP TABLE t1;
|
||||
// CREATE TABLE t1(a,b);
|
||||
// INSERT INTO t1 SELECT a,b FROM t1_backup;
|
||||
// DROP TABLE t1_backup;
|
||||
// COMMIT;
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return parent::_alter_table($alter_type, $table, $field);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Process column
|
||||
*
|
||||
* @param array $field
|
||||
* @return string
|
||||
*/
|
||||
protected function _process_column($field)
|
||||
{
|
||||
return $this->db->escape_identifiers($field['name'])
|
||||
.' '.$field['type']
|
||||
.$field['auto_increment']
|
||||
.$field['null']
|
||||
.$field['unique']
|
||||
.$field['default'];
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Field attribute TYPE
|
||||
*
|
||||
* Performs a data type mapping between different databases.
|
||||
*
|
||||
* @param array &$attributes
|
||||
* @return void
|
||||
*/
|
||||
protected function _attr_type(&$attributes)
|
||||
{
|
||||
switch (strtoupper($attributes['TYPE']))
|
||||
{
|
||||
case 'ENUM':
|
||||
case 'SET':
|
||||
$attributes['TYPE'] = 'TEXT';
|
||||
return;
|
||||
default: return;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Field attribute AUTO_INCREMENT
|
||||
*
|
||||
* @param array &$attributes
|
||||
* @param array &$field
|
||||
* @return void
|
||||
*/
|
||||
protected function _attr_auto_increment(&$attributes, &$field)
|
||||
{
|
||||
if ( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE && stripos($field['type'], 'int') !== FALSE)
|
||||
{
|
||||
$field['type'] = 'INTEGER PRIMARY KEY';
|
||||
$field['default'] = '';
|
||||
$field['null'] = '';
|
||||
$field['unique'] = '';
|
||||
$field['auto_increment'] = ' AUTOINCREMENT';
|
||||
|
||||
$this->primary_keys = array();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,365 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2015 TechFuze
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 1.0.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* PDO SQLSRV Database Adapter Class
|
||||
*
|
||||
* Note: _DB is an extender class that the app controller
|
||||
* creates dynamically based on whether the query builder
|
||||
* class is being used or not.
|
||||
*
|
||||
* Converted from CodeIgniter.
|
||||
*
|
||||
* @package FuzeWorks
|
||||
* @subpackage Drivers
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
*/
|
||||
class FW_DB_pdo_sqlsrv_driver extends FW_DB_pdo_driver {
|
||||
|
||||
/**
|
||||
* Sub-driver
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $subdriver = 'sqlsrv';
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* ORDER BY random keyword
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_random_keyword = array('NEWID()', 'RAND(%d)');
|
||||
|
||||
/**
|
||||
* Quoted identifier flag
|
||||
*
|
||||
* Whether to use SQL-92 standard quoted identifier
|
||||
* (double quotes) or brackets for identifier escaping.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $_quoted_identifier;
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* Builds the DSN if not already set.
|
||||
*
|
||||
* @param array $params
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($params)
|
||||
{
|
||||
parent::__construct($params);
|
||||
|
||||
if (empty($this->dsn))
|
||||
{
|
||||
$this->dsn = 'sqlsrv:Server='.(empty($this->hostname) ? '127.0.0.1' : $this->hostname);
|
||||
|
||||
empty($this->port) OR $this->dsn .= ','.$this->port;
|
||||
empty($this->database) OR $this->dsn .= ';Database='.$this->database;
|
||||
|
||||
// Some custom options
|
||||
|
||||
if (isset($this->QuotedId))
|
||||
{
|
||||
$this->dsn .= ';QuotedId='.$this->QuotedId;
|
||||
$this->_quoted_identifier = (bool) $this->QuotedId;
|
||||
}
|
||||
|
||||
if (isset($this->ConnectionPooling))
|
||||
{
|
||||
$this->dsn .= ';ConnectionPooling='.$this->ConnectionPooling;
|
||||
}
|
||||
|
||||
if ($this->encrypt === TRUE)
|
||||
{
|
||||
$this->dsn .= ';Encrypt=1';
|
||||
}
|
||||
|
||||
if (isset($this->TraceOn))
|
||||
{
|
||||
$this->dsn .= ';TraceOn='.$this->TraceOn;
|
||||
}
|
||||
|
||||
if (isset($this->TrustServerCertificate))
|
||||
{
|
||||
$this->dsn .= ';TrustServerCertificate='.$this->TrustServerCertificate;
|
||||
}
|
||||
|
||||
empty($this->APP) OR $this->dsn .= ';APP='.$this->APP;
|
||||
empty($this->Failover_Partner) OR $this->dsn .= ';Failover_Partner='.$this->Failover_Partner;
|
||||
empty($this->LoginTimeout) OR $this->dsn .= ';LoginTimeout='.$this->LoginTimeout;
|
||||
empty($this->MultipleActiveResultSets) OR $this->dsn .= ';MultipleActiveResultSets='.$this->MultipleActiveResultSets;
|
||||
empty($this->TraceFile) OR $this->dsn .= ';TraceFile='.$this->TraceFile;
|
||||
empty($this->WSID) OR $this->dsn .= ';WSID='.$this->WSID;
|
||||
}
|
||||
elseif (preg_match('/QuotedId=(0|1)/', $this->dsn, $match))
|
||||
{
|
||||
$this->_quoted_identifier = (bool) $match[1];
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Database connection
|
||||
*
|
||||
* @param bool $persistent
|
||||
* @return object
|
||||
*/
|
||||
public function db_connect($persistent = FALSE)
|
||||
{
|
||||
if ( ! empty($this->char_set) && preg_match('/utf[^8]*8/i', $this->char_set))
|
||||
{
|
||||
$this->options[PDO::SQLSRV_ENCODING_UTF8] = 1;
|
||||
}
|
||||
|
||||
$this->conn_id = parent::db_connect($persistent);
|
||||
|
||||
if ( ! is_object($this->conn_id) OR is_bool($this->_quoted_identifier))
|
||||
{
|
||||
return $this->conn_id;
|
||||
}
|
||||
|
||||
// Determine how identifiers are escaped
|
||||
$query = $this->query('SELECT CASE WHEN (@@OPTIONS | 256) = @@OPTIONS THEN 1 ELSE 0 END AS qi');
|
||||
$query = $query->row_array();
|
||||
$this->_quoted_identifier = empty($query) ? FALSE : (bool) $query['qi'];
|
||||
$this->_escape_char = ($this->_quoted_identifier) ? '"' : array('[', ']');
|
||||
|
||||
return $this->conn_id;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Show table query
|
||||
*
|
||||
* Generates a platform-specific query string so that the table names can be fetched
|
||||
*
|
||||
* @param bool $prefix_limit
|
||||
* @return string
|
||||
*/
|
||||
protected function _list_tables($prefix_limit = FALSE)
|
||||
{
|
||||
$sql = 'SELECT '.$this->escape_identifiers('name')
|
||||
.' FROM '.$this->escape_identifiers('sysobjects')
|
||||
.' WHERE '.$this->escape_identifiers('type')." = 'U'";
|
||||
|
||||
if ($prefix_limit === TRUE && $this->dbprefix !== '')
|
||||
{
|
||||
$sql .= ' AND '.$this->escape_identifiers('name')." LIKE '".$this->escape_like_str($this->dbprefix)."%' "
|
||||
.sprintf($this->_like_escape_str, $this->_like_escape_chr);
|
||||
}
|
||||
|
||||
return $sql.' ORDER BY '.$this->escape_identifiers('name');
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Show column query
|
||||
*
|
||||
* Generates a platform-specific query string so that the column names can be fetched
|
||||
*
|
||||
* @param string $table
|
||||
* @return string
|
||||
*/
|
||||
protected function _list_columns($table = '')
|
||||
{
|
||||
return 'SELECT COLUMN_NAME
|
||||
FROM INFORMATION_SCHEMA.Columns
|
||||
WHERE UPPER(TABLE_NAME) = '.$this->escape(strtoupper($table));
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Returns an object with field data
|
||||
*
|
||||
* @param string $table
|
||||
* @return array
|
||||
*/
|
||||
public function field_data($table)
|
||||
{
|
||||
$sql = 'SELECT COLUMN_NAME, DATA_TYPE, CHARACTER_MAXIMUM_LENGTH, NUMERIC_PRECISION, COLUMN_DEFAULT
|
||||
FROM INFORMATION_SCHEMA.Columns
|
||||
WHERE UPPER(TABLE_NAME) = '.$this->escape(strtoupper($table));
|
||||
|
||||
if (($query = $this->query($sql)) === FALSE)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
$query = $query->result_object();
|
||||
|
||||
$retval = array();
|
||||
for ($i = 0, $c = count($query); $i < $c; $i++)
|
||||
{
|
||||
$retval[$i] = new stdClass();
|
||||
$retval[$i]->name = $query[$i]->COLUMN_NAME;
|
||||
$retval[$i]->type = $query[$i]->DATA_TYPE;
|
||||
$retval[$i]->max_length = ($query[$i]->CHARACTER_MAXIMUM_LENGTH > 0) ? $query[$i]->CHARACTER_MAXIMUM_LENGTH : $query[$i]->NUMERIC_PRECISION;
|
||||
$retval[$i]->default = $query[$i]->COLUMN_DEFAULT;
|
||||
}
|
||||
|
||||
return $retval;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Update statement
|
||||
*
|
||||
* Generates a platform-specific update string from the supplied data
|
||||
*
|
||||
* @param string $table
|
||||
* @param array $values
|
||||
* @return string
|
||||
*/
|
||||
protected function _update($table, $values)
|
||||
{
|
||||
$this->qb_limit = FALSE;
|
||||
$this->qb_orderby = array();
|
||||
return parent::_update($table, $values);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Delete statement
|
||||
*
|
||||
* Generates a platform-specific delete string from the supplied data
|
||||
*
|
||||
* @param string $table
|
||||
* @return string
|
||||
*/
|
||||
protected function _delete($table)
|
||||
{
|
||||
if ($this->qb_limit)
|
||||
{
|
||||
return 'WITH fw_delete AS (SELECT TOP '.$this->qb_limit.' * FROM '.$table.$this->_compile_wh('qb_where').') DELETE FROM fw_delete';
|
||||
}
|
||||
|
||||
return parent::_delete($table);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* LIMIT
|
||||
*
|
||||
* Generates a platform-specific LIMIT clause
|
||||
*
|
||||
* @param string $sql SQL Query
|
||||
* @return string
|
||||
*/
|
||||
protected function _limit($sql)
|
||||
{
|
||||
// As of SQL Server 2012 (11.0.*) OFFSET is supported
|
||||
if (version_compare($this->version(), '11', '>='))
|
||||
{
|
||||
// SQL Server OFFSET-FETCH can be used only with the ORDER BY clause
|
||||
empty($this->qb_orderby) && $sql .= ' ORDER BY 1';
|
||||
|
||||
return $sql.' OFFSET '.(int) $this->qb_offset.' ROWS FETCH NEXT '.$this->qb_limit.' ROWS ONLY';
|
||||
}
|
||||
|
||||
$limit = $this->qb_offset + $this->qb_limit;
|
||||
|
||||
// An ORDER BY clause is required for ROW_NUMBER() to work
|
||||
if ($this->qb_offset && ! empty($this->qb_orderby))
|
||||
{
|
||||
$orderby = $this->_compile_order_by();
|
||||
|
||||
// We have to strip the ORDER BY clause
|
||||
$sql = trim(substr($sql, 0, strrpos($sql, $orderby)));
|
||||
|
||||
// Get the fields to select from our subquery, so that we can avoid FW_rownum appearing in the actual results
|
||||
if (count($this->qb_select) === 0)
|
||||
{
|
||||
$select = '*'; // Inevitable
|
||||
}
|
||||
else
|
||||
{
|
||||
// Use only field names and their aliases, everything else is out of our scope.
|
||||
$select = array();
|
||||
$field_regexp = ($this->_quoted_identifier)
|
||||
? '("[^\"]+")' : '(\[[^\]]+\])';
|
||||
for ($i = 0, $c = count($this->qb_select); $i < $c; $i++)
|
||||
{
|
||||
$select[] = preg_match('/(?:\s|\.)'.$field_regexp.'$/i', $this->qb_select[$i], $m)
|
||||
? $m[1] : $this->qb_select[$i];
|
||||
}
|
||||
$select = implode(', ', $select);
|
||||
}
|
||||
|
||||
return 'SELECT '.$select." FROM (\n\n"
|
||||
.preg_replace('/^(SELECT( DISTINCT)?)/i', '\\1 ROW_NUMBER() OVER('.trim($orderby).') AS '.$this->escape_identifiers('FW_rownum').', ', $sql)
|
||||
."\n\n) ".$this->escape_identifiers('FW_subquery')
|
||||
."\nWHERE ".$this->escape_identifiers('FW_rownum').' BETWEEN '.($this->qb_offset + 1).' AND '.$limit;
|
||||
}
|
||||
|
||||
return preg_replace('/(^\SELECT (DISTINCT)?)/i','\\1 TOP '.$limit.' ', $sql);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Insert batch statement
|
||||
*
|
||||
* Generates a platform-specific insert string from the supplied data.
|
||||
*
|
||||
* @param string $table Table name
|
||||
* @param array $keys INSERT keys
|
||||
* @param array $values INSERT values
|
||||
* @return string|bool
|
||||
*/
|
||||
protected function _insert_batch($table, $keys, $values)
|
||||
{
|
||||
// Multiple-value inserts are only supported as of SQL Server 2008
|
||||
if (version_compare($this->version(), '10', '>='))
|
||||
{
|
||||
return parent::_insert_batch($table, $keys, $values);
|
||||
}
|
||||
|
||||
return ($this->db->db_debug) ? $this->db->display_error('db_unsupported_feature') : FALSE;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,141 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2015 TechFuze
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 1.0.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* PDO SQLSRV Forge Class
|
||||
*
|
||||
* Converted from CodeIgniter.
|
||||
*
|
||||
* @package FuzeWorks
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
*/
|
||||
class FW_DB_pdo_sqlsrv_forge extends FW_DB_pdo_forge {
|
||||
|
||||
/**
|
||||
* CREATE TABLE IF statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_create_table_if = "IF NOT EXISTS (SELECT * FROM sysobjects WHERE ID = object_id(N'%s') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)\nCREATE TABLE";
|
||||
|
||||
/**
|
||||
* DROP TABLE IF statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_drop_table_if = "IF EXISTS (SELECT * FROM sysobjects WHERE ID = object_id(N'%s') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)\nDROP TABLE";
|
||||
|
||||
/**
|
||||
* UNSIGNED support
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_unsigned = array(
|
||||
'TINYINT' => 'SMALLINT',
|
||||
'SMALLINT' => 'INT',
|
||||
'INT' => 'BIGINT',
|
||||
'REAL' => 'FLOAT'
|
||||
);
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* ALTER TABLE
|
||||
*
|
||||
* @param string $alter_type ALTER type
|
||||
* @param string $table Table name
|
||||
* @param mixed $field Column definition
|
||||
* @return string|string[]
|
||||
*/
|
||||
protected function _alter_table($alter_type, $table, $field)
|
||||
{
|
||||
if (in_array($alter_type, array('ADD', 'DROP'), TRUE))
|
||||
{
|
||||
return parent::_alter_table($alter_type, $table, $field);
|
||||
}
|
||||
|
||||
$sql = 'ALTER TABLE '.$this->db->escape_identifiers($table).' ALTER COLUMN ';
|
||||
$sqls = array();
|
||||
for ($i = 0, $c = count($field); $i < $c; $i++)
|
||||
{
|
||||
$sqls[] = $sql.$this->_process_column($field[$i]);
|
||||
}
|
||||
|
||||
return $sqls;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Field attribute TYPE
|
||||
*
|
||||
* Performs a data type mapping between different databases.
|
||||
*
|
||||
* @param array &$attributes
|
||||
* @return void
|
||||
*/
|
||||
protected function _attr_type(&$attributes)
|
||||
{
|
||||
switch (strtoupper($attributes['TYPE']))
|
||||
{
|
||||
case 'MEDIUMINT':
|
||||
$attributes['TYPE'] = 'INTEGER';
|
||||
$attributes['UNSIGNED'] = FALSE;
|
||||
return;
|
||||
case 'INTEGER':
|
||||
$attributes['TYPE'] = 'INT';
|
||||
return;
|
||||
default: return;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Field attribute AUTO_INCREMENT
|
||||
*
|
||||
* @param array &$attributes
|
||||
* @param array &$field
|
||||
* @return void
|
||||
*/
|
||||
protected function _attr_auto_increment(&$attributes, &$field)
|
||||
{
|
||||
if ( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE && stripos($field['type'], 'int') !== FALSE)
|
||||
{
|
||||
$field['auto_increment'] = ' IDENTITY(1,1)';
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,618 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2015 TechFuze
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 1.0.0
|
||||
*/
|
||||
|
||||
use FuzeWorks\Core;
|
||||
|
||||
/**
|
||||
* Postgre Database Adapter Class
|
||||
*
|
||||
* Note: _DB is an extender class that the app controller
|
||||
* creates dynamically based on whether the query builder
|
||||
* class is being used or not.
|
||||
*
|
||||
* Converted from CodeIgniter.
|
||||
*
|
||||
* @package FuzeWorks
|
||||
* @subpackage Drivers
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
*/
|
||||
class FW_DB_postgre_driver extends FW_DB {
|
||||
|
||||
/**
|
||||
* Database driver
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $dbdriver = 'postgre';
|
||||
|
||||
/**
|
||||
* Database schema
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $schema = 'public';
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* ORDER BY random keyword
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_random_keyword = array('RANDOM()', 'RANDOM()');
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* Creates a DSN string to be used for db_connect() and db_pconnect()
|
||||
*
|
||||
* @param array $params
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($params)
|
||||
{
|
||||
parent::__construct($params);
|
||||
|
||||
if ( ! empty($this->dsn))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$this->dsn === '' OR $this->dsn = '';
|
||||
|
||||
if (strpos($this->hostname, '/') !== FALSE)
|
||||
{
|
||||
// If UNIX sockets are used, we shouldn't set a port
|
||||
$this->port = '';
|
||||
}
|
||||
|
||||
$this->hostname === '' OR $this->dsn = 'host='.$this->hostname.' ';
|
||||
|
||||
if ( ! empty($this->port) && ctype_digit($this->port))
|
||||
{
|
||||
$this->dsn .= 'port='.$this->port.' ';
|
||||
}
|
||||
|
||||
if ($this->username !== '')
|
||||
{
|
||||
$this->dsn .= 'user='.$this->username.' ';
|
||||
|
||||
/* An empty password is valid!
|
||||
*
|
||||
* $db['password'] = NULL must be done in order to ignore it.
|
||||
*/
|
||||
$this->password === NULL OR $this->dsn .= "password='".$this->password."' ";
|
||||
}
|
||||
|
||||
$this->database === '' OR $this->dsn .= 'dbname='.$this->database.' ';
|
||||
|
||||
/* We don't have these options as elements in our standard configuration
|
||||
* array, but they might be set by parse_url() if the configuration was
|
||||
* provided via string. Example:
|
||||
*
|
||||
* postgre://username:password@localhost:5432/database?connect_timeout=5&sslmode=1
|
||||
*/
|
||||
foreach (array('connect_timeout', 'options', 'sslmode', 'service') as $key)
|
||||
{
|
||||
if (isset($this->$key) && is_string($this->key) && $this->key !== '')
|
||||
{
|
||||
$this->dsn .= $key."='".$this->key."' ";
|
||||
}
|
||||
}
|
||||
|
||||
$this->dsn = rtrim($this->dsn);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Database connection
|
||||
*
|
||||
* @param bool $persistent
|
||||
* @return resource
|
||||
*/
|
||||
public function db_connect($persistent = FALSE)
|
||||
{
|
||||
$this->conn_id = ($persistent === TRUE)
|
||||
? pg_pconnect($this->dsn)
|
||||
: pg_connect($this->dsn);
|
||||
|
||||
if ($this->conn_id !== FALSE)
|
||||
{
|
||||
if ($persistent === TRUE
|
||||
&& pg_connection_status($this->conn_id) === PGSQL_CONNECTION_BAD
|
||||
&& pg_ping($this->conn_id) === FALSE
|
||||
)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
empty($this->schema) OR $this->simple_query('SET search_path TO '.$this->schema.',public');
|
||||
}
|
||||
|
||||
return $this->conn_id;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Reconnect
|
||||
*
|
||||
* Keep / reestablish the db connection if no queries have been
|
||||
* sent for a length of time exceeding the server's idle timeout
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function reconnect()
|
||||
{
|
||||
if (pg_ping($this->conn_id) === FALSE)
|
||||
{
|
||||
$this->conn_id = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Set client character set
|
||||
*
|
||||
* @param string $charset
|
||||
* @return bool
|
||||
*/
|
||||
protected function _db_set_charset($charset)
|
||||
{
|
||||
return (pg_set_client_encoding($this->conn_id, $charset) === 0);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Database version number
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function version()
|
||||
{
|
||||
if (isset($this->data_cache['version']))
|
||||
{
|
||||
return $this->data_cache['version'];
|
||||
}
|
||||
|
||||
if ( ! $this->conn_id OR ($pg_version = pg_version($this->conn_id)) === FALSE)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* If PHP was compiled with PostgreSQL lib versions earlier
|
||||
* than 7.4, pg_version() won't return the server version
|
||||
* and so we'll have to fall back to running a query in
|
||||
* order to get it.
|
||||
*/
|
||||
return isset($pg_version['server'])
|
||||
? $this->data_cache['version'] = $pg_version['server']
|
||||
: parent::version();
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Execute the query
|
||||
*
|
||||
* @param string $sql an SQL query
|
||||
* @return resource
|
||||
*/
|
||||
protected function _execute($sql)
|
||||
{
|
||||
return pg_query($this->conn_id, $sql);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Begin Transaction
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function _trans_begin()
|
||||
{
|
||||
return (bool) pg_query($this->conn_id, 'BEGIN');
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Commit Transaction
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function _trans_commit()
|
||||
{
|
||||
return (bool) pg_query($this->conn_id, 'COMMIT');
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Rollback Transaction
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function _trans_rollback()
|
||||
{
|
||||
return (bool) pg_query($this->conn_id, 'ROLLBACK');
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Determines if a query is a "write" type.
|
||||
*
|
||||
* @param string An SQL query string
|
||||
* @return bool
|
||||
*/
|
||||
public function is_write_type($sql)
|
||||
{
|
||||
if (preg_match('#^(INSERT|UPDATE).*RETURNING\s.+(\,\s?.+)*$#i', $sql))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return parent::is_write_type($sql);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Platform-dependant string escape
|
||||
*
|
||||
* @param string
|
||||
* @return string
|
||||
*/
|
||||
protected function _escape_str($str)
|
||||
{
|
||||
return pg_escape_string($this->conn_id, $str);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* "Smart" Escape String
|
||||
*
|
||||
* Escapes data based on type
|
||||
*
|
||||
* @param string $str
|
||||
* @return mixed
|
||||
*/
|
||||
public function escape($str)
|
||||
{
|
||||
if (Core::isPHP('5.4.4') && (is_string($str) OR (is_object($str) && method_exists($str, '__toString'))))
|
||||
{
|
||||
return pg_escape_literal($this->conn_id, $str);
|
||||
}
|
||||
elseif (is_bool($str))
|
||||
{
|
||||
return ($str) ? 'TRUE' : 'FALSE';
|
||||
}
|
||||
|
||||
return parent::escape($str);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Affected Rows
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function affected_rows()
|
||||
{
|
||||
return pg_affected_rows($this->result_id);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Insert ID
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function insert_id()
|
||||
{
|
||||
$v = pg_version($this->conn_id);
|
||||
$v = isset($v['server']) ? $v['server'] : 0; // 'server' key is only available since PosgreSQL 7.4
|
||||
|
||||
$table = (func_num_args() > 0) ? func_get_arg(0) : NULL;
|
||||
$column = (func_num_args() > 1) ? func_get_arg(1) : NULL;
|
||||
|
||||
if ($table === NULL && $v >= '8.1')
|
||||
{
|
||||
$sql = 'SELECT LASTVAL() AS ins_id';
|
||||
}
|
||||
elseif ($table !== NULL)
|
||||
{
|
||||
if ($column !== NULL && $v >= '8.0')
|
||||
{
|
||||
$sql = 'SELECT pg_get_serial_sequence(\''.$table."', '".$column."') AS seq";
|
||||
$query = $this->query($sql);
|
||||
$query = $query->row();
|
||||
$seq = $query->seq;
|
||||
}
|
||||
else
|
||||
{
|
||||
// seq_name passed in table parameter
|
||||
$seq = $table;
|
||||
}
|
||||
|
||||
$sql = 'SELECT CURRVAL(\''.$seq."') AS ins_id";
|
||||
}
|
||||
else
|
||||
{
|
||||
return pg_last_oid($this->result_id);
|
||||
}
|
||||
|
||||
$query = $this->query($sql);
|
||||
$query = $query->row();
|
||||
return (int) $query->ins_id;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Show table query
|
||||
*
|
||||
* Generates a platform-specific query string so that the table names can be fetched
|
||||
*
|
||||
* @param bool $prefix_limit
|
||||
* @return string
|
||||
*/
|
||||
protected function _list_tables($prefix_limit = FALSE)
|
||||
{
|
||||
$sql = 'SELECT "table_name" FROM "information_schema"."tables" WHERE "table_schema" = \''.$this->schema."'";
|
||||
|
||||
if ($prefix_limit !== FALSE && $this->dbprefix !== '')
|
||||
{
|
||||
return $sql.' AND "table_name" LIKE \''
|
||||
.$this->escape_like_str($this->dbprefix)."%' "
|
||||
.sprintf($this->_like_escape_str, $this->_like_escape_chr);
|
||||
}
|
||||
|
||||
return $sql;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* List column query
|
||||
*
|
||||
* Generates a platform-specific query string so that the column names can be fetched
|
||||
*
|
||||
* @param string $table
|
||||
* @return string
|
||||
*/
|
||||
protected function _list_columns($table = '')
|
||||
{
|
||||
return 'SELECT "column_name"
|
||||
FROM "information_schema"."columns"
|
||||
WHERE LOWER("table_name") = '.$this->escape(strtolower($table));
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Returns an object with field data
|
||||
*
|
||||
* @param string $table
|
||||
* @return array
|
||||
*/
|
||||
public function field_data($table)
|
||||
{
|
||||
$sql = 'SELECT "column_name", "data_type", "character_maximum_length", "numeric_precision", "column_default"
|
||||
FROM "information_schema"."columns"
|
||||
WHERE LOWER("table_name") = '.$this->escape(strtolower($table));
|
||||
|
||||
if (($query = $this->query($sql)) === FALSE)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
$query = $query->result_object();
|
||||
|
||||
$retval = array();
|
||||
for ($i = 0, $c = count($query); $i < $c; $i++)
|
||||
{
|
||||
$retval[$i] = new stdClass();
|
||||
$retval[$i]->name = $query[$i]->column_name;
|
||||
$retval[$i]->type = $query[$i]->data_type;
|
||||
$retval[$i]->max_length = ($query[$i]->character_maximum_length > 0) ? $query[$i]->character_maximum_length : $query[$i]->numeric_precision;
|
||||
$retval[$i]->default = $query[$i]->column_default;
|
||||
}
|
||||
|
||||
return $retval;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Error
|
||||
*
|
||||
* Returns an array containing code and message of the last
|
||||
* database error that has occured.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function error()
|
||||
{
|
||||
return array('code' => '', 'message' => pg_last_error($this->conn_id));
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* ORDER BY
|
||||
*
|
||||
* @param string $orderby
|
||||
* @param string $direction ASC, DESC or RANDOM
|
||||
* @param bool $escape
|
||||
* @return object
|
||||
*/
|
||||
public function order_by($orderby, $direction = '', $escape = NULL)
|
||||
{
|
||||
$direction = strtoupper(trim($direction));
|
||||
if ($direction === 'RANDOM')
|
||||
{
|
||||
if ( ! is_float($orderby) && ctype_digit((string) $orderby))
|
||||
{
|
||||
$orderby = ($orderby > 1)
|
||||
? (float) '0.'.$orderby
|
||||
: (float) $orderby;
|
||||
}
|
||||
|
||||
if (is_float($orderby))
|
||||
{
|
||||
$this->simple_query('SET SEED '.$orderby);
|
||||
}
|
||||
|
||||
$orderby = $this->_random_keyword[0];
|
||||
$direction = '';
|
||||
$escape = FALSE;
|
||||
}
|
||||
|
||||
return parent::order_by($orderby, $direction, $escape);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Update statement
|
||||
*
|
||||
* Generates a platform-specific update string from the supplied data
|
||||
*
|
||||
* @param string $table
|
||||
* @param array $values
|
||||
* @return string
|
||||
*/
|
||||
protected function _update($table, $values)
|
||||
{
|
||||
$this->qb_limit = FALSE;
|
||||
$this->qb_orderby = array();
|
||||
return parent::_update($table, $values);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Update_Batch statement
|
||||
*
|
||||
* Generates a platform-specific batch update string from the supplied data
|
||||
*
|
||||
* @param string $table Table name
|
||||
* @param array $values Update data
|
||||
* @param string $index WHERE key
|
||||
* @return string
|
||||
*/
|
||||
protected function _update_batch($table, $values, $index)
|
||||
{
|
||||
$ids = array();
|
||||
foreach ($values as $key => $val)
|
||||
{
|
||||
$ids[] = $val[$index];
|
||||
|
||||
foreach (array_keys($val) as $field)
|
||||
{
|
||||
if ($field !== $index)
|
||||
{
|
||||
$final[$field][] = 'WHEN '.$val[$index].' THEN '.$val[$field];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$cases = '';
|
||||
foreach ($final as $k => $v)
|
||||
{
|
||||
$cases .= $k.' = (CASE '.$index."\n"
|
||||
.implode("\n", $v)."\n"
|
||||
.'ELSE '.$k.' END), ';
|
||||
}
|
||||
|
||||
$this->where($index.' IN('.implode(',', $ids).')', NULL, FALSE);
|
||||
|
||||
return 'UPDATE '.$table.' SET '.substr($cases, 0, -2).$this->_compile_wh('qb_where');
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Delete statement
|
||||
*
|
||||
* Generates a platform-specific delete string from the supplied data
|
||||
*
|
||||
* @param string $table
|
||||
* @return string
|
||||
*/
|
||||
protected function _delete($table)
|
||||
{
|
||||
$this->qb_limit = FALSE;
|
||||
return parent::_delete($table);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* LIMIT
|
||||
*
|
||||
* Generates a platform-specific LIMIT clause
|
||||
*
|
||||
* @param string $sql SQL Query
|
||||
* @return string
|
||||
*/
|
||||
protected function _limit($sql)
|
||||
{
|
||||
return $sql.' LIMIT '.$this->qb_limit.($this->qb_offset ? ' OFFSET '.$this->qb_offset : '');
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Close DB Connection
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _close()
|
||||
{
|
||||
pg_close($this->conn_id);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,201 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2015 TechFuze
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 1.0.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* Postgre Forge Class
|
||||
*
|
||||
* Converted from CodeIgniter.
|
||||
*
|
||||
* @package FuzeWorks
|
||||
* @subpackage Drivers
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
*/
|
||||
class FW_DB_postgre_forge extends FW_DB_forge {
|
||||
|
||||
/**
|
||||
* UNSIGNED support
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_unsigned = array(
|
||||
'INT2' => 'INTEGER',
|
||||
'SMALLINT' => 'INTEGER',
|
||||
'INT' => 'BIGINT',
|
||||
'INT4' => 'BIGINT',
|
||||
'INTEGER' => 'BIGINT',
|
||||
'INT8' => 'NUMERIC',
|
||||
'BIGINT' => 'NUMERIC',
|
||||
'REAL' => 'DOUBLE PRECISION',
|
||||
'FLOAT' => 'DOUBLE PRECISION'
|
||||
);
|
||||
|
||||
/**
|
||||
* NULL value representation in CREATE/ALTER TABLE statements
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_null = 'NULL';
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param object &$db Database object
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(&$db)
|
||||
{
|
||||
parent::__construct($db);
|
||||
|
||||
if (version_compare($this->db->version(), '9.0', '>'))
|
||||
{
|
||||
$this->create_table_if = 'CREATE TABLE IF NOT EXISTS';
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* ALTER TABLE
|
||||
*
|
||||
* @param string $alter_type ALTER type
|
||||
* @param string $table Table name
|
||||
* @param mixed $field Column definition
|
||||
* @return string|string[]
|
||||
*/
|
||||
protected function _alter_table($alter_type, $table, $field)
|
||||
{
|
||||
if (in_array($alter_type, array('DROP', 'ADD'), TRUE))
|
||||
{
|
||||
return parent::_alter_table($alter_type, $table, $field);
|
||||
}
|
||||
|
||||
$sql = 'ALTER TABLE '.$this->db->escape_identifiers($table);
|
||||
$sqls = array();
|
||||
for ($i = 0, $c = count($field); $i < $c; $i++)
|
||||
{
|
||||
if ($field[$i]['_literal'] !== FALSE)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (version_compare($this->db->version(), '8', '>=') && isset($field[$i]['type']))
|
||||
{
|
||||
$sqls[] = $sql.' ALTER COLUMN '.$this->db->escape_identifiers($field[$i]['name'])
|
||||
.' TYPE '.$field[$i]['type'].$field[$i]['length'];
|
||||
}
|
||||
|
||||
if ( ! empty($field[$i]['default']))
|
||||
{
|
||||
$sqls[] = $sql.' ALTER COLUMN '.$this->db->escape_identifiers($field[$i]['name'])
|
||||
.' SET DEFAULT '.$field[$i]['default'];
|
||||
}
|
||||
|
||||
if (isset($field[$i]['null']))
|
||||
{
|
||||
$sqls[] = $sql.' ALTER COLUMN '.$this->db->escape_identifiers($field[$i]['name'])
|
||||
.($field[$i]['null'] === TRUE ? ' DROP NOT NULL' : ' SET NOT NULL');
|
||||
}
|
||||
|
||||
if ( ! empty($field[$i]['new_name']))
|
||||
{
|
||||
$sqls[] = $sql.' RENAME COLUMN '.$this->db->escape_identifiers($field[$i]['name'])
|
||||
.' TO '.$this->db->escape_identifiers($field[$i]['new_name']);
|
||||
}
|
||||
|
||||
if ( ! empty($field[$i]['comment']))
|
||||
{
|
||||
$sqls[] = 'COMMENT ON COLUMN '
|
||||
.$this->db->escape_identifiers($table).'.'.$this->db->escape_identifiers($field[$i]['name'])
|
||||
.' IS '.$field[$i]['comment'];
|
||||
}
|
||||
}
|
||||
|
||||
return $sqls;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Field attribute TYPE
|
||||
*
|
||||
* Performs a data type mapping between different databases.
|
||||
*
|
||||
* @param array &$attributes
|
||||
* @return void
|
||||
*/
|
||||
protected function _attr_type(&$attributes)
|
||||
{
|
||||
// Reset field lenghts for data types that don't support it
|
||||
if (isset($attributes['CONSTRAINT']) && stripos($attributes['TYPE'], 'int') !== FALSE)
|
||||
{
|
||||
$attributes['CONSTRAINT'] = NULL;
|
||||
}
|
||||
|
||||
switch (strtoupper($attributes['TYPE']))
|
||||
{
|
||||
case 'TINYINT':
|
||||
$attributes['TYPE'] = 'SMALLINT';
|
||||
$attributes['UNSIGNED'] = FALSE;
|
||||
return;
|
||||
case 'MEDIUMINT':
|
||||
$attributes['TYPE'] = 'INTEGER';
|
||||
$attributes['UNSIGNED'] = FALSE;
|
||||
return;
|
||||
default: return;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Field attribute AUTO_INCREMENT
|
||||
*
|
||||
* @param array &$attributes
|
||||
* @param array &$field
|
||||
* @return void
|
||||
*/
|
||||
protected function _attr_auto_increment(&$attributes, &$field)
|
||||
{
|
||||
if ( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE)
|
||||
{
|
||||
$field['type'] = ($field['type'] === 'NUMERIC')
|
||||
? 'BIGSERIAL'
|
||||
: 'SERIAL';
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,178 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2015 TechFuze
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 1.0.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* Postgres Result Class
|
||||
*
|
||||
* This class extends the parent result class: FW_DB_result
|
||||
*
|
||||
* Converted from CodeIgniter.
|
||||
*
|
||||
* @package FuzeWorks
|
||||
* @subpackage Drivers
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
*/
|
||||
class FW_DB_postgre_result extends FW_DB_result {
|
||||
|
||||
/**
|
||||
* Number of rows in the result set
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function num_rows()
|
||||
{
|
||||
return is_int($this->num_rows)
|
||||
? $this->num_rows
|
||||
: $this->num_rows = pg_num_rows($this->result_id);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Number of fields in the result set
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function num_fields()
|
||||
{
|
||||
return pg_num_fields($this->result_id);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Fetch Field Names
|
||||
*
|
||||
* Generates an array of column names
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function list_fields()
|
||||
{
|
||||
$field_names = array();
|
||||
for ($i = 0, $c = $this->num_fields(); $i < $c; $i++)
|
||||
{
|
||||
$field_names[] = pg_field_name($this->result_id, $i);
|
||||
}
|
||||
|
||||
return $field_names;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Field data
|
||||
*
|
||||
* Generates an array of objects containing field meta-data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function field_data()
|
||||
{
|
||||
$retval = array();
|
||||
for ($i = 0, $c = $this->num_fields(); $i < $c; $i++)
|
||||
{
|
||||
$retval[$i] = new stdClass();
|
||||
$retval[$i]->name = pg_field_name($this->result_id, $i);
|
||||
$retval[$i]->type = pg_field_type($this->result_id, $i);
|
||||
$retval[$i]->max_length = pg_field_size($this->result_id, $i);
|
||||
}
|
||||
|
||||
return $retval;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Free the result
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function free_result()
|
||||
{
|
||||
if (is_resource($this->result_id))
|
||||
{
|
||||
pg_free_result($this->result_id);
|
||||
$this->result_id = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Data Seek
|
||||
*
|
||||
* Moves the internal pointer to the desired offset. We call
|
||||
* this internally before fetching results to make sure the
|
||||
* result set starts at zero.
|
||||
*
|
||||
* @param int $n
|
||||
* @return bool
|
||||
*/
|
||||
public function data_seek($n = 0)
|
||||
{
|
||||
return pg_result_seek($this->result_id, $n);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Result - associative array
|
||||
*
|
||||
* Returns the result set as an array
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function _fetch_assoc()
|
||||
{
|
||||
return pg_fetch_assoc($this->result_id);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Result - object
|
||||
*
|
||||
* Returns the result set as an object
|
||||
*
|
||||
* @param string $class_name
|
||||
* @return object
|
||||
*/
|
||||
protected function _fetch_object($class_name = 'stdClass')
|
||||
{
|
||||
return pg_fetch_object($this->result_id, NULL, $class_name);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,74 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2015 TechFuze
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 1.0.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* Postgre Utility Class
|
||||
*
|
||||
* Converted from CodeIgniter.
|
||||
*
|
||||
* @package FuzeWorks
|
||||
* @subpackage Drivers
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
*/
|
||||
class FW_DB_postgre_utility extends FW_DB_utility {
|
||||
|
||||
/**
|
||||
* List databases statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_list_databases = 'SELECT datname FROM pg_database';
|
||||
|
||||
/**
|
||||
* OPTIMIZE TABLE statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_optimize_table = 'REINDEX TABLE %s';
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Export
|
||||
*
|
||||
* @param array $params Preferences
|
||||
* @return mixed
|
||||
*/
|
||||
protected function _backup($params = array())
|
||||
{
|
||||
// Currently unsupported
|
||||
return $this->db->display_error('db_unsupported_feature');
|
||||
}
|
||||
}
|
|
@ -1,328 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2015 TechFuze
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 1.0.0
|
||||
*/
|
||||
|
||||
use FuzeWorks\Logger;
|
||||
|
||||
/**
|
||||
* SQLite Database Adapter Class
|
||||
*
|
||||
* Note: _DB is an extender class that the app controller
|
||||
* creates dynamically based on whether the query builder
|
||||
* class is being used or not.
|
||||
*
|
||||
* Converted from CodeIgniter.
|
||||
*
|
||||
* @package FuzeWorks
|
||||
* @subpackage Drivers
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
*/
|
||||
class FW_DB_sqlite_driver extends FW_DB {
|
||||
|
||||
/**
|
||||
* Database driver
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $dbdriver = 'sqlite';
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* ORDER BY random keyword
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_random_keyword = array('RANDOM()', 'RANDOM()');
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Non-persistent database connection
|
||||
*
|
||||
* @param bool $persistent
|
||||
* @return resource
|
||||
*/
|
||||
public function db_connect($persistent = FALSE)
|
||||
{
|
||||
$error = NULL;
|
||||
$conn_id = ($persistent === TRUE)
|
||||
? sqlite_popen($this->database, 0666, $error)
|
||||
: sqlite_open($this->database, 0666, $error);
|
||||
|
||||
isset($error) && Logger::logError($error);
|
||||
|
||||
return $conn_id;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Database version number
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function version()
|
||||
{
|
||||
return isset($this->data_cache['version'])
|
||||
? $this->data_cache['version']
|
||||
: $this->data_cache['version'] = sqlite_libversion();
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Execute the query
|
||||
*
|
||||
* @param string $sql an SQL query
|
||||
* @return resource
|
||||
*/
|
||||
protected function _execute($sql)
|
||||
{
|
||||
return $this->is_write_type($sql)
|
||||
? sqlite_exec($this->conn_id, $sql)
|
||||
: sqlite_query($this->conn_id, $sql);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Begin Transaction
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function _trans_begin()
|
||||
{
|
||||
return $this->simple_query('BEGIN TRANSACTION');
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Commit Transaction
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function _trans_commit()
|
||||
{
|
||||
return $this->simple_query('COMMIT');
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Rollback Transaction
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function _trans_rollback()
|
||||
{
|
||||
return $this->simple_query('ROLLBACK');
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Platform-dependant string escape
|
||||
*
|
||||
* @param string
|
||||
* @return string
|
||||
*/
|
||||
protected function _escape_str($str)
|
||||
{
|
||||
return sqlite_escape_string($str);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Affected Rows
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function affected_rows()
|
||||
{
|
||||
return sqlite_changes($this->conn_id);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Insert ID
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function insert_id()
|
||||
{
|
||||
return sqlite_last_insert_rowid($this->conn_id);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* List table query
|
||||
*
|
||||
* Generates a platform-specific query string so that the table names can be fetched
|
||||
*
|
||||
* @param bool $prefix_limit
|
||||
* @return string
|
||||
*/
|
||||
protected function _list_tables($prefix_limit = FALSE)
|
||||
{
|
||||
$sql = "SELECT name FROM sqlite_master WHERE type='table'";
|
||||
|
||||
if ($prefix_limit !== FALSE && $this->dbprefix != '')
|
||||
{
|
||||
return $sql." AND 'name' LIKE '".$this->escape_like_str($this->dbprefix)."%' ".sprintf($this->_like_escape_str, $this->_like_escape_chr);
|
||||
}
|
||||
|
||||
return $sql;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Show column query
|
||||
*
|
||||
* Generates a platform-specific query string so that the column names can be fetched
|
||||
*
|
||||
* @param string $table
|
||||
* @return bool
|
||||
*/
|
||||
protected function _list_columns($table = '')
|
||||
{
|
||||
// Not supported
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Returns an object with field data
|
||||
*
|
||||
* @param string $table
|
||||
* @return array
|
||||
*/
|
||||
public function field_data($table)
|
||||
{
|
||||
if (($query = $this->query('PRAGMA TABLE_INFO('.$this->protect_identifiers($table, TRUE, NULL, FALSE).')')) === FALSE)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$query = $query->result_array();
|
||||
if (empty($query))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$retval = array();
|
||||
for ($i = 0, $c = count($query); $i < $c; $i++)
|
||||
{
|
||||
$retval[$i] = new stdClass();
|
||||
$retval[$i]->name = $query[$i]['name'];
|
||||
$retval[$i]->type = $query[$i]['type'];
|
||||
$retval[$i]->max_length = NULL;
|
||||
$retval[$i]->default = $query[$i]['dflt_value'];
|
||||
$retval[$i]->primary_key = isset($query[$i]['pk']) ? (int) $query[$i]['pk'] : 0;
|
||||
}
|
||||
|
||||
return $retval;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Error
|
||||
*
|
||||
* Returns an array containing code and message of the last
|
||||
* database error that has occured.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function error()
|
||||
{
|
||||
$error = array('code' => sqlite_last_error($this->conn_id));
|
||||
$error['message'] = sqlite_error_string($error['code']);
|
||||
return $error;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Replace statement
|
||||
*
|
||||
* Generates a platform-specific replace string from the supplied data
|
||||
*
|
||||
* @param string $table Table name
|
||||
* @param array $keys INSERT keys
|
||||
* @param array $values INSERT values
|
||||
* @return string
|
||||
*/
|
||||
protected function _replace($table, $keys, $values)
|
||||
{
|
||||
return 'INSERT OR '.parent::_replace($table, $keys, $values);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Truncate statement
|
||||
*
|
||||
* Generates a platform-specific truncate string from the supplied data
|
||||
*
|
||||
* If the database does not support the TRUNCATE statement,
|
||||
* then this function maps to 'DELETE FROM table'
|
||||
*
|
||||
* @param string $table
|
||||
* @return string
|
||||
*/
|
||||
protected function _truncate($table)
|
||||
{
|
||||
return 'DELETE FROM '.$table;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Close DB Connection
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _close()
|
||||
{
|
||||
sqlite_close($this->conn_id);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,202 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2015 TechFuze
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 1.0.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* SQLite Forge Class
|
||||
*
|
||||
* Converted from CodeIgniter.
|
||||
*
|
||||
* @package FuzeWorks
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
*/
|
||||
class FW_DB_sqlite_forge extends FW_DB_forge {
|
||||
|
||||
/**
|
||||
* CREATE TABLE IF statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_create_table_if = FALSE;
|
||||
|
||||
/**
|
||||
* UNSIGNED support
|
||||
*
|
||||
* @var bool|array
|
||||
*/
|
||||
protected $_unsigned = FALSE;
|
||||
|
||||
/**
|
||||
* NULL value representation in CREATE/ALTER TABLE statements
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_null = 'NULL';
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Create database
|
||||
*
|
||||
* @param string $db_name (ignored)
|
||||
* @return bool
|
||||
*/
|
||||
public function create_database($db_name = '')
|
||||
{
|
||||
// In SQLite, a database is created when you connect to the database.
|
||||
// We'll return TRUE so that an error isn't generated
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Drop database
|
||||
*
|
||||
* @param string $db_name (ignored)
|
||||
* @return bool
|
||||
*/
|
||||
public function drop_database($db_name = '')
|
||||
{
|
||||
if ( ! file_exists($this->db->database) OR ! @unlink($this->db->database))
|
||||
{
|
||||
return ($this->db->db_debug) ? $this->db->display_error('db_unable_to_drop') : FALSE;
|
||||
}
|
||||
elseif ( ! empty($this->db->data_cache['db_names']))
|
||||
{
|
||||
$key = array_search(strtolower($this->db->database), array_map('strtolower', $this->db->data_cache['db_names']), TRUE);
|
||||
if ($key !== FALSE)
|
||||
{
|
||||
unset($this->db->data_cache['db_names'][$key]);
|
||||
}
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* ALTER TABLE
|
||||
*
|
||||
* @todo implement drop_column(), modify_column()
|
||||
* @param string $alter_type ALTER type
|
||||
* @param string $table Table name
|
||||
* @param mixed $field Column definition
|
||||
* @return string|string[]
|
||||
*/
|
||||
protected function _alter_table($alter_type, $table, $field)
|
||||
{
|
||||
if ($alter_type === 'DROP' OR $alter_type === 'CHANGE')
|
||||
{
|
||||
// drop_column():
|
||||
// BEGIN TRANSACTION;
|
||||
// CREATE TEMPORARY TABLE t1_backup(a,b);
|
||||
// INSERT INTO t1_backup SELECT a,b FROM t1;
|
||||
// DROP TABLE t1;
|
||||
// CREATE TABLE t1(a,b);
|
||||
// INSERT INTO t1 SELECT a,b FROM t1_backup;
|
||||
// DROP TABLE t1_backup;
|
||||
// COMMIT;
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return parent::_alter_table($alter_type, $table, $field);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Process column
|
||||
*
|
||||
* @param array $field
|
||||
* @return string
|
||||
*/
|
||||
protected function _process_column($field)
|
||||
{
|
||||
return $this->db->escape_identifiers($field['name'])
|
||||
.' '.$field['type']
|
||||
.$field['auto_increment']
|
||||
.$field['null']
|
||||
.$field['unique']
|
||||
.$field['default'];
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Field attribute TYPE
|
||||
*
|
||||
* Performs a data type mapping between different databases.
|
||||
*
|
||||
* @param array &$attributes
|
||||
* @return void
|
||||
*/
|
||||
protected function _attr_type(&$attributes)
|
||||
{
|
||||
switch (strtoupper($attributes['TYPE']))
|
||||
{
|
||||
case 'ENUM':
|
||||
case 'SET':
|
||||
$attributes['TYPE'] = 'TEXT';
|
||||
return;
|
||||
default: return;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Field attribute AUTO_INCREMENT
|
||||
*
|
||||
* @param array &$attributes
|
||||
* @param array &$field
|
||||
* @return void
|
||||
*/
|
||||
protected function _attr_auto_increment(&$attributes, &$field)
|
||||
{
|
||||
if ( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE && stripos($field['type'], 'int') !== FALSE)
|
||||
{
|
||||
$field['type'] = 'INTEGER PRIMARY KEY';
|
||||
$field['default'] = '';
|
||||
$field['null'] = '';
|
||||
$field['unique'] = '';
|
||||
$field['auto_increment'] = ' AUTOINCREMENT';
|
||||
|
||||
$this->primary_keys = array();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,161 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2015 TechFuze
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 1.0.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* SQLite Result Class
|
||||
*
|
||||
* This class extends the parent result class: FW_DB_result
|
||||
*
|
||||
* Converted from CodeIgniter.
|
||||
*
|
||||
* @package FuzeWorks
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
*/
|
||||
class FW_DB_sqlite_result extends FW_DB_result {
|
||||
|
||||
/**
|
||||
* Number of rows in the result set
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function num_rows()
|
||||
{
|
||||
return is_int($this->num_rows)
|
||||
? $this->num_rows
|
||||
: $this->num_rows = @sqlite_num_rows($this->result_id);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Number of fields in the result set
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function num_fields()
|
||||
{
|
||||
return @sqlite_num_fields($this->result_id);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Fetch Field Names
|
||||
*
|
||||
* Generates an array of column names
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function list_fields()
|
||||
{
|
||||
$field_names = array();
|
||||
for ($i = 0, $c = $this->num_fields(); $i < $c; $i++)
|
||||
{
|
||||
$field_names[$i] = sqlite_field_name($this->result_id, $i);
|
||||
}
|
||||
|
||||
return $field_names;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Field data
|
||||
*
|
||||
* Generates an array of objects containing field meta-data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function field_data()
|
||||
{
|
||||
$retval = array();
|
||||
for ($i = 0, $c = $this->num_fields(); $i < $c; $i++)
|
||||
{
|
||||
$retval[$i] = new stdClass();
|
||||
$retval[$i]->name = sqlite_field_name($this->result_id, $i);
|
||||
$retval[$i]->type = NULL;
|
||||
$retval[$i]->max_length = NULL;
|
||||
}
|
||||
|
||||
return $retval;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Data Seek
|
||||
*
|
||||
* Moves the internal pointer to the desired offset. We call
|
||||
* this internally before fetching results to make sure the
|
||||
* result set starts at zero.
|
||||
*
|
||||
* @param int $n
|
||||
* @return bool
|
||||
*/
|
||||
public function data_seek($n = 0)
|
||||
{
|
||||
return sqlite_seek($this->result_id, $n);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Result - associative array
|
||||
*
|
||||
* Returns the result set as an array
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function _fetch_assoc()
|
||||
{
|
||||
return sqlite_fetch_array($this->result_id);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Result - object
|
||||
*
|
||||
* Returns the result set as an object
|
||||
*
|
||||
* @param string $class_name
|
||||
* @return object
|
||||
*/
|
||||
protected function _fetch_object($class_name = 'stdClass')
|
||||
{
|
||||
return sqlite_fetch_object($this->result_id, $class_name);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,58 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2015 TechFuze
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 1.0.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* SQLite Utility Class
|
||||
*
|
||||
* Converted from CodeIgniter.
|
||||
*
|
||||
* @package FuzeWorks
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
*/
|
||||
class FW_DB_sqlite_utility extends FW_DB_utility {
|
||||
|
||||
/**
|
||||
* Export
|
||||
*
|
||||
* @param array $params Preferences
|
||||
* @return mixed
|
||||
*/
|
||||
protected function _backup($params = array())
|
||||
{
|
||||
// Currently unsupported
|
||||
return $this->db->display_error('db_unsupported_feature');
|
||||
}
|
||||
|
||||
}
|
|
@ -1,349 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2015 TechFuze
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 1.0.0
|
||||
*/
|
||||
|
||||
use FuzeWorks\Logger;
|
||||
use \Exception;
|
||||
|
||||
/**
|
||||
* SQLite3 Database Adapter Class
|
||||
*
|
||||
* Note: _DB is an extender class that the app controller
|
||||
* creates dynamically based on whether the query builder
|
||||
* class is being used or not.
|
||||
*
|
||||
* Converted from CodeIgniter.
|
||||
*
|
||||
* @package FuzeWorks
|
||||
* @subpackage Drivers
|
||||
* @category Database
|
||||
* @author Andrey Andreev
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
*/
|
||||
class FW_DB_sqlite3_driver extends FW_DB {
|
||||
|
||||
/**
|
||||
* Database driver
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $dbdriver = 'sqlite3';
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* ORDER BY random keyword
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_random_keyword = array('RANDOM()', 'RANDOM()');
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Non-persistent database connection
|
||||
*
|
||||
* @param bool $persistent
|
||||
* @return SQLite3
|
||||
*/
|
||||
public function db_connect($persistent = FALSE)
|
||||
{
|
||||
if ($persistent)
|
||||
{
|
||||
Logger::logDebug('SQLite3 doesn\'t support persistent connections');
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
return ( ! $this->password)
|
||||
? new SQLite3($this->database)
|
||||
: new SQLite3($this->database, SQLITE3_OPEN_READWRITE | SQLITE3_OPEN_CREATE, $this->password);
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Database version number
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function version()
|
||||
{
|
||||
if (isset($this->data_cache['version']))
|
||||
{
|
||||
return $this->data_cache['version'];
|
||||
}
|
||||
|
||||
$version = SQLite3::version();
|
||||
return $this->data_cache['version'] = $version['versionString'];
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Execute the query
|
||||
*
|
||||
* @todo Implement use of SQLite3::querySingle(), if needed
|
||||
* @param string $sql
|
||||
* @return mixed SQLite3Result object or bool
|
||||
*/
|
||||
protected function _execute($sql)
|
||||
{
|
||||
return $this->is_write_type($sql)
|
||||
? $this->conn_id->exec($sql)
|
||||
: $this->conn_id->query($sql);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Begin Transaction
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function _trans_begin()
|
||||
{
|
||||
return $this->conn_id->exec('BEGIN TRANSACTION');
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Commit Transaction
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function _trans_commit()
|
||||
{
|
||||
return $this->conn_id->exec('END TRANSACTION');
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Rollback Transaction
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function _trans_rollback()
|
||||
{
|
||||
return $this->conn_id->exec('ROLLBACK');
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Platform-dependant string escape
|
||||
*
|
||||
* @param string
|
||||
* @return string
|
||||
*/
|
||||
protected function _escape_str($str)
|
||||
{
|
||||
return $this->conn_id->escapeString($str);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Affected Rows
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function affected_rows()
|
||||
{
|
||||
return $this->conn_id->changes();
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Insert ID
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function insert_id()
|
||||
{
|
||||
return $this->conn_id->lastInsertRowID();
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Show table query
|
||||
*
|
||||
* Generates a platform-specific query string so that the table names can be fetched
|
||||
*
|
||||
* @param bool $prefix_limit
|
||||
* @return string
|
||||
*/
|
||||
protected function _list_tables($prefix_limit = FALSE)
|
||||
{
|
||||
return 'SELECT "NAME" FROM "SQLITE_MASTER" WHERE "TYPE" = \'table\''
|
||||
.(($prefix_limit !== FALSE && $this->dbprefix != '')
|
||||
? ' AND "NAME" LIKE \''.$this->escape_like_str($this->dbprefix).'%\' '.sprintf($this->_like_escape_str, $this->_like_escape_chr)
|
||||
: '');
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Fetch Field Names
|
||||
*
|
||||
* @param string $table Table name
|
||||
* @return array
|
||||
*/
|
||||
public function list_fields($table)
|
||||
{
|
||||
// Is there a cached result?
|
||||
if (isset($this->data_cache['field_names'][$table]))
|
||||
{
|
||||
return $this->data_cache['field_names'][$table];
|
||||
}
|
||||
|
||||
if (($result = $this->query('PRAGMA TABLE_INFO('.$this->protect_identifiers($table, TRUE, NULL, FALSE).')')) === FALSE)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$this->data_cache['field_names'][$table] = array();
|
||||
foreach ($result->result_array() as $row)
|
||||
{
|
||||
$this->data_cache['field_names'][$table][] = $row['name'];
|
||||
}
|
||||
|
||||
return $this->data_cache['field_names'][$table];
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Returns an object with field data
|
||||
*
|
||||
* @param string $table
|
||||
* @return array
|
||||
*/
|
||||
public function field_data($table)
|
||||
{
|
||||
if (($query = $this->query('PRAGMA TABLE_INFO('.$this->protect_identifiers($table, TRUE, NULL, FALSE).')')) === FALSE)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$query = $query->result_array();
|
||||
if (empty($query))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$retval = array();
|
||||
for ($i = 0, $c = count($query); $i < $c; $i++)
|
||||
{
|
||||
$retval[$i] = new stdClass();
|
||||
$retval[$i]->name = $query[$i]['name'];
|
||||
$retval[$i]->type = $query[$i]['type'];
|
||||
$retval[$i]->max_length = NULL;
|
||||
$retval[$i]->default = $query[$i]['dflt_value'];
|
||||
$retval[$i]->primary_key = isset($query[$i]['pk']) ? (int) $query[$i]['pk'] : 0;
|
||||
}
|
||||
|
||||
return $retval;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Error
|
||||
*
|
||||
* Returns an array containing code and message of the last
|
||||
* database error that has occured.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function error()
|
||||
{
|
||||
return array('code' => $this->conn_id->lastErrorCode(), 'message' => $this->conn_id->lastErrorMsg());
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Replace statement
|
||||
*
|
||||
* Generates a platform-specific replace string from the supplied data
|
||||
*
|
||||
* @param string $table Table name
|
||||
* @param array $keys INSERT keys
|
||||
* @param array $values INSERT values
|
||||
* @return string
|
||||
*/
|
||||
protected function _replace($table, $keys, $values)
|
||||
{
|
||||
return 'INSERT OR '.parent::_replace($table, $keys, $values);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Truncate statement
|
||||
*
|
||||
* Generates a platform-specific truncate string from the supplied data
|
||||
*
|
||||
* If the database does not support the TRUNCATE statement,
|
||||
* then this method maps to 'DELETE FROM table'
|
||||
*
|
||||
* @param string $table
|
||||
* @return string
|
||||
*/
|
||||
protected function _truncate($table)
|
||||
{
|
||||
return 'DELETE FROM '.$table;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Close DB Connection
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _close()
|
||||
{
|
||||
$this->conn_id->close();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,222 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2015 TechFuze
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 1.0.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* SQLite3 Forge Class
|
||||
*
|
||||
* Converted from CodeIgniter.
|
||||
*
|
||||
* @package FuzeWorks
|
||||
* @category Database
|
||||
* @author Andrey Andreev
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
*/
|
||||
class FW_DB_sqlite3_forge extends FW_DB_forge {
|
||||
|
||||
/**
|
||||
* UNSIGNED support
|
||||
*
|
||||
* @var bool|array
|
||||
*/
|
||||
protected $_unsigned = FALSE;
|
||||
|
||||
/**
|
||||
* NULL value representation in CREATE/ALTER TABLE statements
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_null = 'NULL';
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param object &$db Database object
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(&$db)
|
||||
{
|
||||
parent::__construct($db);
|
||||
|
||||
if (version_compare($this->db->version(), '3.3', '<'))
|
||||
{
|
||||
$this->_create_table_if = FALSE;
|
||||
$this->_drop_table_if = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Create database
|
||||
*
|
||||
* @param string $db_name
|
||||
* @return bool
|
||||
*/
|
||||
public function create_database($db_name = '')
|
||||
{
|
||||
// In SQLite, a database is created when you connect to the database.
|
||||
// We'll return TRUE so that an error isn't generated
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Drop database
|
||||
*
|
||||
* @param string $db_name (ignored)
|
||||
* @return bool
|
||||
*/
|
||||
public function drop_database($db_name = '')
|
||||
{
|
||||
// In SQLite, a database is dropped when we delete a file
|
||||
if (file_exists($this->db->database))
|
||||
{
|
||||
// We need to close the pseudo-connection first
|
||||
$this->db->close();
|
||||
if ( ! @unlink($this->db->database))
|
||||
{
|
||||
return $this->db->db_debug ? $this->db->display_error('db_unable_to_drop') : FALSE;
|
||||
}
|
||||
elseif ( ! empty($this->db->data_cache['db_names']))
|
||||
{
|
||||
$key = array_search(strtolower($this->db->database), array_map('strtolower', $this->db->data_cache['db_names']), TRUE);
|
||||
if ($key !== FALSE)
|
||||
{
|
||||
unset($this->db->data_cache['db_names'][$key]);
|
||||
}
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return $this->db->db_debug ? $this->db->display_error('db_unable_to_drop') : FALSE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* ALTER TABLE
|
||||
*
|
||||
* @todo implement drop_column(), modify_column()
|
||||
* @param string $alter_type ALTER type
|
||||
* @param string $table Table name
|
||||
* @param mixed $field Column definition
|
||||
* @return string|string[]
|
||||
*/
|
||||
protected function _alter_table($alter_type, $table, $field)
|
||||
{
|
||||
if ($alter_type === 'DROP' OR $alter_type === 'CHANGE')
|
||||
{
|
||||
// drop_column():
|
||||
// BEGIN TRANSACTION;
|
||||
// CREATE TEMPORARY TABLE t1_backup(a,b);
|
||||
// INSERT INTO t1_backup SELECT a,b FROM t1;
|
||||
// DROP TABLE t1;
|
||||
// CREATE TABLE t1(a,b);
|
||||
// INSERT INTO t1 SELECT a,b FROM t1_backup;
|
||||
// DROP TABLE t1_backup;
|
||||
// COMMIT;
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return parent::_alter_table($alter_type, $table, $field);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Process column
|
||||
*
|
||||
* @param array $field
|
||||
* @return string
|
||||
*/
|
||||
protected function _process_column($field)
|
||||
{
|
||||
return $this->db->escape_identifiers($field['name'])
|
||||
.' '.$field['type']
|
||||
.$field['auto_increment']
|
||||
.$field['null']
|
||||
.$field['unique']
|
||||
.$field['default'];
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Field attribute TYPE
|
||||
*
|
||||
* Performs a data type mapping between different databases.
|
||||
*
|
||||
* @param array &$attributes
|
||||
* @return void
|
||||
*/
|
||||
protected function _attr_type(&$attributes)
|
||||
{
|
||||
switch (strtoupper($attributes['TYPE']))
|
||||
{
|
||||
case 'ENUM':
|
||||
case 'SET':
|
||||
$attributes['TYPE'] = 'TEXT';
|
||||
return;
|
||||
default: return;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Field attribute AUTO_INCREMENT
|
||||
*
|
||||
* @param array &$attributes
|
||||
* @param array &$field
|
||||
* @return void
|
||||
*/
|
||||
protected function _attr_auto_increment(&$attributes, &$field)
|
||||
{
|
||||
if ( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE && stripos($field['type'], 'int') !== FALSE)
|
||||
{
|
||||
$field['type'] = 'INTEGER PRIMARY KEY';
|
||||
$field['default'] = '';
|
||||
$field['null'] = '';
|
||||
$field['unique'] = '';
|
||||
$field['auto_increment'] = ' AUTOINCREMENT';
|
||||
|
||||
$this->primary_keys = array();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,191 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2015 TechFuze
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 1.0.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* SQLite3 Result Class
|
||||
*
|
||||
* This class extends the parent result class: FW_DB_result
|
||||
*
|
||||
* Converted from CodeIgniter.
|
||||
*
|
||||
* @package FuzeWorks
|
||||
* @category Database
|
||||
* @author Andrey Andreev
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
*/
|
||||
class FW_DB_sqlite3_result extends FW_DB_result {
|
||||
|
||||
/**
|
||||
* Number of fields in the result set
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function num_fields()
|
||||
{
|
||||
return $this->result_id->numColumns();
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Fetch Field Names
|
||||
*
|
||||
* Generates an array of column names
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function list_fields()
|
||||
{
|
||||
$field_names = array();
|
||||
for ($i = 0, $c = $this->num_fields(); $i < $c; $i++)
|
||||
{
|
||||
$field_names[] = $this->result_id->columnName($i);
|
||||
}
|
||||
|
||||
return $field_names;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Field data
|
||||
*
|
||||
* Generates an array of objects containing field meta-data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function field_data()
|
||||
{
|
||||
static $data_types = array(
|
||||
SQLITE3_INTEGER => 'integer',
|
||||
SQLITE3_FLOAT => 'float',
|
||||
SQLITE3_TEXT => 'text',
|
||||
SQLITE3_BLOB => 'blob',
|
||||
SQLITE3_NULL => 'null'
|
||||
);
|
||||
|
||||
$retval = array();
|
||||
for ($i = 0, $c = $this->num_fields(); $i < $c; $i++)
|
||||
{
|
||||
$retval[$i] = new stdClass();
|
||||
$retval[$i]->name = $this->result_id->columnName($i);
|
||||
|
||||
$type = $this->result_id->columnType($i);
|
||||
$retval[$i]->type = isset($data_types[$type]) ? $data_types[$type] : $type;
|
||||
|
||||
$retval[$i]->max_length = NULL;
|
||||
}
|
||||
|
||||
return $retval;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Free the result
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function free_result()
|
||||
{
|
||||
if (is_object($this->result_id))
|
||||
{
|
||||
$this->result_id->finalize();
|
||||
$this->result_id = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Result - associative array
|
||||
*
|
||||
* Returns the result set as an array
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function _fetch_assoc()
|
||||
{
|
||||
return $this->result_id->fetchArray(SQLITE3_ASSOC);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Result - object
|
||||
*
|
||||
* Returns the result set as an object
|
||||
*
|
||||
* @param string $class_name
|
||||
* @return object
|
||||
*/
|
||||
protected function _fetch_object($class_name = 'stdClass')
|
||||
{
|
||||
// No native support for fetching rows as objects
|
||||
if (($row = $this->result_id->fetchArray(SQLITE3_ASSOC)) === FALSE)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
elseif ($class_name === 'stdClass')
|
||||
{
|
||||
return (object) $row;
|
||||
}
|
||||
|
||||
$class_name = new $class_name();
|
||||
foreach (array_keys($row) as $key)
|
||||
{
|
||||
$class_name->$key = $row[$key];
|
||||
}
|
||||
|
||||
return $class_name;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Data Seek
|
||||
*
|
||||
* Moves the internal pointer to the desired offset. We call
|
||||
* this internally before fetching results to make sure the
|
||||
* result set starts at zero.
|
||||
*
|
||||
* @param int $n (ignored)
|
||||
* @return array
|
||||
*/
|
||||
public function data_seek($n = 0)
|
||||
{
|
||||
// Only resetting to the start of the result set is supported
|
||||
return ($n > 0) ? FALSE : $this->result_id->reset();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,58 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2015 TechFuze
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 1.0.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* SQLite3 Utility Class
|
||||
*
|
||||
* Converted from CodeIgniter.
|
||||
*
|
||||
* @package FuzeWorks
|
||||
* @category Database
|
||||
* @author Andrey Andreev
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
*/
|
||||
class FW_DB_sqlite3_utility extends FW_DB_utility {
|
||||
|
||||
/**
|
||||
* Export
|
||||
*
|
||||
* @param array $params Preferences
|
||||
* @return mixed
|
||||
*/
|
||||
protected function _backup($params = array())
|
||||
{
|
||||
// Not supported
|
||||
return $this->db->display_error('db_unsupported_feature');
|
||||
}
|
||||
|
||||
}
|
|
@ -1,538 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2015 TechFuze
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 1.0.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* SQLSRV Database Adapter Class
|
||||
*
|
||||
* Note: _DB is an extender class that the app controller
|
||||
* creates dynamically based on whether the query builder
|
||||
* class is being used or not.
|
||||
*
|
||||
* Converted from CodeIgniter.
|
||||
*
|
||||
* @package FuzeWorks
|
||||
* @subpackage Drivers
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
*/
|
||||
class FW_DB_sqlsrv_driver extends FW_DB {
|
||||
|
||||
/**
|
||||
* Database driver
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $dbdriver = 'sqlsrv';
|
||||
|
||||
/**
|
||||
* Scrollable flag
|
||||
*
|
||||
* Determines what cursor type to use when executing queries.
|
||||
*
|
||||
* FALSE or SQLSRV_CURSOR_FORWARD would increase performance,
|
||||
* but would disable num_rows() (and possibly insert_id())
|
||||
*
|
||||
* @var mixed
|
||||
*/
|
||||
public $scrollable;
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* ORDER BY random keyword
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_random_keyword = array('NEWID()', 'RAND(%d)');
|
||||
|
||||
/**
|
||||
* Quoted identifier flag
|
||||
*
|
||||
* Whether to use SQL-92 standard quoted identifier
|
||||
* (double quotes) or brackets for identifier escaping.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $_quoted_identifier = TRUE;
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param array $params
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($params)
|
||||
{
|
||||
parent::__construct($params);
|
||||
|
||||
// This is only supported as of SQLSRV 3.0
|
||||
if ($this->scrollable === NULL)
|
||||
{
|
||||
$this->scrollable = defined('SQLSRV_CURSOR_CLIENT_BUFFERED')
|
||||
? SQLSRV_CURSOR_CLIENT_BUFFERED
|
||||
: FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Database connection
|
||||
*
|
||||
* @param bool $pooling
|
||||
* @return resource
|
||||
*/
|
||||
public function db_connect($pooling = FALSE)
|
||||
{
|
||||
$charset = in_array(strtolower($this->char_set), array('utf-8', 'utf8'), TRUE)
|
||||
? 'UTF-8' : SQLSRV_ENC_CHAR;
|
||||
|
||||
$connection = array(
|
||||
'UID' => empty($this->username) ? '' : $this->username,
|
||||
'PWD' => empty($this->password) ? '' : $this->password,
|
||||
'Database' => $this->database,
|
||||
'ConnectionPooling' => ($pooling === TRUE) ? 1 : 0,
|
||||
'CharacterSet' => $charset,
|
||||
'Encrypt' => ($this->encrypt === TRUE) ? 1 : 0,
|
||||
'ReturnDatesAsStrings' => 1
|
||||
);
|
||||
|
||||
// If the username and password are both empty, assume this is a
|
||||
// 'Windows Authentication Mode' connection.
|
||||
if (empty($connection['UID']) && empty($connection['PWD']))
|
||||
{
|
||||
unset($connection['UID'], $connection['PWD']);
|
||||
}
|
||||
|
||||
if (FALSE !== ($this->conn_id = sqlsrv_connect($this->hostname, $connection)))
|
||||
{
|
||||
// Determine how identifiers are escaped
|
||||
$query = $this->query('SELECT CASE WHEN (@@OPTIONS | 256) = @@OPTIONS THEN 1 ELSE 0 END AS qi');
|
||||
$query = $query->row_array();
|
||||
$this->_quoted_identifier = empty($query) ? FALSE : (bool) $query['qi'];
|
||||
$this->_escape_char = ($this->_quoted_identifier) ? '"' : array('[', ']');
|
||||
}
|
||||
|
||||
return $this->conn_id;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Select the database
|
||||
*
|
||||
* @param string $database
|
||||
* @return bool
|
||||
*/
|
||||
public function db_select($database = '')
|
||||
{
|
||||
if ($database === '')
|
||||
{
|
||||
$database = $this->database;
|
||||
}
|
||||
|
||||
if ($this->_execute('USE '.$this->escape_identifiers($database)))
|
||||
{
|
||||
$this->database = $database;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Execute the query
|
||||
*
|
||||
* @param string $sql an SQL query
|
||||
* @return resource
|
||||
*/
|
||||
protected function _execute($sql)
|
||||
{
|
||||
return ($this->scrollable === FALSE OR $this->is_write_type($sql))
|
||||
? sqlsrv_query($this->conn_id, $sql)
|
||||
: sqlsrv_query($this->conn_id, $sql, NULL, array('Scrollable' => $this->scrollable));
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Begin Transaction
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function _trans_begin()
|
||||
{
|
||||
return sqlsrv_begin_transaction($this->conn_id);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Commit Transaction
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function _trans_commit()
|
||||
{
|
||||
return sqlsrv_commit($this->conn_id);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Rollback Transaction
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function _trans_rollback()
|
||||
{
|
||||
return sqlsrv_rollback($this->conn_id);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Affected Rows
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function affected_rows()
|
||||
{
|
||||
return sqlsrv_rows_affected($this->result_id);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Insert ID
|
||||
*
|
||||
* Returns the last id created in the Identity column.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function insert_id()
|
||||
{
|
||||
return $this->query('SELECT SCOPE_IDENTITY() AS insert_id')->row()->insert_id;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Database version number
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function version()
|
||||
{
|
||||
if (isset($this->data_cache['version']))
|
||||
{
|
||||
return $this->data_cache['version'];
|
||||
}
|
||||
|
||||
if ( ! $this->conn_id OR ($info = sqlsrv_server_info($this->conn_id)) === FALSE)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return $this->data_cache['version'] = $info['SQLServerVersion'];
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* List table query
|
||||
*
|
||||
* Generates a platform-specific query string so that the table names can be fetched
|
||||
*
|
||||
* @param bool
|
||||
* @return string $prefix_limit
|
||||
*/
|
||||
protected function _list_tables($prefix_limit = FALSE)
|
||||
{
|
||||
$sql = 'SELECT '.$this->escape_identifiers('name')
|
||||
.' FROM '.$this->escape_identifiers('sysobjects')
|
||||
.' WHERE '.$this->escape_identifiers('type')." = 'U'";
|
||||
|
||||
if ($prefix_limit === TRUE && $this->dbprefix !== '')
|
||||
{
|
||||
$sql .= ' AND '.$this->escape_identifiers('name')." LIKE '".$this->escape_like_str($this->dbprefix)."%' "
|
||||
.sprintf($this->_escape_like_str, $this->_escape_like_chr);
|
||||
}
|
||||
|
||||
return $sql.' ORDER BY '.$this->escape_identifiers('name');
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* List column query
|
||||
*
|
||||
* Generates a platform-specific query string so that the column names can be fetched
|
||||
*
|
||||
* @param string $table
|
||||
* @return string
|
||||
*/
|
||||
protected function _list_columns($table = '')
|
||||
{
|
||||
return 'SELECT COLUMN_NAME
|
||||
FROM INFORMATION_SCHEMA.Columns
|
||||
WHERE UPPER(TABLE_NAME) = '.$this->escape(strtoupper($table));
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Returns an object with field data
|
||||
*
|
||||
* @param string $table
|
||||
* @return array
|
||||
*/
|
||||
public function field_data($table)
|
||||
{
|
||||
$sql = 'SELECT COLUMN_NAME, DATA_TYPE, CHARACTER_MAXIMUM_LENGTH, NUMERIC_PRECISION, COLUMN_DEFAULT
|
||||
FROM INFORMATION_SCHEMA.Columns
|
||||
WHERE UPPER(TABLE_NAME) = '.$this->escape(strtoupper($table));
|
||||
|
||||
if (($query = $this->query($sql)) === FALSE)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
$query = $query->result_object();
|
||||
|
||||
$retval = array();
|
||||
for ($i = 0, $c = count($query); $i < $c; $i++)
|
||||
{
|
||||
$retval[$i] = new stdClass();
|
||||
$retval[$i]->name = $query[$i]->COLUMN_NAME;
|
||||
$retval[$i]->type = $query[$i]->DATA_TYPE;
|
||||
$retval[$i]->max_length = ($query[$i]->CHARACTER_MAXIMUM_LENGTH > 0) ? $query[$i]->CHARACTER_MAXIMUM_LENGTH : $query[$i]->NUMERIC_PRECISION;
|
||||
$retval[$i]->default = $query[$i]->COLUMN_DEFAULT;
|
||||
}
|
||||
|
||||
return $retval;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Error
|
||||
*
|
||||
* Returns an array containing code and message of the last
|
||||
* database error that has occured.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function error()
|
||||
{
|
||||
$error = array('code' => '00000', 'message' => '');
|
||||
$sqlsrv_errors = sqlsrv_errors(SQLSRV_ERR_ERRORS);
|
||||
|
||||
if ( ! is_array($sqlsrv_errors))
|
||||
{
|
||||
return $error;
|
||||
}
|
||||
|
||||
$sqlsrv_error = array_shift($sqlsrv_errors);
|
||||
if (isset($sqlsrv_error['SQLSTATE']))
|
||||
{
|
||||
$error['code'] = isset($sqlsrv_error['code']) ? $sqlsrv_error['SQLSTATE'].'/'.$sqlsrv_error['code'] : $sqlsrv_error['SQLSTATE'];
|
||||
}
|
||||
elseif (isset($sqlsrv_error['code']))
|
||||
{
|
||||
$error['code'] = $sqlsrv_error['code'];
|
||||
}
|
||||
|
||||
if (isset($sqlsrv_error['message']))
|
||||
{
|
||||
$error['message'] = $sqlsrv_error['message'];
|
||||
}
|
||||
|
||||
return $error;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Update statement
|
||||
*
|
||||
* Generates a platform-specific update string from the supplied data
|
||||
*
|
||||
* @param string $table
|
||||
* @param array $values
|
||||
* @return string
|
||||
*/
|
||||
protected function _update($table, $values)
|
||||
{
|
||||
$this->qb_limit = FALSE;
|
||||
$this->qb_orderby = array();
|
||||
return parent::_update($table, $values);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Truncate statement
|
||||
*
|
||||
* Generates a platform-specific truncate string from the supplied data
|
||||
*
|
||||
* If the database does not support the TRUNCATE statement,
|
||||
* then this method maps to 'DELETE FROM table'
|
||||
*
|
||||
* @param string $table
|
||||
* @return string
|
||||
*/
|
||||
protected function _truncate($table)
|
||||
{
|
||||
return 'TRUNCATE TABLE '.$table;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Delete statement
|
||||
*
|
||||
* Generates a platform-specific delete string from the supplied data
|
||||
*
|
||||
* @param string $table
|
||||
* @return string
|
||||
*/
|
||||
protected function _delete($table)
|
||||
{
|
||||
if ($this->qb_limit)
|
||||
{
|
||||
return 'WITH fw_delete AS (SELECT TOP '.$this->qb_limit.' * FROM '.$table.$this->_compile_wh('qb_where').') DELETE FROM fw_delete';
|
||||
}
|
||||
|
||||
return parent::_delete($table);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* LIMIT
|
||||
*
|
||||
* Generates a platform-specific LIMIT clause
|
||||
*
|
||||
* @param string $sql SQL Query
|
||||
* @return string
|
||||
*/
|
||||
protected function _limit($sql)
|
||||
{
|
||||
// As of SQL Server 2012 (11.0.*) OFFSET is supported
|
||||
if (version_compare($this->version(), '11', '>='))
|
||||
{
|
||||
// SQL Server OFFSET-FETCH can be used only with the ORDER BY clause
|
||||
empty($this->qb_orderby) && $sql .= ' ORDER BY 1';
|
||||
|
||||
return $sql.' OFFSET '.(int) $this->qb_offset.' ROWS FETCH NEXT '.$this->qb_limit.' ROWS ONLY';
|
||||
}
|
||||
|
||||
$limit = $this->qb_offset + $this->qb_limit;
|
||||
|
||||
// An ORDER BY clause is required for ROW_NUMBER() to work
|
||||
if ($this->qb_offset && ! empty($this->qb_orderby))
|
||||
{
|
||||
$orderby = $this->_compile_order_by();
|
||||
|
||||
// We have to strip the ORDER BY clause
|
||||
$sql = trim(substr($sql, 0, strrpos($sql, $orderby)));
|
||||
|
||||
// Get the fields to select from our subquery, so that we can avoid FW_rownum appearing in the actual results
|
||||
if (count($this->qb_select) === 0)
|
||||
{
|
||||
$select = '*'; // Inevitable
|
||||
}
|
||||
else
|
||||
{
|
||||
// Use only field names and their aliases, everything else is out of our scope.
|
||||
$select = array();
|
||||
$field_regexp = ($this->_quoted_identifier)
|
||||
? '("[^\"]+")' : '(\[[^\]]+\])';
|
||||
for ($i = 0, $c = count($this->qb_select); $i < $c; $i++)
|
||||
{
|
||||
$select[] = preg_match('/(?:\s|\.)'.$field_regexp.'$/i', $this->qb_select[$i], $m)
|
||||
? $m[1] : $this->qb_select[$i];
|
||||
}
|
||||
$select = implode(', ', $select);
|
||||
}
|
||||
|
||||
return 'SELECT '.$select." FROM (\n\n"
|
||||
.preg_replace('/^(SELECT( DISTINCT)?)/i', '\\1 ROW_NUMBER() OVER('.trim($orderby).') AS '.$this->escape_identifiers('FW_rownum').', ', $sql)
|
||||
."\n\n) ".$this->escape_identifiers('FW_subquery')
|
||||
."\nWHERE ".$this->escape_identifiers('FW_rownum').' BETWEEN '.($this->qb_offset + 1).' AND '.$limit;
|
||||
}
|
||||
|
||||
return preg_replace('/(^\SELECT (DISTINCT)?)/i','\\1 TOP '.$limit.' ', $sql);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Insert batch statement
|
||||
*
|
||||
* Generates a platform-specific insert string from the supplied data.
|
||||
*
|
||||
* @param string $table Table name
|
||||
* @param array $keys INSERT keys
|
||||
* @param array $values INSERT values
|
||||
* @return string|bool
|
||||
*/
|
||||
protected function _insert_batch($table, $keys, $values)
|
||||
{
|
||||
// Multiple-value inserts are only supported as of SQL Server 2008
|
||||
if (version_compare($this->version(), '10', '>='))
|
||||
{
|
||||
return parent::_insert_batch($table, $keys, $values);
|
||||
}
|
||||
|
||||
return ($this->db->db_debug) ? $this->db->display_error('db_unsupported_feature') : FALSE;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Close DB Connection
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _close()
|
||||
{
|
||||
sqlsrv_close($this->conn_id);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,141 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2015 TechFuze
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 1.0.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* SQLSRV Forge Class
|
||||
*
|
||||
* Converted from CodeIgniter.
|
||||
*
|
||||
* @package FuzeWorks
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
*/
|
||||
class FW_DB_sqlsrv_forge extends FW_DB_forge {
|
||||
|
||||
/**
|
||||
* CREATE TABLE IF statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_create_table_if = "IF NOT EXISTS (SELECT * FROM sysobjects WHERE ID = object_id(N'%s') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)\nCREATE TABLE";
|
||||
|
||||
/**
|
||||
* DROP TABLE IF statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_drop_table_if = "IF EXISTS (SELECT * FROM sysobjects WHERE ID = object_id(N'%s') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)\nDROP TABLE";
|
||||
|
||||
/**
|
||||
* UNSIGNED support
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_unsigned = array(
|
||||
'TINYINT' => 'SMALLINT',
|
||||
'SMALLINT' => 'INT',
|
||||
'INT' => 'BIGINT',
|
||||
'REAL' => 'FLOAT'
|
||||
);
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* ALTER TABLE
|
||||
*
|
||||
* @param string $alter_type ALTER type
|
||||
* @param string $table Table name
|
||||
* @param mixed $field Column definition
|
||||
* @return string|string[]
|
||||
*/
|
||||
protected function _alter_table($alter_type, $table, $field)
|
||||
{
|
||||
if (in_array($alter_type, array('ADD', 'DROP'), TRUE))
|
||||
{
|
||||
return parent::_alter_table($alter_type, $table, $field);
|
||||
}
|
||||
|
||||
$sql = 'ALTER TABLE '.$this->db->escape_identifiers($table).' ALTER COLUMN ';
|
||||
$sqls = array();
|
||||
for ($i = 0, $c = count($field); $i < $c; $i++)
|
||||
{
|
||||
$sqls[] = $sql.$this->_process_column($field[$i]);
|
||||
}
|
||||
|
||||
return $sqls;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Field attribute TYPE
|
||||
*
|
||||
* Performs a data type mapping between different databases.
|
||||
*
|
||||
* @param array &$attributes
|
||||
* @return void
|
||||
*/
|
||||
protected function _attr_type(&$attributes)
|
||||
{
|
||||
switch (strtoupper($attributes['TYPE']))
|
||||
{
|
||||
case 'MEDIUMINT':
|
||||
$attributes['TYPE'] = 'INTEGER';
|
||||
$attributes['UNSIGNED'] = FALSE;
|
||||
return;
|
||||
case 'INTEGER':
|
||||
$attributes['TYPE'] = 'INT';
|
||||
return;
|
||||
default: return;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Field attribute AUTO_INCREMENT
|
||||
*
|
||||
* @param array &$attributes
|
||||
* @param array &$field
|
||||
* @return void
|
||||
*/
|
||||
protected function _attr_auto_increment(&$attributes, &$field)
|
||||
{
|
||||
if ( ! empty($attributes['AUTO_INCREMENT']) && $attributes['AUTO_INCREMENT'] === TRUE && stripos($field['type'], 'int') !== FALSE)
|
||||
{
|
||||
$field['auto_increment'] = ' IDENTITY(1,1)';
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,190 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2015 TechFuze
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 1.0.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* SQLSRV Result Class
|
||||
*
|
||||
* This class extends the parent result class: FW_DB_result
|
||||
*
|
||||
* Converted from CodeIgniter.
|
||||
*
|
||||
* @package FuzeWorks
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
*/
|
||||
class FW_DB_sqlsrv_result extends FW_DB_result {
|
||||
|
||||
/**
|
||||
* Scrollable flag
|
||||
*
|
||||
* @var mixed
|
||||
*/
|
||||
public $scrollable;
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param object $driver_object
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(&$driver_object)
|
||||
{
|
||||
parent::__construct($driver_object);
|
||||
|
||||
$this->scrollable = $driver_object->scrollable;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Number of rows in the result set
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function num_rows()
|
||||
{
|
||||
// sqlsrv_num_rows() doesn't work with the FORWARD and DYNAMIC cursors (FALSE is the same as FORWARD)
|
||||
if ( ! in_array($this->scrollable, array(FALSE, SQLSRV_CURSOR_FORWARD, SQLSRV_CURSOR_DYNAMIC), TRUE))
|
||||
{
|
||||
return parent::num_rows();
|
||||
}
|
||||
|
||||
return is_int($this->num_rows)
|
||||
? $this->num_rows
|
||||
: $this->num_rows = sqlsrv_num_rows($this->result_id);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Number of fields in the result set
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function num_fields()
|
||||
{
|
||||
return @sqlsrv_num_fields($this->result_id);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Fetch Field Names
|
||||
*
|
||||
* Generates an array of column names
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function list_fields()
|
||||
{
|
||||
$field_names = array();
|
||||
foreach (sqlsrv_field_metadata($this->result_id) as $offset => $field)
|
||||
{
|
||||
$field_names[] = $field['Name'];
|
||||
}
|
||||
|
||||
return $field_names;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Field data
|
||||
*
|
||||
* Generates an array of objects containing field meta-data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function field_data()
|
||||
{
|
||||
$retval = array();
|
||||
foreach (sqlsrv_field_metadata($this->result_id) as $i => $field)
|
||||
{
|
||||
$retval[$i] = new stdClass();
|
||||
$retval[$i]->name = $field['Name'];
|
||||
$retval[$i]->type = $field['Type'];
|
||||
$retval[$i]->max_length = $field['Size'];
|
||||
}
|
||||
|
||||
return $retval;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Free the result
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function free_result()
|
||||
{
|
||||
if (is_resource($this->result_id))
|
||||
{
|
||||
sqlsrv_free_stmt($this->result_id);
|
||||
$this->result_id = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Result - associative array
|
||||
*
|
||||
* Returns the result set as an array
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function _fetch_assoc()
|
||||
{
|
||||
return sqlsrv_fetch_array($this->result_id, SQLSRV_FETCH_ASSOC);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Result - object
|
||||
*
|
||||
* Returns the result set as an object
|
||||
*
|
||||
* @param string $class_name
|
||||
* @return object
|
||||
*/
|
||||
protected function _fetch_object($class_name = 'stdClass')
|
||||
{
|
||||
return sqlsrv_fetch_object($this->result_id, $class_name);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,74 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2015 TechFuze
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 1.0.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* SQLSRV Utility Class
|
||||
*
|
||||
* Converted from CodeIgniter.
|
||||
*
|
||||
* @package FuzeWorks
|
||||
* @category Database
|
||||
* @author EllisLab Dev Team
|
||||
* @link https://codeigniter.com/user_guide/database/
|
||||
* @license http://opensource.org/licenses/MIT MIT License
|
||||
*/
|
||||
class FW_DB_sqlsrv_utility extends FW_DB_utility {
|
||||
|
||||
/**
|
||||
* List databases statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_list_databases = 'EXEC sp_helpdb'; // Can also be: EXEC sp_databases
|
||||
|
||||
/**
|
||||
* OPTIMIZE TABLE statement
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_optimize_table = 'ALTER INDEX all ON %s REORGANIZE';
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Export
|
||||
*
|
||||
* @param array $params Preferences
|
||||
* @return bool
|
||||
*/
|
||||
protected function _backup($params = array())
|
||||
{
|
||||
// Currently unsupported
|
||||
return $this->db->display_error('db_unsupported_feature');
|
||||
}
|
||||
|
||||
}
|
|
@ -64,7 +64,7 @@ class Config
|
|||
|
||||
public function __construct()
|
||||
{
|
||||
$this->configPaths[] = Core::$appDir . DS. 'Config';
|
||||
$this->configPaths = Core::$appDirs;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2015 TechFuze
|
||||
* Copyright (C) 2018 TechFuze
|
||||
*
|
||||
* 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
|
||||
|
@ -27,7 +27,7 @@
|
|||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 1.0.0
|
||||
* @version Version 1.2.0
|
||||
*/
|
||||
|
||||
namespace FuzeWorks;
|
||||
|
@ -44,110 +44,214 @@ use Tracy\Debugger;
|
|||
*
|
||||
* This allows for more flexible startups.
|
||||
* @author Abel Hoogeveen <abel@techfuze.net>
|
||||
* @author David Grudl <https://davidgrudl.com>
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 2013 - 2018, Techfuze. (http://techfuze.net)
|
||||
*/
|
||||
class Configurator
|
||||
{
|
||||
|
||||
/**
|
||||
* The parameters that will be passed to FuzeWorks.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $parameters;
|
||||
protected $parameters = ['debugEnabled' => false];
|
||||
|
||||
/**
|
||||
* Components that will be attached to the Factory.
|
||||
*
|
||||
* @var array Array of classnames
|
||||
*/
|
||||
protected $components = [];
|
||||
|
||||
/**
|
||||
* Directories that will be passed to FuzeWorks components.
|
||||
*
|
||||
* These are NOT the temp and log directory.
|
||||
*
|
||||
* @var array of directories
|
||||
*/
|
||||
protected $directories = ['app' => []];
|
||||
|
||||
/**
|
||||
* Plugins that can be loaded outside of a directory and through a classname.
|
||||
*
|
||||
* @var array of plugins
|
||||
*/
|
||||
protected $plugins = [];
|
||||
|
||||
/**
|
||||
* Libraries that can be loaded outside of a directory and through a classname.
|
||||
*
|
||||
* @var array of plugins
|
||||
*/
|
||||
protected $libraries = [];
|
||||
|
||||
const COOKIE_SECRET = 'fuzeworks-debug';
|
||||
|
||||
/**
|
||||
* Constructs the Configurator class.
|
||||
*
|
||||
* Loads the default parameters
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->parameters = $this->getDefaultParameters();
|
||||
}
|
||||
/* ---------------- Core Directories--------------------- */
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* Sets path to temporary directory.
|
||||
*/
|
||||
protected function getDefaultParameters(): array
|
||||
public function setLogDirectory($path)
|
||||
{
|
||||
$trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
|
||||
$last = end($trace);
|
||||
$debugMode = static::detectDebugMode();
|
||||
return [
|
||||
'appDir' => isset($trace[1]['file']) ? dirname($trace[1]['file']) : NULL,
|
||||
'wwwDir' => isset($last['file']) ? dirname($last['file']) : NULL,
|
||||
'debugMode' => $debugMode
|
||||
];
|
||||
if (!is_dir($path))
|
||||
throw new InvalidArgumentException("Could not set log directory. Directory does not exist", 1);
|
||||
$this->parameters['logDir'] = $path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets path to temporary directory.
|
||||
* @return self
|
||||
*/
|
||||
public function setLogDirectory($path): self
|
||||
public function setTempDirectory($path)
|
||||
{
|
||||
$this->parameters['logDir'] = $path;
|
||||
return $this;
|
||||
if (!is_dir($path))
|
||||
throw new InvalidArgumentException("Could not set temp directory. Directory does not exist", 1);
|
||||
$this->parameters['tempDir'] = $path;
|
||||
}
|
||||
/* ---------------- Components -------------------------- */
|
||||
|
||||
/**
|
||||
* Registers a component that will be added to the Factory when the container is built
|
||||
*/
|
||||
public function addComponent(array $components)
|
||||
{
|
||||
foreach ($components as $componentName => $componentClass) {
|
||||
$this->components[$componentName] = $componentClass;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a plugin that will be loaded outside of a directory
|
||||
*
|
||||
* @param array Array with pluginName and pluginClass ('name' => 'classname')
|
||||
*/
|
||||
public function addPlugin(array $plugin)
|
||||
{
|
||||
foreach ($plugin as $key => $value) {
|
||||
$this->plugins[$key] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a library that will be loaded outside of a directory
|
||||
*
|
||||
* @param array Array with libraryName and libraryClass ('name' => 'classname')
|
||||
*/
|
||||
public function addLibrary(array $library)
|
||||
{
|
||||
foreach ($library as $key => $value) {
|
||||
$this->libraries[$key] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
/* ---------------- App Directories --------------------- */
|
||||
|
||||
public function addAppDirectory(string $directory)
|
||||
{
|
||||
$this->directories['app'][] = $directory;
|
||||
}
|
||||
|
||||
/*public function addConfigDirectory(string $directory)
|
||||
{
|
||||
$this->directories['config'][] = $directory;
|
||||
}
|
||||
|
||||
public function addEventDirectory(string $directory)
|
||||
{
|
||||
$this->directories['events'][] = $directory;
|
||||
}
|
||||
|
||||
public function addHelperDirectory(string $directory)
|
||||
{
|
||||
$this->directories['helpers'][] = $directory;
|
||||
}
|
||||
|
||||
public function addLibraryDirectory(string $directory)
|
||||
{
|
||||
$this->directories['libraries'][] = $directory;
|
||||
}
|
||||
|
||||
public function addPluginDirectory(string $directory)
|
||||
{
|
||||
$this->directories['plugins'][] = $directory;
|
||||
}*/
|
||||
|
||||
// @todo How do we add these dynamically for components?
|
||||
|
||||
/* ---------------- Other Features ---------------------- */
|
||||
|
||||
/**
|
||||
* Sets the default timezone.
|
||||
* @return self
|
||||
*/
|
||||
public function setTimeZone($timezone): self
|
||||
public function setTimeZone($timezone)
|
||||
{
|
||||
date_default_timezone_set($timezone);
|
||||
if (!date_default_timezone_set($timezone))
|
||||
throw new InvalidArgumentException("Could not set timezone. Invalid timezone provided.", 1);
|
||||
@ini_set('date.timezone', $timezone); // @ - function may be disabled
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds new parameters. The %params% will be expanded.
|
||||
* @return self
|
||||
* Adds new parameters. Use to quickly set multiple parameters at once
|
||||
*/
|
||||
public function setParameters(array $params): self
|
||||
public function setParameters(array $params)
|
||||
{
|
||||
foreach ($params as $key => $value) {
|
||||
$this->parameters[$key] = $value;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/* ---------------- Debug Mode -------------------------- */
|
||||
|
||||
/**
|
||||
* Fully enable or disable debug mode using one variable
|
||||
*/
|
||||
public function enableDebugMode(bool $bool = true)
|
||||
{
|
||||
$this->parameters['debugEnabled'] = $bool;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets path to temporary directory.
|
||||
* @return self
|
||||
* Provide a string from where debug mode can be accessed.
|
||||
* Can be the following type of addresses:
|
||||
* @todo
|
||||
*/
|
||||
public function setTempDirectory($path): self
|
||||
public function setDebugAddress($address = 'NONE')
|
||||
{
|
||||
$this->parameters['tempDir'] = $path;
|
||||
return $this;
|
||||
}
|
||||
// First we fetch the list
|
||||
if (!is_string($address) && !is_array($address))
|
||||
throw new InvalidArgumentException("Can not set debug address. Address must be a string or array",1);
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isDebugMode(): bool
|
||||
{
|
||||
return $this->parameters['debugMode'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Set parameter %debugMode%.
|
||||
* @param bool|string|array
|
||||
* @return self
|
||||
*/
|
||||
public function setDebugMode($value): self
|
||||
{
|
||||
if (is_string($value) || is_array($value)) {
|
||||
$value = static::detectDebugMode($value);
|
||||
} elseif (!is_bool($value)) {
|
||||
throw new InvalidArgumentException(sprintf('Value must be either a string, array, or boolean, %s given.', gettype($value)));
|
||||
// Then we test some common cases
|
||||
if (is_string($address) && $address == 'NONE')
|
||||
{
|
||||
$this->parameters['debugMatch'] = false;
|
||||
return;
|
||||
}
|
||||
$this->parameters['debugMode'] = $value;
|
||||
return $this;
|
||||
elseif (is_string($address) && $address == 'ALL')
|
||||
{
|
||||
$this->parameters['debugMatch'] = true;
|
||||
return;
|
||||
}
|
||||
|
||||
// Otherwise we run the regular tracy detectDebugMode
|
||||
$list = is_string($address)
|
||||
? preg_split('#[,\s]+#', $address)
|
||||
: (array) $address;
|
||||
$addr = isset($_SERVER['REMOTE_ADDR'])
|
||||
? $_SERVER['REMOTE_ADDR']
|
||||
: php_uname('n');
|
||||
$secret = isset($_COOKIE[self::COOKIE_SECRET]) && is_string($_COOKIE[self::COOKIE_SECRET])
|
||||
? $_COOKIE[self::COOKIE_SECRET]
|
||||
: NULL;
|
||||
if (!isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
|
||||
$list[] = '127.0.0.1';
|
||||
$list[] = '::1';
|
||||
}
|
||||
|
||||
$this->parameters['debugMatch'] = in_array($addr, $list, TRUE) || in_array("$secret@$addr", $list, TRUE);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -161,26 +265,11 @@ class Configurator
|
|||
}
|
||||
|
||||
/**
|
||||
* Detects debug mode by IP address.
|
||||
* @param string|array IP addresses or computer names whitelist detection
|
||||
* @return bool
|
||||
*/
|
||||
public static function detectDebugMode($list = NULL): bool
|
||||
public function isDebugMode(): bool
|
||||
{
|
||||
$addr = isset($_SERVER['REMOTE_ADDR'])
|
||||
? $_SERVER['REMOTE_ADDR']
|
||||
: php_uname('n');
|
||||
$secret = isset($_COOKIE[self::COOKIE_SECRET]) && is_string($_COOKIE[self::COOKIE_SECRET])
|
||||
? $_COOKIE[self::COOKIE_SECRET]
|
||||
: NULL;
|
||||
$list = is_string($list)
|
||||
? preg_split('#[,\s]+#', $list)
|
||||
: (array) $list;
|
||||
if (!isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
|
||||
$list[] = '127.0.0.1';
|
||||
$list[] = '::1';
|
||||
}
|
||||
return in_array($addr, $list, TRUE) || in_array("$secret@$addr", $list, TRUE);
|
||||
return $this->parameters['debugEnabled'] && $this->parameters['debugMatch'];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -193,26 +282,19 @@ class Configurator
|
|||
*/
|
||||
public function createContainer(): Factory
|
||||
{
|
||||
// First set all the directories
|
||||
Core::$appDir = $this->parameters['appDir'];
|
||||
Core::$wwwDir = $this->parameters['wwwDir'];
|
||||
// First set all the fixed directories
|
||||
Core::$tempDir = $this->parameters['tempDir'];
|
||||
Core::$logDir = $this->parameters['logDir'];
|
||||
Core::$appDirs = $this->directories['app'];
|
||||
|
||||
// Then set debug mode
|
||||
if ($this->parameters['debugMode'])
|
||||
{
|
||||
define('ENVIRONMENT', 'DEVELOPMENT');
|
||||
}
|
||||
else
|
||||
{
|
||||
define('ENVIRONMENT', 'PRODUCTION');
|
||||
}
|
||||
// Then prepare the debugger
|
||||
$debug = ($this->parameters['debugEnabled'] && $this->parameters['debugMatch'] ? true : false);
|
||||
define('ENVIRONMENT', ($debug ? 'DEVELOPMENT' : 'PRODUCTION'));
|
||||
|
||||
// And enable Tracy Debugger
|
||||
if (class_exists('Tracy\Debugger', true))
|
||||
{
|
||||
Debugger::enable(!$this->parameters['debugMode'], realpath($this->parameters['logDir']));
|
||||
Debugger::enable(!$debug, realpath($this->parameters['logDir']));
|
||||
if (isset($this->parameters['debugEmail']))
|
||||
{
|
||||
Debugger::$email = $this->parameters['debugEmail'];
|
||||
|
@ -221,8 +303,21 @@ class Configurator
|
|||
}
|
||||
|
||||
// Then load the framework
|
||||
Core::init();
|
||||
$container = Core::init();
|
||||
|
||||
return Factory::getInstance();
|
||||
// Add all components
|
||||
foreach ($this->components as $componentName => $componentClass) {
|
||||
$container->setInstance($componentName, new $componentClass());
|
||||
}
|
||||
|
||||
// And add all directories to the components
|
||||
foreach ($this->directories as $component => $directories) {
|
||||
if ($component == 'app')
|
||||
continue;
|
||||
|
||||
$container->{$component}->setDirectories($directories);
|
||||
}
|
||||
|
||||
return $container;
|
||||
}
|
||||
}
|
|
@ -1,46 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2015 TechFuze
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 1.0.0
|
||||
*/
|
||||
|
||||
namespace FuzeWorks;
|
||||
|
||||
/**
|
||||
* Abstract class ControllerAbstract.
|
||||
*
|
||||
* Extends all controllers to use the Factory.
|
||||
* Factory should in the future be replaced with a DI container
|
||||
*
|
||||
* @author Abel Hoogeveen <abel@techfuze.net>
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
*/
|
||||
abstract class ControllerAbstract extends Factory
|
||||
{
|
||||
}
|
|
@ -60,16 +60,14 @@ class Core
|
|||
*/
|
||||
public static $cwd;
|
||||
|
||||
public static $appDir;
|
||||
|
||||
public static $wwwDir;
|
||||
|
||||
public static $coreDir;
|
||||
|
||||
public static $tempDir;
|
||||
|
||||
public static $logDir;
|
||||
|
||||
public static $appDirs = [];
|
||||
|
||||
/**
|
||||
* The HTTP status code of the current request
|
||||
*
|
||||
|
@ -82,19 +80,13 @@ class Core
|
|||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function init()
|
||||
public static function init(): Factory
|
||||
{
|
||||
// Set the CWD for usage in the shutdown function
|
||||
self::$cwd = getcwd();
|
||||
|
||||
// Set the core dir for when the loading of classes is required
|
||||
self::$coreDir = dirname(__DIR__);
|
||||
|
||||
// If the environment is not yet defined, use production settings
|
||||
if (!defined('ENVIRONMENT'))
|
||||
{
|
||||
define('ENVIRONMENT', 'PRODUCTION');
|
||||
}
|
||||
|
||||
// Defines the time the framework starts. Used for timing functions in the framework
|
||||
if (!defined('STARTTIME')) {
|
||||
|
@ -118,10 +110,6 @@ class Core
|
|||
Events::disable();
|
||||
}
|
||||
|
||||
// And initialize multiple classes
|
||||
$container->layout->init();
|
||||
Language::init();
|
||||
|
||||
// And load all the plugins
|
||||
$container->plugins->loadHeaders();
|
||||
|
||||
|
@ -130,6 +118,8 @@ class Core
|
|||
if ($event->isCancelled()) {
|
||||
exit;
|
||||
}
|
||||
|
||||
return $container;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -147,9 +137,7 @@ class Core
|
|||
|
||||
if ($event->isCancelled() === false)
|
||||
{
|
||||
// If the output should be displayed, send the final render and parse the logger
|
||||
Logger::shutdownError();
|
||||
Factory::getInstance()->output->_display();
|
||||
Logger::shutdown();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,278 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2015 TechFuze
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 1.0.0
|
||||
*/
|
||||
|
||||
namespace FuzeWorks;
|
||||
use FuzeWorks\Exception\DatabaseException;
|
||||
use FW_DB;
|
||||
use FW_DB_forge;
|
||||
use FW_DB_utility;
|
||||
|
||||
/**
|
||||
* Database loading class
|
||||
*
|
||||
* Loads databases, forges and utilities in a standardized manner.
|
||||
*
|
||||
* @author TechFuze <contact@techfuze.net>
|
||||
* @copyright (c) 2013 - 2014, TechFuze. (https://techfuze.net)
|
||||
*
|
||||
*/
|
||||
class Database
|
||||
{
|
||||
|
||||
/**
|
||||
* The default database forge.
|
||||
* @var FW_DB|null
|
||||
*/
|
||||
protected static $defaultDB = null;
|
||||
|
||||
/**
|
||||
* Array of all the non-default databases
|
||||
* @var array FW_DB|null
|
||||
*/
|
||||
protected static $databases = array();
|
||||
|
||||
/**
|
||||
* The default database forge.
|
||||
* @var FW_DB_forge|null
|
||||
*/
|
||||
protected static $defaultForge = null;
|
||||
|
||||
/**
|
||||
* Array of all the non-default databases forges.
|
||||
* @var array FW_DB_forge|null
|
||||
*/
|
||||
protected static $forges = array();
|
||||
|
||||
/**
|
||||
* The default database utility.
|
||||
* @var FW_DB_utility|null
|
||||
*/
|
||||
protected static $defaultUtil = null;
|
||||
|
||||
/**
|
||||
* Register with the TracyBridge upon startup
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
if (class_exists('Tracy\Debugger', true))
|
||||
{
|
||||
DatabaseTracyBridge::register();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a database using a DSN or the default configuration.
|
||||
*
|
||||
* If a string is provided like this: 'dbdriver://username:password@hostname/database',
|
||||
* the string will be interpreted and converted into a database connection parameter array.
|
||||
*
|
||||
* If a string is provided with a name, like this: 'default' the 'default' connection from the
|
||||
* configuration file will be loaded. If no string is provided the default database will be loaded.
|
||||
*
|
||||
* If the $newInstance is a true boolean, a new instance will be loaded instead of loading the
|
||||
* default one. $newInstance will also make sure that the loaded database is not default one.
|
||||
* This behaviour will be changed in the future.
|
||||
*
|
||||
*
|
||||
* If $queryBuilder = false is provided, the database will load without a queryBuilder.
|
||||
* By default the queryBuilder will load.
|
||||
*
|
||||
* @param string $parameters
|
||||
* @param bool $newInstance
|
||||
* @param bool $queryBuilder
|
||||
* @return FW_DB|bool
|
||||
*/
|
||||
public static function get($parameters = '', $newInstance = false, $queryBuilder = null)
|
||||
{
|
||||
// Fire the event to allow settings to be changed
|
||||
$event = Events::fireEvent('databaseLoadDriverEvent', $parameters, $newInstance, $queryBuilder);
|
||||
if ($event->isCancelled())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// If an instance already exists and is requested, return it
|
||||
if (isset($event->database) && empty($event->parameters))
|
||||
{
|
||||
return self::$defaultDB = $event->database;
|
||||
}
|
||||
elseif (isset($event->database) && !empty($event->parameters))
|
||||
{
|
||||
return self::$databases[$event->parameters] = $event->database;
|
||||
}
|
||||
elseif (empty($event->parameters) && !$event->newInstance && is_object(self::$defaultDB) && ! empty(self::$defaultDB->conn_id))
|
||||
{
|
||||
return $reference = self::$defaultDB;
|
||||
}
|
||||
elseif (!empty($event->parameters) && !$event->newInstance && isset(self::$databases[$event->parameters]))
|
||||
{
|
||||
return $reference = self::$databases[$event->parameters];
|
||||
}
|
||||
|
||||
// If a new instance is required, load it
|
||||
require_once (Core::$coreDir . DS . 'Database'.DS.'DB.php');
|
||||
|
||||
if ($event->newInstance === TRUE)
|
||||
{
|
||||
$database = DB($event->parameters, $event->queryBuilder);
|
||||
}
|
||||
elseif (empty($event->parameters) && $event->newInstance === FALSE)
|
||||
{
|
||||
$database = self::$defaultDB = DB($event->parameters, $event->queryBuilder);
|
||||
}
|
||||
else
|
||||
{
|
||||
$database = self::$databases[$event->parameters] = DB($event->parameters, $event->queryBuilder);
|
||||
}
|
||||
|
||||
// Tie it into the Tracy Bar if available
|
||||
if (class_exists('\Tracy\Debugger', true))
|
||||
{
|
||||
DatabaseTracyBridge::registerDatabase($database);
|
||||
}
|
||||
|
||||
return $database;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a database forge from the provided or default database.
|
||||
*
|
||||
* If no database is provided, the default database will be used.
|
||||
*
|
||||
* @param FW_DB|null $database
|
||||
* @param bool $newInstance
|
||||
* @return FW_DB_forge
|
||||
*/
|
||||
public static function getForge($database = null, $newInstance = false)
|
||||
{
|
||||
// Fire the event to allow settings to be changed
|
||||
$event = Events::fireEvent('databaseLoadForgeEvent', $database, $newInstance);
|
||||
if ($event->isCancelled())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// First check if we're talking about the default forge and that one is already set
|
||||
if (is_object($event->forge) && ($event->forge instanceof FW_DB_forge) )
|
||||
{
|
||||
return $event->forge;
|
||||
}
|
||||
elseif (is_object($event->database) && $event->database === self::$defaultDB && is_object(self::$defaultForge))
|
||||
{
|
||||
return $reference = self::$defaultForge;
|
||||
}
|
||||
elseif ( ! is_object($event->database) OR ! ($event->database instanceof FW_DB))
|
||||
{
|
||||
isset(self::$defaultDB) OR self::get('', false);
|
||||
$database =& self::$defaultDB;
|
||||
}
|
||||
|
||||
require_once (Core::$coreDir . DS . 'Database'.DS.'DB_forge.php');
|
||||
require_once(Core::$coreDir . DS . 'Database'.DS.'drivers'.DS.$database->dbdriver.DS.$database->dbdriver.'_forge.php');
|
||||
|
||||
if ( ! empty($database->subdriver))
|
||||
{
|
||||
$driver_path = Core::$coreDir . DS . 'Database'.DS.'drivers'.DS.$database->dbdriver.DS.'subdrivers'.DS.$database->dbdriver.'_'.$database->subdriver.'_forge.php';
|
||||
if (file_exists($driver_path))
|
||||
{
|
||||
require_once($driver_path);
|
||||
$class = 'FW_DB_'.$database->dbdriver.'_'.$database->subdriver.'_forge';
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new DatabaseException("Could not load forge. Driver file does not exist.", 1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$class = 'FW_DB_'.$database->dbdriver.'_forge';
|
||||
}
|
||||
|
||||
// Create a new instance of set the default database
|
||||
if ($event->newInstance)
|
||||
{
|
||||
return new $class($database);
|
||||
}
|
||||
else
|
||||
{
|
||||
return self::$defaultForge = new $class($database);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a database utility from the provided or default database.
|
||||
*
|
||||
* If no database is provided, the default database will be used.
|
||||
*
|
||||
* @param FW_DB|null $database
|
||||
* @param bool $newInstance
|
||||
* @return FW_DB_utility
|
||||
*/
|
||||
public static function getUtil($database = null, $newInstance = false)
|
||||
{
|
||||
// Fire the event to allow settings to be changed
|
||||
$event = Events::fireEvent('databaseLoadUtilEvent', $database, $newInstance);
|
||||
if ($event->isCancelled())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// First check if we're talking about the default util and that one is already set
|
||||
if (is_object($event->util) && ($event->util instanceof FW_DB_utility))
|
||||
{
|
||||
return $event->util;
|
||||
}
|
||||
elseif (is_object($event->database) && $event->database === self::$defaultDB && is_object(self::$defaultUtil))
|
||||
{
|
||||
return $reference = self::$defaultUtil;
|
||||
}
|
||||
|
||||
if ( ! is_object($event->database) OR ! ($event->database instanceof FW_DB))
|
||||
{
|
||||
isset(self::$defaultDB) OR self::get('', false);
|
||||
$database = & self::$defaultDB;
|
||||
}
|
||||
|
||||
require_once (Core::$coreDir . DS . 'Database'.DS.'DB_utility.php');
|
||||
require_once(Core::$coreDir . DS . 'Database'.DS.'drivers'.DS.$database->dbdriver.DS.$database->dbdriver.'_utility.php');
|
||||
$class = 'FW_DB_'.$database->dbdriver.'_utility';
|
||||
|
||||
if ($event->newInstance)
|
||||
{
|
||||
return new $class($database);
|
||||
}
|
||||
else
|
||||
{
|
||||
return self::$defaultUtil = new $class($database);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,142 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2017 TechFuze
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2017, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 1.0.4
|
||||
*
|
||||
* @version Version 1.0.4
|
||||
*/
|
||||
|
||||
namespace FuzeWorks;
|
||||
use Tracy\IBarPanel;
|
||||
use Tracy\Debugger;
|
||||
|
||||
/**
|
||||
* DatabaseTracyBridge Class.
|
||||
*
|
||||
* This class provides a bridge between FuzeWorks\Database and Tracy Debugging tool.
|
||||
*
|
||||
* This class registers in Tracy, and creates a Bar object which contains information about database sessions.
|
||||
* It hooks into database usage and provides the information on the Tracy Bar panel.
|
||||
*
|
||||
* @author Abel Hoogeveen <abel@techfuze.net>
|
||||
* @copyright Copyright (c) 2013 - 2017, Techfuze. (http://techfuze.net)
|
||||
*/
|
||||
class DatabaseTracyBridge implements IBarPanel
|
||||
{
|
||||
|
||||
public static $databases = array();
|
||||
protected $results = array();
|
||||
|
||||
public static function register()
|
||||
{
|
||||
$class = new self();
|
||||
$bar = Debugger::getBar();
|
||||
$bar->addPanel($class);
|
||||
}
|
||||
|
||||
public static function registerDatabase($database)
|
||||
{
|
||||
self::$databases[] = $database;
|
||||
}
|
||||
|
||||
protected function getResults(): array
|
||||
{
|
||||
if (!empty($this->results))
|
||||
{
|
||||
return $this->results;
|
||||
}
|
||||
|
||||
// First prepare global variables
|
||||
$results = array();
|
||||
$results['dbCount'] = 0;
|
||||
$results['queryCount'] = 0;
|
||||
$results['queryTimings'] = 0.0;
|
||||
$results['errorsFound'] = false;
|
||||
|
||||
// Go through all databases
|
||||
foreach (self::$databases as $database) {
|
||||
// Increase total databases
|
||||
$results['dbCount']++;
|
||||
|
||||
// First determine the ID
|
||||
if (!empty($database->dsn))
|
||||
{
|
||||
$databaseId = $database->dsn;
|
||||
}
|
||||
elseif (!empty($database->username) && !empty($database->database) && !empty($database->hostname))
|
||||
{
|
||||
$databaseId = $database->username . '@' . $database->hostname . '/' . $database->database;
|
||||
}
|
||||
else
|
||||
{
|
||||
$databaseId = spl_object_hash($database);
|
||||
}
|
||||
|
||||
// Go through all queries
|
||||
foreach ($database->queries as $key => $query) {
|
||||
$results['queryCount']++;
|
||||
$results['queryTimings'] += $database->query_times[$key];
|
||||
$results['queries'][$databaseId][$key]['query'] = $query;
|
||||
$results['queries'][$databaseId][$key]['timings'] = $database->query_times[$key];
|
||||
$results['queries'][$databaseId][$key]['data'] = $database->query_data[$key];
|
||||
|
||||
// If errors are found, set this at the top of the array
|
||||
if ($database->query_data[$key]['error']['code'] != 0)
|
||||
{
|
||||
$results['errorsFound'] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Limit the amount in order to keep things readable
|
||||
$results['queryCountProvided'] = 0;
|
||||
foreach ($results['queries'] as $id => $database) {
|
||||
$results['queries'][$id] = array_reverse(array_slice($database, -10));
|
||||
$results['queryCountProvided'] += count($results['queries'][$id]);
|
||||
}
|
||||
$results = array_slice($results, -10);
|
||||
|
||||
return $this->results = $results;
|
||||
}
|
||||
|
||||
public function getTab(): string
|
||||
{
|
||||
$results = $this->getResults();
|
||||
ob_start(function () {});
|
||||
require dirname(__DIR__) . DS . 'Layout' . DS . 'layout.tracydatabasetab.php';
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
public function getPanel(): string
|
||||
{
|
||||
// Parse the panel
|
||||
$results = $this->getResults();
|
||||
ob_start(function () {});
|
||||
require dirname(__DIR__) . DS . 'Layout' . DS . 'layout.tracydatabasepanel.php';
|
||||
return ob_get_clean();
|
||||
}
|
||||
}
|
|
@ -1,85 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2015 TechFuze
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2017, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 1.0.4
|
||||
*
|
||||
* @version Version 1.0.4
|
||||
*/
|
||||
|
||||
namespace FuzeWorks\Event;
|
||||
|
||||
use FuzeWorks\Event;
|
||||
|
||||
/**
|
||||
* Event that gets loaded when a database driver is loaded
|
||||
*
|
||||
* Use this to cancel the loading of a database, or change the provided database
|
||||
*
|
||||
* @author Abel Hoogeveen <abel@techfuze.net>
|
||||
* @copyright Copyright (c) 2013 - 2017, Techfuze. (http://techfuze.net)
|
||||
*/
|
||||
class DatabaseLoadDriverEvent extends Event
|
||||
{
|
||||
/**
|
||||
* A possible database that can be loaded.
|
||||
*
|
||||
* Provide a database in this variable and it will be loaded. It shall be identified as default if
|
||||
* the parameters variable is empty. If there is a string in parameters this database shall be identified as
|
||||
* such.
|
||||
*
|
||||
* @var FW_DB|null
|
||||
*/
|
||||
public $database = null;
|
||||
|
||||
/**
|
||||
* Parameters of the database to be loaded
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $parameters;
|
||||
|
||||
/**
|
||||
* Whether a database instance shall be cloned if existing
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $newInstance;
|
||||
|
||||
/**
|
||||
* Whether to attach the queryBuilder to the database driver
|
||||
*
|
||||
* @var null|bool
|
||||
*/
|
||||
public $queryBuilder;
|
||||
|
||||
public function init($parameters = '', $newInstance = false, $queryBuilder = null)
|
||||
{
|
||||
$this->parameters = $parameters;
|
||||
$this->newInstance = $newInstance;
|
||||
$this->queryBuilder = $queryBuilder;
|
||||
}
|
||||
}
|
|
@ -1,77 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2015 TechFuze
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2017, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 1.0.4
|
||||
*
|
||||
* @version Version 1.0.4
|
||||
*/
|
||||
|
||||
namespace FuzeWorks\Event;
|
||||
|
||||
use FuzeWorks\Event;
|
||||
|
||||
/**
|
||||
* Event that gets loaded when a database forge is loaded
|
||||
*
|
||||
* Use this to cancel the loading of a forge, or change the provided database
|
||||
*
|
||||
* @author Abel Hoogeveen <abel@techfuze.net>
|
||||
* @copyright Copyright (c) 2013 - 2017, Techfuze. (http://techfuze.net)
|
||||
*/
|
||||
class DatabaseLoadForgeEvent extends Event
|
||||
{
|
||||
/**
|
||||
* A possible forge that can be loaded.
|
||||
*
|
||||
* Provide a forge in this variable and it will be loaded.
|
||||
*
|
||||
* @var FW_DB_forge|null
|
||||
*/
|
||||
public $forge = null;
|
||||
|
||||
/**
|
||||
* Database to be used by the forge.
|
||||
*
|
||||
* If no database is provided, FuzeWorks\Database shall provide the default database
|
||||
*
|
||||
* @var FW_DB|null
|
||||
*/
|
||||
public $database = null;
|
||||
|
||||
/**
|
||||
* Whether a database instance shall be cloned if existing
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $newInstance;
|
||||
|
||||
public function init($database = null, $newInstance = false)
|
||||
{
|
||||
$this->database = $database;
|
||||
$this->newInstance = $newInstance;
|
||||
}
|
||||
}
|
|
@ -1,77 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2015 TechFuze
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2017, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 1.0.4
|
||||
*
|
||||
* @version Version 1.0.4
|
||||
*/
|
||||
|
||||
namespace FuzeWorks\Event;
|
||||
|
||||
use FuzeWorks\Event;
|
||||
|
||||
/**
|
||||
* Event that gets loaded when a database utility is loaded
|
||||
*
|
||||
* Use this to cancel the loading of a util, or change the provided database
|
||||
*
|
||||
* @author Abel Hoogeveen <abel@techfuze.net>
|
||||
* @copyright Copyright (c) 2013 - 2017, Techfuze. (http://techfuze.net)
|
||||
*/
|
||||
class DatabaseLoadUtilEvent extends Event
|
||||
{
|
||||
/**
|
||||
* A possible util that can be loaded.
|
||||
*
|
||||
* Provide a util in this variable and it will be loaded.
|
||||
*
|
||||
* @var FW_DB_util|null
|
||||
*/
|
||||
public $util = null;
|
||||
|
||||
/**
|
||||
* Database to be used by the util.
|
||||
*
|
||||
* If no database is provided, FuzeWorks\Database shall provide the default database
|
||||
*
|
||||
* @var FW_DB_utility|null
|
||||
*/
|
||||
public $database = null;
|
||||
|
||||
/**
|
||||
* Whether a database instance shall be cloned if existing
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $newInstance;
|
||||
|
||||
public function init($database = null, $newInstance = false)
|
||||
{
|
||||
$this->database = $database;
|
||||
$this->newInstance = $newInstance;
|
||||
}
|
||||
}
|
|
@ -1,82 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2015 TechFuze
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 1.0.0
|
||||
*/
|
||||
|
||||
namespace FuzeWorks\Event;
|
||||
|
||||
use FuzeWorks\Event;
|
||||
|
||||
/**
|
||||
* Event that gets loaded when a layout is loaded.
|
||||
*
|
||||
* Use this to cancel the loading of a layout, or change the file or engine of a layout
|
||||
*
|
||||
* @author Abel Hoogeveen <abel@techfuze.net>
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
*/
|
||||
class LayoutLoadEvent extends Event
|
||||
{
|
||||
/**
|
||||
* The directory of the layout to be loaded.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $directory;
|
||||
|
||||
/**
|
||||
* The file of the layout to be loaded.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $file;
|
||||
|
||||
/**
|
||||
* The engine the file will be loaded with.
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
public $engine;
|
||||
|
||||
/**
|
||||
* The assigned variables to the template.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $assigned_variables;
|
||||
|
||||
public function init($file, $directory, $engine, $assigned_variables)
|
||||
{
|
||||
$this->file = $file;
|
||||
$this->directory = $directory;
|
||||
$this->engine = $engine;
|
||||
$this->assigned_variables = $assigned_variables;
|
||||
}
|
||||
}
|
|
@ -1,66 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2015 TechFuze
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 1.0.0
|
||||
*/
|
||||
|
||||
namespace FuzeWorks\Event;
|
||||
|
||||
use FuzeWorks\Event;
|
||||
|
||||
/**
|
||||
* Event that gets loaded when a model is loaded.
|
||||
*
|
||||
* Use this to cancel the loading of a model, or change the model to be loaded
|
||||
*
|
||||
* @author Abel Hoogeveen <abel@techfuze.net>
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
*/
|
||||
class ModelLoadEvent extends Event
|
||||
{
|
||||
/**
|
||||
* The directories the model can get loaded from.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $directories = array();
|
||||
|
||||
/**
|
||||
* The name of the model to be loaded.
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
public $modelName = null;
|
||||
|
||||
public function init($modelName, $directories)
|
||||
{
|
||||
$this->modelName = $modelName;
|
||||
$this->directories = $directories;
|
||||
}
|
||||
}
|
|
@ -1,70 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2015 TechFuze
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 1.0.0
|
||||
*/
|
||||
|
||||
namespace FuzeWorks\Event;
|
||||
|
||||
use FuzeWorks\Event;
|
||||
|
||||
/**
|
||||
* Class routerLoadCallableEvent.
|
||||
*
|
||||
* Called when a callable is about to be loaded
|
||||
*
|
||||
* @author Abel Hoogeveen <abel@techfuze.net>
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
*/
|
||||
class routerLoadCallableEvent extends Event
|
||||
{
|
||||
/**
|
||||
* @var callable The callable
|
||||
*/
|
||||
public $callable;
|
||||
|
||||
/**
|
||||
* @var array The matches with the routing path
|
||||
*/
|
||||
public $matches = array();
|
||||
|
||||
/**
|
||||
* The route which was matched.
|
||||
*
|
||||
* @var null|string
|
||||
*/
|
||||
public $route = null;
|
||||
|
||||
public function init($callable, $matches, $route)
|
||||
{
|
||||
$this->callable = $callable;
|
||||
$this->matches = $matches;
|
||||
$this->route = $route;
|
||||
}
|
||||
}
|
|
@ -1,100 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2015 TechFuze
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 1.0.0
|
||||
*/
|
||||
|
||||
namespace FuzeWorks\Event;
|
||||
|
||||
use FuzeWorks\Event;
|
||||
|
||||
/**
|
||||
* Event that gets fired when a controller is loaded.
|
||||
*
|
||||
* Use this to cancel the loading of a controller, or change the details of what is loaded.
|
||||
*
|
||||
* Currently only used by Router::defaultCallable();
|
||||
*
|
||||
* @author Abel Hoogeveen <abel@techfuze.net>
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
*/
|
||||
class RouterLoadControllerEvent extends Event
|
||||
{
|
||||
/**
|
||||
* The directory where the controller is located
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $directory;
|
||||
|
||||
/**
|
||||
* The file in which the controller is found
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $file;
|
||||
|
||||
/**
|
||||
* The class of the controller
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $className;
|
||||
|
||||
/**
|
||||
* The name of the controller
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $controller;
|
||||
|
||||
/**
|
||||
* The function that will be loaded in the controller
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $function;
|
||||
|
||||
/**
|
||||
* The parameters that will be provided to the function in the controller
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
public $parameters;
|
||||
|
||||
public function init($file, $directory, $className, $controller, $function, $parameters)
|
||||
{
|
||||
$this->file = $file;
|
||||
$this->directory = $directory;
|
||||
$this->className = $className;
|
||||
$this->controller = $controller;
|
||||
$this->function = $function;
|
||||
$this->parameters = $parameters;
|
||||
}
|
||||
}
|
|
@ -1,89 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2015 TechFuze
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 1.0.0
|
||||
*/
|
||||
|
||||
namespace FuzeWorks\Event;
|
||||
|
||||
use FuzeWorks\Event;
|
||||
|
||||
/**
|
||||
* Class routerRouteEvent.
|
||||
*
|
||||
* Fired after the router has extracted the path, and is about to find out what route matches the path.
|
||||
*
|
||||
* This Event is usefull for adding routes.
|
||||
*
|
||||
* @author Abel Hoogeveen <abel@techfuze.net>
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
*/
|
||||
class routerRouteEvent extends Event
|
||||
{
|
||||
/**
|
||||
* @var array The routing table
|
||||
*/
|
||||
public $routes;
|
||||
|
||||
/**
|
||||
* @var bool Whether the callable will be loaded directly after or not
|
||||
*/
|
||||
public $performLoading;
|
||||
|
||||
/**
|
||||
* Whether a cached page should be ignored or not
|
||||
*
|
||||
* @var bool true if cache should not be used
|
||||
*/
|
||||
public $cacheOverride = false;
|
||||
|
||||
/**
|
||||
* The current path input to FuzeWorks.
|
||||
*
|
||||
* @var null|string
|
||||
*/
|
||||
public $path;
|
||||
|
||||
public function init($routes, $performLoading, $path)
|
||||
{
|
||||
$this->routes = $routes;
|
||||
$this->performLoading = $performLoading;
|
||||
$this->path = $path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether a cached page should be ignored or not
|
||||
*
|
||||
* @param bool $overrideCache true if cache should not be used
|
||||
*/
|
||||
public function overrideCache($bool = true)
|
||||
{
|
||||
$this->cacheOverride = $bool;
|
||||
}
|
||||
}
|
|
@ -1,45 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2015 TechFuze
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 1.0.1
|
||||
*/
|
||||
|
||||
namespace FuzeWorks\Exception;
|
||||
|
||||
/**
|
||||
* Class DatabaseException.
|
||||
*
|
||||
* @author Abel Hoogeveen <abel@techfuze.net>
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
*/
|
||||
class DatabaseException extends Exception
|
||||
{
|
||||
}
|
||||
|
||||
?>
|
|
@ -1,45 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2015 TechFuze
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 1.0.1
|
||||
*/
|
||||
|
||||
namespace FuzeWorks\Exception;
|
||||
|
||||
/**
|
||||
* Class LanguageException.
|
||||
*
|
||||
* @author Abel Hoogeveen <abel@techfuze.net>
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
*/
|
||||
class LanguageException extends Exception
|
||||
{
|
||||
}
|
||||
|
||||
?>
|
|
@ -1,45 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* FuzeWorks.
|
||||
*
|
||||
* The FuzeWorks MVC PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2015 TechFuze
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
* @copyright Copyright (c) 1996 - 2015, Free Software Foundation, Inc. (http://www.fsf.org/)
|
||||
* @license http://opensource.org/licenses/GPL-3.0 GPLv3 License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 0.0.1
|
||||
*
|
||||
* @version Version 1.0.1
|
||||
*/
|
||||
|
||||
namespace FuzeWorks\Exception;
|
||||
|
||||
/**
|
||||
* Class LayoutException.
|
||||
*
|
||||
* @author Abel Hoogeveen <abel@techfuze.net>
|
||||
* @copyright Copyright (c) 2013 - 2016, Techfuze. (http://techfuze.net)
|
||||
*/
|
||||
class LayoutException extends Exception
|
||||
{
|
||||
}
|
||||
|
||||
?>
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue