Advertisement
Islam-Hacker

by jm511 Universidad in Venezuela was fucked

Mar 29th, 2012
7,359
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 28.77 KB | None | 0 0
  1. by team jm_hacker
  2. jm511 + shi5 aLHacker
  3. 29-3-2012
  4. We Fucked the Database .. Priv8
  5. +
  6. From : Saudi Arabia
  7.  
  8. #(( There is no patch to human stupidity ))##
  9. We Are Saudi Arabian Hackers
  10. ------------
  11. Website From Venezuela ..
  12. Universidad Nacional Experimental Poli Técnica Antonio José de Sucre
  13. www.bqto.unexpo.edu.ve
  14.  
  15.  
  16.  
  17. ====================================
  18. we fucked Config of the site
  19. ---------------------------------
  20.  
  21.  
  22.  
  23.  
  24. <?php
  25.  
  26. /*
  27. * Set tabs to 4 for best viewing.
  28. *
  29. * Latest version is available at http://php.weblogs.com
  30. *
  31. * This is the main include file for ADOdb.
  32. * Database specific drivers are stored in the adodb/drivers/adodb-*.inc.php
  33. *
  34. * The ADOdb files are formatted so that doxygen can be used to generate documentation.
  35. * Doxygen is a documentation generation tool and can be downloaded from http://doxygen.org/
  36. */
  37.  
  38. /**
  39. \mainpage
  40.  
  41. @version V3.40 7 April 2003 (c) 2000-2003 John Lim (jlim\@natsoft.com.my). All rights reserved.
  42.  
  43. Released under both BSD license and Lesser GPL library license.
  44. Whenever there is any discrepancy between the two licenses,
  45. the BSD license will take precedence.
  46.  
  47. PHP's database access functions are not standardised. This creates a need for a database
  48. class library to hide the differences between the different database API's (encapsulate
  49. the differences) so we can easily switch databases.
  50.  
  51. We currently support MySQL, Oracle, Microsoft SQL Server, Sybase, Sybase SQL Anywhere,
  52. Informix, PostgreSQL, FrontBase, Interbase (Firebird and Borland variants), Foxpro, Access,
  53. ADO and ODBC. We have had successful reports of connecting to Progress and DB2 via ODBC.
  54. We hope more people will contribute drivers to support other databases.
  55.  
  56. Latest Download at http://php.weblogs.com/adodb<br>
  57. Manual is at http://php.weblogs.com/adodb_manual
  58.  
  59. */
  60.  
  61. if (!defined('_ADODB_LAYER')) {
  62. define('_ADODB_LAYER',1);
  63.  
  64. //==============================================================================================
  65. // CONSTANT DEFINITIONS
  66. //==============================================================================================
  67.  
  68. define('ADODB_BAD_RS','<p>Bad $rs in %s. Connection or SQL invalid. Try using $connection->debug=true;</p>');
  69.  
  70. define('ADODB_FETCH_DEFAULT',0);
  71. define('ADODB_FETCH_NUM',1);
  72. define('ADODB_FETCH_ASSOC',2);
  73. define('ADODB_FETCH_BOTH',3);
  74.  
  75. /*
  76. Controls ADODB_FETCH_ASSOC field-name case. Default is 2, use native case-names.
  77. This currently works only with mssql, odbc, oci8po and ibase derived drivers.
  78.  
  79. 0 = assoc lowercase field names. $rs->fields['orderid']
  80. 1 = assoc uppercase field names. $rs->fields['ORDERID']
  81. 2 = use native-case field names. $rs->fields['OrderID']
  82. */
  83. if (!defined('ADODB_ASSOC_CASE')) define('ADODB_ASSOC_CASE',2);
  84.  
  85. // allow [ ] @ ` and . in table names
  86. define('ADODB_TABLE_REGEX','([]0-9a-z_\`\.\@\[-]*)');
  87.  
  88.  
  89. if (!defined('ADODB_PREFETCH_ROWS')) define('ADODB_PREFETCH_ROWS',10);
  90.  
  91. /**
  92. * Set ADODB_DIR to the directory where this file resides...
  93. * This constant was formerly called $ADODB_RootPath
  94. */
  95. if (!defined('ADODB_DIR')) define('ADODB_DIR',dirname(__FILE__));
  96.  
  97. define('TIMESTAMP_FIRST_YEAR',100);
  98.  
  99. //==============================================================================================
  100. // GLOBAL VARIABLES
  101. //==============================================================================================
  102.  
  103. GLOBAL
  104. $ADODB_vers, // database version
  105. $ADODB_Database, // last database driver used
  106. $ADODB_COUNTRECS, // count number of records returned - slows down query
  107. $ADODB_CACHE_DIR, // directory to cache recordsets
  108. $ADODB_EXTENSION, // ADODB extension installed
  109. $ADODB_COMPAT_PATCH, // If $ADODB_COUNTRECS and this is true, $rs->fields is available on EOF
  110. $ADODB_FETCH_MODE; // DEFAULT, NUM, ASSOC or BOTH. Default follows native driver default...
  111.  
  112. //==============================================================================================
  113. // GLOBAL SETUP
  114. //==============================================================================================
  115.  
  116. if (strnatcmp(PHP_VERSION,'4.3.0')>=0) {
  117. define('ADODB_PHPVER',0x4300);
  118. } else if (strnatcmp(PHP_VERSION,'4.2.0')>=0) {
  119. define('ADODB_PHPVER',0x4200);
  120. } else if (strnatcmp(PHP_VERSION,'4.0.5')>=0) {
  121. define('ADODB_PHPVER',0x4050);
  122. } else {
  123. define('ADODB_PHPVER',0x4000);
  124. }
  125. $ADODB_EXTENSION = defined('ADODB_EXTENSION');
  126. //if (extension_loaded('dbx')) define('ADODB_DBX',1);
  127.  
  128. /**
  129. Accepts $src and $dest arrays, replacing string $data
  130. */
  131. function ADODB_str_replace($src, $dest, $data)
  132. {
  133. if (ADODB_PHPVER >= 0x4050) return str_replace($src,$dest,$data);
  134.  
  135. $s = reset($src);
  136. $d = reset($dest);
  137. while ($s !== false) {
  138. $data = str_replace($s,$d,$data);
  139. $s = next($src);
  140. $d = next($dest);
  141. }
  142. return $data;
  143. }
  144.  
  145. function ADODB_Setup()
  146. {
  147. GLOBAL
  148. $ADODB_vers, // database version
  149. $ADODB_Database, // last database driver used
  150. $ADODB_COUNTRECS, // count number of records returned - slows down query
  151. $ADODB_CACHE_DIR, // directory to cache recordsets
  152. $ADODB_FETCH_MODE;
  153.  
  154. $ADODB_FETCH_MODE = ADODB_FETCH_DEFAULT;
  155.  
  156. if (!isset($ADODB_CACHE_DIR)) {
  157. $ADODB_CACHE_DIR = '/tmp';
  158. } else {
  159. // do not accept url based paths, eg. http:/ or ftp:/
  160. if (strpos($ADODB_CACHE_DIR,'://') !== false)
  161. die("Illegal path http:// or ftp://");
  162. }
  163.  
  164.  
  165. // Initialize random number generator for randomizing cache flushes
  166. srand(((double)microtime())*1000000);
  167.  
  168. /**
  169. * Name of last database driver loaded into memory. Set by ADOLoadCode().
  170. */
  171. $ADODB_Database = '';
  172.  
  173. /**
  174. * ADODB version as a string.
  175. */
  176. $ADODB_vers = 'V3.40 7 April 2003 (c) 2000-2003 John Lim ([email protected]). All rights reserved. Released BSD & LGPL.';
  177.  
  178. /**
  179. * Determines whether recordset->RecordCount() is used.
  180. * Set to false for highest performance -- RecordCount() will always return -1 then
  181. * for databases that provide "virtual" recordcounts...
  182. */
  183. $ADODB_COUNTRECS = true;
  184. }
  185.  
  186.  
  187. //==============================================================================================
  188. // CHANGE NOTHING BELOW UNLESS YOU ARE CODING
  189. //==============================================================================================
  190.  
  191. ADODB_Setup();
  192.  
  193. //==============================================================================================
  194. // CLASS ADOFieldObject
  195. //==============================================================================================
  196. /**
  197. * Helper class for FetchFields -- holds info on a column
  198. */
  199. class ADOFieldObject {
  200. var $name = '';
  201. var $max_length=0;
  202. var $type="";
  203.  
  204. // additional fields by dannym... ([email protected])
  205. var $not_null = false;
  206. // actually, this has already been built-in in the postgres, fbsql AND mysql module? ^-^
  207. // so we can as well make not_null standard (leaving it at "false" does not harm anyways)
  208.  
  209. var $has_default = false; // this one I have done only in mysql and postgres for now ...
  210. // others to come (dannym)
  211. var $default_value; // default, if any, and supported. Check has_default first.
  212. }
  213.  
  214.  
  215. //==============================================================================================
  216. // CLASS ADOConnection
  217. //==============================================================================================
  218.  
  219. include_once(ADODB_DIR.'/adodb-connection.inc.php');
  220.  
  221.  
  222.  
  223. //==============================================================================================
  224. // CLASS ADOFetchObj
  225. //==============================================================================================
  226.  
  227. /**
  228. * Internal placeholder for record objects. Used by ADORecordSet->FetchObj().
  229. */
  230. class ADOFetchObj {
  231. };
  232.  
  233. //==============================================================================================
  234. // CLASS ADORecordSet_empty
  235. //==============================================================================================
  236.  
  237. /**
  238. * Lightweight recordset when there are no records to be returned
  239. */
  240. class ADORecordSet_empty
  241. {
  242. var $dataProvider = 'empty';
  243. var $databaseType = false;
  244. var $EOF = true;
  245. var $_numOfRows = 0;
  246. var $fields = false;
  247. var $connection = false;
  248. function RowCount() {return 0;}
  249. function RecordCount() {return 0;}
  250. function PO_RecordCount(){return 0;}
  251. function Close(){return true;}
  252. function FetchRow() {return false;}
  253. function FieldCount(){ return 0;}
  254. }
  255.  
  256. //==============================================================================================
  257. // DATE AND TIME FUNCTIONS
  258. //==============================================================================================
  259. include_once(ADODB_DIR.'/adodb-time.inc.php');
  260.  
  261. //==============================================================================================
  262. // CLASS ADORecordSet
  263. //==============================================================================================
  264. include_once(ADODB_DIR.'/adodb-recordset.inc.php');
  265.  
  266. //==============================================================================================
  267. // CLASS ADORecordSet_array
  268. //==============================================================================================
  269.  
  270. /**
  271. * This class encapsulates the concept of a recordset created in memory
  272. * as an array. This is useful for the creation of cached recordsets.
  273. *
  274. * Note that the constructor is different from the standard ADORecordSet
  275. */
  276.  
  277. class ADORecordSet_array extends ADORecordSet
  278. {
  279. var $databaseType = 'array';
  280.  
  281. var $_array; // holds the 2-dimensional data array
  282. var $_types; // the array of types of each column (C B I L M)
  283. var $_colnames; // names of each column in array
  284. var $_skiprow1; // skip 1st row because it holds column names
  285. var $_fieldarr; // holds array of field objects
  286. var $canSeek = true;
  287. var $affectedrows = false;
  288. var $insertid = false;
  289. var $sql = '';
  290. var $compat = false;
  291. /**
  292. * Constructor
  293. *
  294. */
  295. function ADORecordSet_array($fakeid=1)
  296. {
  297. global $ADODB_FETCH_MODE,$ADODB_COMPAT_FETCH;
  298.  
  299. // fetch() on EOF does not delete $this->fields
  300. $this->compat = !empty($ADODB_COMPAT_FETCH);
  301. $this->ADORecordSet($fakeid); // fake queryID
  302. $this->fetchMode = $ADODB_FETCH_MODE;
  303. }
  304.  
  305.  
  306. /**
  307. * Setup the Array. Later we will have XML-Data and CSV handlers
  308. *
  309. * @param array is a 2-dimensional array holding the data.
  310. * The first row should hold the column names
  311. * unless paramter $colnames is used.
  312. * @param typearr holds an array of types. These are the same types
  313. * used in MetaTypes (C,B,L,I,N).
  314. * @param [colnames] array of column names. If set, then the first row of
  315. * $array should not hold the column names.
  316. */
  317. function InitArray($array,$typearr,$colnames=false)
  318. {
  319. $this->_array = $array;
  320. $this->_types = $typearr;
  321. if ($colnames) {
  322. $this->_skiprow1 = false;
  323. $this->_colnames = $colnames;
  324. } else $this->_colnames = $array[0];
  325.  
  326. $this->Init();
  327. }
  328. /**
  329. * Setup the Array and datatype file objects
  330. *
  331. * @param array is a 2-dimensional array holding the data.
  332. * The first row should hold the column names
  333. * unless paramter $colnames is used.
  334. * @param fieldarr holds an array of ADOFieldObject's.
  335. */
  336. function InitArrayFields($array,$fieldarr)
  337. {
  338. $this->_array = $array;
  339. $this->_skiprow1= false;
  340. if ($fieldarr) {
  341. $this->_fieldobjects = $fieldarr;
  342. }
  343. $this->Init();
  344. }
  345.  
  346. function GetArray($nRows=-1)
  347. {
  348. if ($nRows == -1 && $this->_currentRow <= 0 && !$this->_skiprow1) {
  349. return $this->_array;
  350. } else {
  351. return ADORecordSet::GetArray($nRows);
  352. }
  353. }
  354.  
  355. function _initrs()
  356. {
  357. $this->_numOfRows = sizeof($this->_array);
  358. if ($this->_skiprow1) $this->_numOfRows -= 1;
  359.  
  360. $this->_numOfFields =(isset($this->_fieldobjects)) ?
  361. sizeof($this->_fieldobjects):sizeof($this->_types);
  362. }
  363.  
  364. /* Use associative array to get fields array */
  365. function Fields($colname)
  366. {
  367. if ($this->fetchMode & ADODB_FETCH_ASSOC) return $this->fields[$colname];
  368.  
  369. if (!$this->bind) {
  370. $this->bind = array();
  371. for ($i=0; $i < $this->_numOfFields; $i++) {
  372. $o = $this->FetchField($i);
  373. $this->bind[strtoupper($o->name)] = $i;
  374. }
  375. }
  376. return $this->fields[$this->bind[strtoupper($colname)]];
  377. }
  378.  
  379. function &FetchField($fieldOffset = -1)
  380. {
  381. if (isset($this->_fieldobjects)) {
  382. return $this->_fieldobjects[$fieldOffset];
  383. }
  384. $o = new ADOFieldObject();
  385. $o->name = $this->_colnames[$fieldOffset];
  386. $o->type = $this->_types[$fieldOffset];
  387. $o->max_length = -1; // length not known
  388.  
  389. return $o;
  390. }
  391.  
  392. function _seek($row)
  393. {
  394. if (sizeof($this->_array) && $row < $this->_numOfRows) {
  395. $this->fields = $this->_array[$row];
  396. return true;
  397. }
  398. return false;
  399. }
  400.  
  401. function MoveNext()
  402. {
  403. if (!$this->EOF) {
  404. $this->_currentRow++;
  405.  
  406. $pos = $this->_currentRow;
  407. if ($this->_skiprow1) $pos += 1;
  408.  
  409. if ($this->_numOfRows <= $pos) {
  410. if (!$this->compat) $this->fields = false;
  411. } else {
  412. $this->fields = $this->_array[$pos];
  413. return true;
  414. }
  415. $this->EOF = true;
  416. }
  417.  
  418. return false;
  419. }
  420.  
  421. function _fetch()
  422. {
  423. $pos = $this->_currentRow;
  424. if ($this->_skiprow1) $pos += 1;
  425.  
  426. if ($this->_numOfRows <= $pos) {
  427. if (!$this->compat) $this->fields = false;
  428. return false;
  429. }
  430.  
  431. $this->fields = $this->_array[$pos];
  432. return true;
  433. }
  434.  
  435. function _close()
  436. {
  437. return true;
  438. }
  439.  
  440. } // ADORecordSet_array
  441.  
  442. //==============================================================================================
  443. // HELPER FUNCTIONS
  444. //==============================================================================================
  445.  
  446. /**
  447. * Synonym for ADOLoadCode.
  448. *
  449. * @deprecated
  450. */
  451. function ADOLoadDB($dbType)
  452. {
  453. return ADOLoadCode($dbType);
  454. }
  455.  
  456. /**
  457. * Load the code for a specific database driver
  458. */
  459. function ADOLoadCode($dbType)
  460. {
  461. GLOBAL $ADODB_Database;
  462.  
  463. if (!$dbType) return false;
  464. $ADODB_Database = strtolower($dbType);
  465. switch ($ADODB_Database) {
  466. case 'maxsql': $ADODB_Database = 'mysqlt'; break;
  467. case 'postgres':
  468. case 'pgsql': $ADODB_Database = 'postgres7'; break;
  469. }
  470. // Karsten Kraus <[email protected]>
  471. return @include_once(ADODB_DIR."/drivers/adodb-".$ADODB_Database.".inc.php");
  472. }
  473.  
  474. /**
  475. * synonym for ADONewConnection for people like me who cannot remember the correct name
  476. */
  477. function &NewADOConnection($db='')
  478. {
  479. return ADONewConnection($db);
  480. }
  481.  
  482. /**
  483. * Instantiate a new Connection class for a specific database driver.
  484. *
  485. * @param [db] is the database Connection object to create. If undefined,
  486. * use the last database driver that was loaded by ADOLoadCode().
  487. *
  488. * @return the freshly created instance of the Connection class.
  489. */
  490. function &ADONewConnection($db='')
  491. {
  492. GLOBAL $ADODB_Database;
  493.  
  494. $rez = true;
  495. if ($db) {
  496. if ($ADODB_Database != $db) ADOLoadCode($db);
  497. } else {
  498. if (!empty($ADODB_Database)) {
  499. ADOLoadCode($ADODB_Database);
  500. } else {
  501. $rez = false;
  502. }
  503. }
  504.  
  505. $errorfn = (defined('ADODB_ERROR_HANDLER')) ? ADODB_ERROR_HANDLER : false;
  506. if (!$rez) {
  507. if ($errorfn) {
  508. // raise an error
  509. $errorfn('ADONewConnection', 'ADONewConnection', -998,
  510. "could not load the database driver for '$db",
  511. $dbtype);
  512. } else
  513. ADOConnection::outp( "<p>ADONewConnection: Unable to load database driver '$db'</p>",false);
  514.  
  515. return false;
  516. }
  517.  
  518. $cls = 'ADODB_'.$ADODB_Database;
  519. $obj = new $cls();
  520. if ($errorfn) {
  521. $obj->raiseErrorFn = $errorfn;
  522. }
  523. return $obj;
  524. }
  525.  
  526. function &NewDataDictionary(&$conn)
  527. {
  528. $provider = $conn->dataProvider;
  529. if ($provider !== 'native' && $provider != 'odbc' && $provider != 'ado')
  530. $drivername = $conn->dataProvider;
  531. else {
  532. $drivername = $conn->databaseType;
  533. if (substr($drivername,0,5) == 'odbc_') $drivername = substr($drivername,5);
  534. else if (substr($drivername,0,4) == 'ado_') $drivername = substr($drivername,4);
  535. else if ($drivername == 'oracle') $drivername = 'oci8';
  536. }
  537. include_once(ADODB_DIR.'/adodb-lib.inc.php');
  538. include_once(ADODB_DIR.'/adodb-datadict.inc.php');
  539. $path = ADODB_DIR."/datadict/datadict-$drivername.inc.php";
  540.  
  541. if (!file_exists($path)) {
  542. ADOConnection::outp("Database driver '$path' not available");
  543. return false;
  544. }
  545. include_once($path);
  546. $class = "ADODB2_$drivername";
  547. $dict = new $class();
  548. $dict->connection = &$conn;
  549. $dict->upperName = strtoupper($drivername);
  550. if (is_resource($conn->_connectionID))
  551. $dict->serverInfo = $conn->ServerInfo();
  552.  
  553. return $dict;
  554. }
  555.  
  556.  
  557. /**
  558. * Save a file $filename and its $contents (normally for caching) with file locking
  559. */
  560. function adodb_write_file($filename, $contents,$debug=false)
  561. {
  562. # http://www.php.net/bugs.php?id=9203 Bug that flock fails on Windows
  563. # So to simulate locking, we assume that rename is an atomic operation.
  564. # First we delete $filename, then we create a $tempfile write to it and
  565. # rename to the desired $filename. If the rename works, then we successfully
  566. # modified the file exclusively.
  567. # What a stupid need - having to simulate locking.
  568. # Risks:
  569. # 1. $tempfile name is not unique -- very very low
  570. # 2. unlink($filename) fails -- ok, rename will fail
  571. # 3. adodb reads stale file because unlink fails -- ok, $rs timeout occurs
  572. # 4. another process creates $filename between unlink() and rename() -- ok, rename() fails and cache updated
  573. if (strpos(strtoupper(PHP_OS),'WIN') !== false) {
  574. // skip the decimal place
  575. $mtime = substr(str_replace(' ','_',microtime()),2);
  576. // unlink will let some latencies develop, so uniqid() is more random
  577. @unlink($filename);
  578. // getmypid() actually returns 0 on Win98 - never mind!
  579. $tmpname = $filename.uniqid($mtime).getmypid();
  580. if (!($fd = fopen($tmpname,'a'))) return false;
  581. $ok = ftruncate($fd,0);
  582. if (!fwrite($fd,$contents)) $ok = false;
  583. fclose($fd);
  584. chmod($tmpname,0644);
  585. if (!@rename($tmpname,$filename)) {
  586. unlink($tmpname);
  587. $ok = false;
  588. }
  589. if (!$ok) {
  590. if ($debug) ADOConnection::outp( " Rename $tmpname ".($ok? 'ok' : 'failed'));
  591. }
  592. return $ok;
  593. }
  594. if (!($fd = fopen($filename, 'a'))) return false;
  595. if (flock($fd, LOCK_EX) && ftruncate($fd, 0)) {
  596. $ok = fwrite( $fd, $contents );
  597. fclose($fd);
  598. chmod($filename,0644);
  599. }else {
  600. fclose($fd);
  601. if ($debug)ADOConnection::outp( " Failed acquiring lock for $filename<br>\n");
  602. $ok = false;
  603. }
  604.  
  605. return $ok;
  606. }
  607.  
  608.  
  609. function adodb_backtrace($print=true)
  610. {
  611. $s = '';
  612. if (PHPVERSION() >= 4.3) {
  613.  
  614. $MAXSTRLEN = 64;
  615.  
  616. $s = '<pre align=left>';
  617. $traceArr = debug_backtrace();
  618. array_shift($traceArr);
  619. $tabs = sizeof($traceArr)-1;
  620. foreach ($traceArr as $arr) {
  621. for ($i=0; $i < $tabs; $i++) $s .= ' &nbsp; ';
  622. $tabs -= 1;
  623. $s .= '<font face="Courier New,Courier">';
  624. if (isset($arr['class'])) $s .= $arr['class'].'.';
  625. foreach($arr['args'] as $v) {
  626. if (is_null($v)) $args[] = 'null';
  627. else if (is_array($v)) $args[] = 'Array['.sizeof($v).']';
  628. else if (is_object($v)) $args[] = 'Object:'.get_class($v);
  629. else if (is_bool($v)) $args[] = $v ? 'true' : 'false';
  630. else {
  631. $v = (string) @$v;
  632. $str = htmlspecialchars(substr($v,0,$MAXSTRLEN));
  633. if (strlen($v) > $MAXSTRLEN) $str .= '...';
  634. $args[] = $str;
  635. }
  636. }
  637.  
  638. $s .= $arr['function'].'('.implode(', ',$args).')';
  639. $s .= sprintf("</font><font color=#808080 size=-1> # line %4d, file: <a href=\"file:/%s\">%s</a></font>",
  640. $arr['line'],$arr['file'],$arr['file']);
  641. $s .= "\n";
  642. }
  643. $s .= '</pre>';
  644. if ($print) print $s;
  645. }
  646. return $s;
  647. }
  648.  
  649. } // defined
  650. ?>
  651.  
  652.  
  653. ==================
  654. ===================
  655. ======================
  656. =============================
  657.  
  658.  
  659.  
  660. <?php
  661.  
  662. /**
  663. V3.40 7 April 2003 (c) 2000-2003 John Lim ([email protected]). All rights reserved.
  664. Released under both BSD license and Lesser GPL library license.
  665. Whenever there is any discrepancy between the two licenses,
  666. the BSD license will take precedence.
  667.  
  668. Set tabs to 4 for best viewing.
  669.  
  670. DOCUMENTATION:
  671.  
  672. See adodb/tests/test-datadict.php for docs and examples.
  673. */
  674.  
  675. class ADODB_DataDict {
  676. var $connection;
  677. var $debug = false;
  678. var $dropTable = "DROP TABLE %s";
  679. var $addCol = ' ADD';
  680. var $alterCol = ' ALTER COLUMN';
  681. var $dropCol = ' DROP COLUMN';
  682. var $schema = false;
  683. var $serverInfo = array();
  684.  
  685. function MetaTables()
  686. {
  687. return $this->connection->MetaTables();
  688. }
  689.  
  690. function MetaColumns($tab)
  691. {
  692. return $this->connection->MetaColumns($tab);
  693. }
  694.  
  695. function MetaPrimaryKeys($tab,$owner=false,$intkey=false)
  696. {
  697. return $this->connection->MetaPrimaryKeys($tab.$owner,$intkey);
  698. }
  699.  
  700. function MetaType($t,$len=-1,$fieldobj=false)
  701. {
  702. return ADORecordSet::MetaType($t,$len,$fieldobj);
  703. }
  704.  
  705. // Executes the sql array returned by GetTableSQL and GetIndexSQL
  706. function ExecuteSQLArray($sql, $continueOnError = true)
  707. {
  708. $rez = 2;
  709. $conn = &$this->connection;
  710. foreach($sql as $line) {
  711. $ok = $conn->Execute($line);
  712. if (!$ok) {
  713. if ($this->debug) ADOConnection::outp($conn->ErrorMsg());
  714. if (!$continueOnError) return 0;
  715. $rez = 1;
  716. }
  717. }
  718. return 2;
  719. }
  720.  
  721. /*
  722. Returns the actual type given a character code.
  723.  
  724. C: varchar
  725. X: CLOB (character large object) or largest varchar size if CLOB is not supported
  726. C2: Multibyte varchar
  727. X2: Multibyte CLOB
  728.  
  729. B: BLOB (binary large object)
  730.  
  731. D: Date
  732. T: Date-time
  733. L: Integer field suitable for storing booleans (0 or 1)
  734. I: Integer
  735. F: Floating point number
  736. N: Numeric or decimal number
  737. */
  738.  
  739. function ActualType($meta)
  740. {
  741. return $meta;
  742. }
  743.  
  744. function CreateDatabase($dbname,$options=false)
  745. {
  746. $options = $this->_Options($options);
  747. $s = 'CREATE DATABASE '.$dbname;
  748. if (isset($options[$this->upperName])) $s .= ' '.$options[$this->upperName];
  749. $sql[] = $s;
  750. return $sql;
  751. }
  752.  
  753. /*
  754. Generates the SQL to create index. Returns an array of sql strings.
  755. */
  756. function CreateIndexSQL($idxname, $tabname, $flds, $idxoptions = false)
  757. {
  758. if ($this->schema) $tabname = $this->schema.'.'.$tabname;
  759. return $this->_IndexSQL($idxname, $tabname, $flds, $this->_Options($idxoptions));
  760. }
  761.  
  762. function SetSchema($schema)
  763. {
  764. $this->schema = $schema;
  765. }
  766.  
  767. function AddColumnSQL($tabname, $flds)
  768. {
  769. if ($this->schema) $tabname = $this->schema.'.'.$tabname;
  770. $sql = array();
  771. list($lines,$pkey) = $this->_GenFields($flds);
  772. foreach($lines as $v) {
  773. $sql[] = "ALTER TABLE $tabname $this->addCol $v";
  774. }
  775. return $sql;
  776. }
  777.  
  778. function AlterColumnSQL($tabname, $flds)
  779. {
  780. if ($this->schema) $tabname = $this->schema.'.'.$tabname;
  781. $sql = array();
  782. list($lines,$pkey) = $this->_GenFields($flds);
  783.  
  784. foreach($lines as $v) {
  785. $sql[] = "ALTER TABLE $tabname $this->alterCol $v";
  786. }
  787. return $sql;
  788. }
  789.  
  790. function DropColumnSQL($tabname, $flds)
  791. {
  792. if ($this->schema) $tabname = $this->schema.'.'.$tabname;
  793. if (!is_array($flds)) $flds = explode(',',$flds);
  794. $sql = array();
  795. foreach($flds as $v) {
  796. $sql[] = "ALTER TABLE $tabname $this->dropCol $v";
  797. }
  798. return $sql;
  799. }
  800.  
  801. function DropTableSQL($tabname)
  802. {
  803. if ($this->schema) $tabname = $this->schema.'.'.$tabname;
  804. $sql[] = sprintf($this->dropTable,$tabname);
  805. return $sql;
  806. }
  807.  
  808. /*
  809. Generate the SQL to create table. Returns an array of sql strings.
  810. */
  811. function CreateTableSQL($tabname, $flds, $tableoptions=false)
  812. {
  813. if (!$tableoptions) $tableoptions = array();
  814.  
  815. list($lines,$pkey) = $this->_GenFields($flds);
  816.  
  817. $taboptions = $this->_Options($tableoptions);
  818. if ($this->schema) $tabname = $this->schema.'.'.$tabname;
  819. $sql = $this->_TableSQL($tabname,$lines,$pkey,$taboptions);
  820.  
  821. $tsql = $this->_Triggers($tabname,$taboptions);
  822. foreach($tsql as $s) $sql[] = $s;
  823.  
  824. return $sql;
  825. }
  826.  
  827. function _GenFields($flds)
  828. {
  829. $lines = array();
  830. $pkey = array();
  831. foreach($flds as $fld) {
  832. $fld = _array_change_key_case($fld);
  833.  
  834. $fname = false;
  835. $fdefault = false;
  836. $fautoinc = false;
  837. $ftype = false;
  838. $fsize = false;
  839. $fprec = false;
  840. $fprimary = false;
  841. $fnoquote = false;
  842. $fdefts = false;
  843. $fdefdate = false;
  844. $fconstraint = false;
  845. $fnotnull = false;
  846. //-----------------
  847. // Parse attributes
  848. foreach($fld as $attr => $v) {
  849. if ($attr == 2 && is_numeric($v)) $attr = 'SIZE';
  850. else if (is_numeric($attr) && $attr > 1 && !is_numeric($v)) $attr = strtoupper($v);
  851.  
  852. switch($attr) {
  853. case '0':
  854. case 'NAME': $fname = $v; break;
  855. case '1':
  856. case 'TYPE': $ty = $v; $ftype = $this->ActualType(strtoupper($v)); break;
  857. case 'SIZE': $dotat = strpos($v,'.');
  858. if ($dotat === false) $fsize = $v;
  859. else {
  860. $fsize = substr($v,0,$dotat);
  861. $fprec = substr($v,$dotat+1);
  862. }
  863. break;
  864. case 'AUTOINCREMENT':
  865. case 'AUTO': $fautoinc = true; $fnotnull = true; break;
  866. case 'KEY':
  867. case 'PRIMARY': $fprimary = $v; $fnotnull = true; break;
  868. case 'DEFAULT': $fdefault = $v; break;
  869. case 'NOTNULL': $fnotnull = $v; break;
  870. case 'NOQUOTE': $fnoquote = $v; break;
  871. case 'DEFDATE': $fdefdate = $v; break;
  872. case 'DEFTIMESTAMP': $fdefts = $v; break;
  873. case 'CONSTRAINT': $fconstraint = $v; break;
  874. } //switch
  875. } // foreach $fld
  876.  
  877. //--------------------
  878. // VALIDATE FIELD INFO
  879. if (!strlen($fname)) {
  880. if ($this->debug) ADOConnection::outp("Undefined NAME");
  881. return false;
  882. }
  883.  
  884. if (!strlen($ftype)) {
  885. if ($this->debug) ADOConnection::outp("Undefined TYPE for field '$fname'");
  886. return false;
  887. } else
  888. $ftype = strtoupper($ftype);
  889.  
  890. $ftype = $this->_GetSize($ftype, $ty, $fsize, $fprec);
  891.  
  892. if ($fprimary) $pkey[] = $fname;
  893.  
  894. // some databases do not allow blobs to have defaults
  895. if ($ty == 'X') $fdefault = false;
  896.  
  897. //--------------------
  898. // CONSTRUCT FIELD SQL
  899. if ($fdefts) {
  900. if (substr($this->connection->databaseType,0,5) == 'mysql') {
  901. $ftype = 'TIMESTAMP';
  902. } else {
  903. $fdefault = $this->connection->sysTimeStamp;
  904. }
  905. } else if ($fdefdate) {
  906. if (substr($this->connection->databaseType,0,5) == 'mysql') {
  907. $ftype = 'TIMESTAMP';
  908. } else {
  909. $fdefault = $this->connection->sysDate;
  910. }
  911. } else if (strlen($fdefault) && !$fnoquote)
  912. if ($ty == 'C' or $ty == 'X' or
  913. ( substr($fdefault,0,1) != "'" && !is_numeric($fdefault)))
  914. if (substr($fdefault,0,1) == ' ' && substr($fdefault,strlen($fdefault)-1) == ' ')
  915. $fdefault = trim($fdefault);
  916. else
  917. $fdefault = $this->connection->qstr($fdefault);
  918. $suffix = $this->_CreateSuffix($fname,$ftype,$fnotnull,$fdefault,$fautoinc,$fconstraint);
  919.  
  920. $fname = str_pad($fname,16);
  921. $lines[] = "$fname $ftype$suffix";
  922.  
  923. } // foreach $flds
  924.  
  925.  
  926. return array($lines,$pkey);
  927. }
  928. /*
  929. GENERATE THE SIZE PART OF THE DATATYPE
  930. $ftype is the actual type
  931. $ty is the type defined originally in the DDL
  932. */
  933. function _GetSize($ftype, $ty, $fsize, $fprec)
  934. {
  935. if (strlen($fsize) && $ty != 'X' && $ty != 'B') {
  936. $ftype .= "(".$fsize;
  937. if ($fprec) $ftype .= ",".$fprec;
  938. $ftype .= ')';
  939. }
  940. return $ftype;
  941. }
  942.  
  943.  
  944. function _TableSQL($tabname,$lines,$pkey,$tableoptions)
  945. {
  946. $sql = array();
  947.  
  948. if (isset($tableoptions['REPLACE'])) $sql[] = sprintf($this->dropTable,$tabname);
  949. $s = "CREATE TABLE $tabname (\n";
  950. $s .= implode(",\n", $lines);
  951. if (sizeof($pkey)>0) {
  952. $s .= ",\n PRIMARY KEY (";
  953. $s .= implode(", ",$pkey).")";
  954. }
  955. if (isset($tableoptions['CONSTRAINTS']))
  956. $s .= "\n".$tableoptions['CONSTRAINTS'];
  957.  
  958. if (isset($tableoptions[$this->upperName.'_CONSTRAINTS']))
  959. $s .= "\n".$tableoptions[$this->upperName.'_CONSTRAINTS'];
  960.  
  961. $s .= "\n)";
  962. if (isset($tableoptions[$this->upperName])) $s .= $tableoptions[$this->upperName];
  963. $sql[] = $s;
  964.  
  965. return $sql;
  966. }
  967.  
  968. /*
  969. GENERATE TRIGGERS IF NEEDED
  970. used when table has auto-incrementing field that is emulated using triggers
  971. */
  972. function _Triggers($tabname,$taboptions)
  973. {
  974. return array();
  975. }
  976.  
  977. /*
  978. Sanitize options, so that array elements with no keys are promoted to keys
  979. */
  980. function _Options($opts)
  981. {
  982. if (!is_array($opts)) return array();
  983. $newopts = array();
  984. foreach($opts as $k => $v) {
  985. if (is_numeric($k)) $newopts[strtoupper($v)] = $v;
  986. else $newopts[strtoupper($k)] = $v;
  987. }
  988. return $newopts;
  989. }
  990. }
  991. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement