Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
/**
3
 * SAP SQL Anywhere driver (previously Sybase SQL Anywhere)
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
 */
21
 
22
// security - hide paths
23
if (!defined('ADODB_DIR')) die();
24
 
25
if (!defined('_ADODB_ODBC_LAYER')) {
26
 include_once(ADODB_DIR."/drivers/adodb-odbc.inc.php");
27
}
28
 
29
if (!defined('ADODB_SYBASE_SQLANYWHERE')){
30
 
31
 define('ADODB_SYBASE_SQLANYWHERE',1);
32
 
33
 class ADODB_sqlanywhere extends ADODB_odbc
34
 {
35
	 var $databaseType = "sqlanywhere";
36
	 var $hasInsertID = true;
37
 
38
	protected function _insertID($table = '', $column = '')
39
	{
40
		 return $this->GetOne('select @@identity');
41
	}
42
 
43
  function create_blobvar($blobVarName) {
44
   $this->Execute("create variable $blobVarName long binary");
45
   return;
46
  }
47
 
48
  function drop_blobvar($blobVarName) {
49
   $this->Execute("drop variable $blobVarName");
50
   return;
51
  }
52
 
53
  function load_blobvar_from_file($blobVarName, $filename) {
54
   $chunk_size = 1000;
55
 
56
   $fd = fopen ($filename, "rb");
57
 
58
   $integer_chunks = (integer)filesize($filename) / $chunk_size;
59
   $modulus = filesize($filename) % $chunk_size;
60
   if ($modulus != 0){
61
	$integer_chunks += 1;
62
   }
63
 
64
   for($loop=1;$loop<=$integer_chunks;$loop++){
65
	$contents = fread ($fd, $chunk_size);
66
	$contents = bin2hex($contents);
67
 
68
	$hexstring = '';
69
 
70
	for($loop2=0;$loop2<strlen($contents);$loop2+=2){
71
	 $hexstring .= '\x' . substr($contents,$loop2,2);
72
	 }
73
 
74
	$hexstring = $this->qstr($hexstring);
75
 
76
	$this->Execute("set $blobVarName = $blobVarName || " . $hexstring);
77
   }
78
 
79
   fclose ($fd);
80
   return;
81
  }
82
 
83
  function load_blobvar_from_var($blobVarName, &$varName) {
84
   $chunk_size = 1000;
85
 
86
   $integer_chunks = (integer)strlen($varName) / $chunk_size;
87
   $modulus = strlen($varName) % $chunk_size;
88
   if ($modulus != 0){
89
	$integer_chunks += 1;
90
   }
91
 
92
   for($loop=1;$loop<=$integer_chunks;$loop++){
93
	$contents = substr ($varName, (($loop - 1) * $chunk_size), $chunk_size);
94
	$contents = bin2hex($contents);
95
 
96
	$hexstring = '';
97
 
98
	for($loop2=0;$loop2<strlen($contents);$loop2+=2){
99
	 $hexstring .= '\x' . substr($contents,$loop2,2);
100
	 }
101
 
102
	$hexstring = $this->qstr($hexstring);
103
 
104
	$this->Execute("set $blobVarName = $blobVarName || " . $hexstring);
105
   }
106
 
107
   return;
108
  }
109
 
110
 /*
111
  Insert a null into the blob field of the table first.
112
  Then use UpdateBlob to store the blob.
113
 
114
  Usage:
115
 
116
  $conn->Execute('INSERT INTO blobtable (id, blobcol) VALUES (1, null)');
117
  $conn->UpdateBlob('blobtable','blobcol',$blob,'id=1');
118
 */
119
  function updateBlob($table, $column, $val, $where, $blobtype = 'BLOB')
120
  {
121
   $blobVarName = 'hold_blob';
122
   $this->create_blobvar($blobVarName);
123
   $this->load_blobvar_from_var($blobVarName, $val);
124
   $this->Execute("UPDATE $table SET $column=$blobVarName WHERE $where");
125
   $this->drop_blobvar($blobVarName);
126
   return true;
127
  }
128
 }; //class
129
 
130
 class  ADORecordSet_sqlanywhere extends ADORecordSet_odbc {
131
 
132
  var $databaseType = "sqlanywhere";
133
 
134
 
135
 }; //class
136
 
137
 
138
} //define