Project

General

Profile

« Previous | Next » 

Revision 1763

Added by Dietmar about 12 years ago

  1. fixed methode index_add in WbDatabase, always faild

View differences:

branches/2.8.x/CHANGELOG
13 13

  
14 14

  
15 15

  
16
22 Sep-2012 Build 1763 Dietmar Woellbrink (Luisehahne)
17
# fixed methode index_add in WbDatabase, always faild
16 18
18 Sep-2012 Build 1762 Dietmar Woellbrink (Luisehahne)
17 19
# fixed upgrade-script wrong Adding/updating page_icon_dir to settings table
18 20
18 Sep-2012 Build 1761 Dietmar Woellbrink (Luisehahne)
branches/2.8.x/wb/admin/interface/version.php
51 51

  
52 52
// check if defined to avoid errors during installation (redirect to admin panel fails if PHP error/warnings are enabled)
53 53
if(!defined('VERSION')) define('VERSION', '2.8.3');
54
if(!defined('REVISION')) define('REVISION', '1762');
54
if(!defined('REVISION')) define('REVISION', '1763');
55 55
if(!defined('SP')) define('SP', '');
branches/2.8.x/wb/framework/WbDatabase.php
31 31

  
32 32

  
33 33
class WbDatabase {
34
	
34

  
35 35
	private static $_oInstances = array();
36 36

  
37 37
	private $_db_handle = null; // readonly from outside
......
111 111
		}
112 112
		return $this->connected;
113 113
	}
114
	
114

  
115 115
	// Disconnect from the database
116 116
	public function disconnect() {
117 117
		if($this->connected==true) {
......
121 121
			return false;
122 122
		}
123 123
	}
124
	
124

  
125 125
	// Run a query
126 126
	public function query($statement) {
127 127
		$this->iQueryCount++;
......
148 148
			return $result;
149 149
		}
150 150
	}
151
	
151

  
152 152
	// Set the DB error
153 153
	public function set_error($message = null) {
154 154
		global $TABLE_DOES_NOT_EXIST, $TABLE_UNKNOWN;
......
159 159
			$this->error_type = $TABLE_UNKNOWN;
160 160
		}
161 161
	}
162
	
162

  
163 163
	// Return true if there was an error
164 164
	public function is_error() {
165 165
		return (!empty($this->error)) ? true : false;
166 166
	}
167
	
167

  
168 168
	// Return the error
169 169
	public function get_error() {
170 170
		return $this->error;
......
239 239
			return ($keys == $number_fields);
240 240
		}
241 241
	}
242

  
242 243
/*
243 244
 * @param string $table_name: full name of the table (incl. TABLE_PREFIX)
244 245
 * @param string $field_name: name of the field to add
......
299 300

  
300 301
/*
301 302
 * @param string $table_name: full name of the table (incl. TABLE_PREFIX)
302
 * @param string $index_name: name of the new index
303
 * @param string $index_name: name of the new index (empty string for PRIMARY)
303 304
 * @param string $field_list: comma seperated list of fields for this index
304
 * @param string $index_type: kind of index (UNIQUE, PRIMARY, '')
305
 * @param string $index_type: kind of index (PRIMARY, UNIQUE, KEY, FULLTEXT)
305 306
 * @return bool: true if successful, otherwise false and error will be set
306 307
 */
307
	public function index_add($table_name, $index_name, $field_list, $index_type = '')
308
	{
309
		$retval = false;
310
		$field_list = str_replace(' ', '', $field_list);
311
		$field_list = explode(',', $field_list);
312
		$number_fields = sizeof($field_list);
313
		$field_list = '`'.implode('`,`', $field_list).'`';
314
		if( $this->index_exists($table_name, $index_name, $number_fields) ||
315
		    $this->index_exists($table_name, $index_name))
316
		{
317
			$sql  = 'ALTER TABLE `'.$table_name.'` ';
318
			$sql .= 'DROP INDEX `'.$index_name.'`';
319
			if( $this->query($sql, $this->_db_handle))
320
			{
321
				$sql  = 'ALTER TABLE `'.$table_name.'` ';
322
				$sql .= 'ADD '.$index_type.' `'.$index_name.'` ( '.$field_list.' ); ';
323
				if( $this->query($sql, $this->_db_handle)) { $retval = true; }
324
			}
325
		}
326
		return $retval;
327
	}
308
     public function index_add($table_name, $index_name, $field_list, $index_type = 'KEY')
309
     {
310
        $retval = false;
311
        $field_list = str_replace(' ', '', $field_list);
312
        $field_list = explode(',', $field_list);
313
        $number_fields = sizeof($field_list);
314
        $field_list = '`'.implode('`,`', $field_list).'`';
315
        $index_name = $index_type == 'PRIMARY' ? $index_type : $index_name;
316
        if( $this->index_exists($table_name, $index_name, $number_fields) ||
317
            $this->index_exists($table_name, $index_name))
318
        {
319
            $sql  = 'ALTER TABLE `'.$table_name.'` ';
320
            $sql .= 'DROP INDEX `'.$index_name.'`';
321
            if( !$this->query($sql, $this->_db_handle)) { return false; }
322
        }
323
        $sql  = 'ALTER TABLE `'.$table_name.'` ';
324
        $sql .= 'ADD '.$index_type.' ';
325
        $sql .= $index_type == 'PRIMARY' ? 'KEY ' : '`'.$index_name.'` ';
326
        $sql .= '( '.$field_list.' ); ';
327
        if( $this->query($sql, $this->_db_handle)) { $retval = true; }
328
        return $retval;
329
    }
328 330

  
329 331
/*
330 332
 * @param string $table_name: full name of the table (incl. TABLE_PREFIX)
......
341 343
		}
342 344
		return $retval;
343 345
	}
346

  
344 347
/**
345 348
 * Import a standard *.sql dump file
346 349
 * @param string $sSqlDump link to the sql-dumpfile
......
419 422
		$this->error = mysql_error($this->_db_handle);
420 423
		return $this->result;
421 424
	}
422
	
425

  
423 426
	// Fetch num rows
424 427
	function numRows() {
425 428
		return mysql_num_rows($this->result);
......
452 455
	}
453 456

  
454 457
}
458

  
455 459
/* this function is placed inside this file temporarely until a better place is found */
456 460
/*  function to update a var/value-pair(s) in table ****************************
457 461
 *  nonexisting keys are inserted

Also available in: Unified diff