Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 310 and 401] [Versions 311 and 401] [Versions 39 and 401]

   1  <?php
   2  /**
   3   * SAP Adaptive Server Enterprise driver (formerly Sybase ASE)
   4   *
   5   * This file is part of ADOdb, a Database Abstraction Layer library for PHP.
   6   *
   7   * @package ADOdb
   8   * @link https://adodb.org Project's web site and documentation
   9   * @link https://github.com/ADOdb/ADOdb Source code and issue tracker
  10   *
  11   * The ADOdb Library is dual-licensed, released under both the BSD 3-Clause
  12   * and the GNU Lesser General Public Licence (LGPL) v2.1 or, at your option,
  13   * any later version. This means you can use it in proprietary products.
  14   * See the LICENSE.md file distributed with this source code for details.
  15   * @license BSD-3-Clause
  16   * @license LGPL-2.1-or-later
  17   *
  18   * @copyright 2000-2013 John Lim
  19   * @copyright 2014 Damien Regad, Mark Newnham and the ADOdb community
  20   * @author Cristian Marin, Interakt Online <cristic@interaktonline.com>
  21   */
  22  
  23  require_once ADODB_DIR."/drivers/adodb-sybase.inc.php";
  24  
  25  class ADODB_sybase_ase extends ADODB_sybase {
  26   	 var $databaseType = "sybase_ase";
  27  
  28  	  var $metaTablesSQL="SELECT sysobjects.name FROM sysobjects, sysusers WHERE sysobjects.type='U' AND sysobjects.uid = sysusers.uid";
  29  	  var $metaColumnsSQL = "SELECT syscolumns.name AS field_name, systypes.name AS type, systypes.length AS width FROM sysobjects, syscolumns, systypes WHERE sysobjects.name='%s' AND syscolumns.id = sysobjects.id AND systypes.type=syscolumns.type";
  30  	  var $metaDatabasesSQL ="SELECT a.name FROM master.dbo.sysdatabases a, master.dbo.syslogins b WHERE a.suid = b.suid and a.name like '%' and a.name != 'tempdb' and a.status3 != 256  order by 1";
  31  
  32  	 // split the Views, Tables and procedures.
  33  	function MetaTables($ttype=false,$showSchema=false,$mask=false)
  34  	 {
  35  	 	 $false = false;
  36  	 	 if ($this->metaTablesSQL) {
  37  	 	 	 // complicated state saving by the need for backward compat
  38  
  39  	 	 	 if ($ttype == 'VIEWS'){
  40  	 	 	 	 	 	 $sql = str_replace('U', 'V', $this->metaTablesSQL);
  41  	 	 	 }elseif (false === $ttype){
  42  	 	 	 	 	 	 $sql = str_replace('U',"U' OR type='V", $this->metaTablesSQL);
  43  	 	 	 }else{ // TABLES OR ANY OTHER
  44  	 	 	 	 	 	 $sql = $this->metaTablesSQL;
  45  	 	 	 }
  46  	 	 	 $rs = $this->Execute($sql);
  47  
  48  	 	 	 if ($rs === false || !method_exists($rs, 'GetArray')){
  49  	 	 	 	 	 return $false;
  50  	 	 	 }
  51  	 	 	 $arr = $rs->GetArray();
  52  
  53  	 	 	 $arr2 = array();
  54  	 	 	 foreach($arr as $key=>$value){
  55  	 	 	 	 	 $arr2[] = trim($value['name']);
  56  	 	 	 }
  57  	 	 	 return $arr2;
  58  	 	 }
  59  	 	 return $false;
  60  	 }
  61  
  62  	function MetaDatabases()
  63  	 {
  64  	 	 	 $arr = array();
  65  	 	 	 if ($this->metaDatabasesSQL!='') {
  66  	 	 	 	 $rs = $this->Execute($this->metaDatabasesSQL);
  67  	 	 	 	 if ($rs && !$rs->EOF){
  68  	 	 	 	 	 while (!$rs->EOF){
  69  	 	 	 	 	 	 $arr[] = $rs->Fields('name');
  70  	 	 	 	 	 	 $rs->MoveNext();
  71  	 	 	 	 	 }
  72  	 	 	 	 	 return $arr;
  73  	 	 	 	 }
  74  	 	 	 }
  75  	 	 	 return false;
  76  	 }
  77  
  78  	 // fix a bug which prevent the metaColumns query to be executed for Sybase ASE
  79  	function MetaColumns($table,$upper=false)
  80  	 {
  81  	 	 $false = false;
  82  	 	 if (!empty($this->metaColumnsSQL)) {
  83  
  84  	 	 	 $rs = $this->Execute(sprintf($this->metaColumnsSQL,$table));
  85  	 	 	 if ($rs === false) return $false;
  86  
  87  	 	 	 $retarr = array();
  88  	 	 	 while (!$rs->EOF) {
  89  	 	 	 	 $fld = new ADOFieldObject();
  90  	 	 	 	 $fld->name = $rs->Fields('field_name');
  91  	 	 	 	 $fld->type = $rs->Fields('type');
  92  	 	 	 	 $fld->max_length = $rs->Fields('width');
  93  	 	 	 	 $retarr[strtoupper($fld->name)] = $fld;
  94  	 	 	 	 $rs->MoveNext();
  95  	 	 	 }
  96  	 	 	 $rs->Close();
  97  	 	 	 return $retarr;
  98  	 	 }
  99  	 	 return $false;
 100  	 }
 101  
 102  	function getProcedureList($schema)
 103  	 {
 104  	 	 	 return false;
 105  	 }
 106  
 107  	function ErrorMsg()
 108  	 {
 109  	 	 if (!function_exists('sybase_connect')){
 110  	 	 	 	 return 'Your PHP doesn\'t contain the Sybase connection module!';
 111  	 	 }
 112  	 	 return parent::ErrorMsg();
 113  	 }
 114  }
 115  
 116  class adorecordset_sybase_ase extends ADORecordset_sybase {
 117  	 var $databaseType = "sybase_ase";
 118  }