wordpress/wp-content/plugins/sqlite-integration/query_alter.class.php
/**
	 * Function to handle CHANGE COLUMN.
	 *
	 * @access private
	 * @param array of string $queries
	 * @return string|array of string
	 */
Function to handle CHANGE COLUMN.
@access private
@param array of string $queries
@return string|array of string
Function to handle CHANGE COLUMN . @access private @param array of string $queries @return string|array of string
private function handle_change_command($queries) {
		$col_check       = false;
		$old_fields      = '';
		$new_fields      = '';
		$tokenized_query = $queries;
		$temp_table      = 'temp_'.$tokenized_query['table_name'];
		if (isset($tokenized_query['new_column'])) {
			$column_name = $tokenized_query['new_column'];
		} else {
			$column_name = $tokenized_query['old_column'];
		}
		$column_def = $this->convert_field_types($column_name, $tokenized_query['column_def']);
		$_wpdb = new PDODB();
		$col_obj = $_wpdb->get_results("SHOW COLUMNS FROM {$tokenized_query['table_name']}");
		foreach ($col_obj as $col) {
			if (stripos($col->Field, $tokenized_query['old_column']) !== false) $col_check = true;
			$old_fields .= $col->Field . ',';
		}
		if ($col_check == false) {
			$_wpdb = null;
			return 'SELECT 1=1';
		}
		$old_fields = rtrim($old_fields, ',');
		$new_fields = str_ireplace($tokenized_query['old_column'], $column_name, $old_fields);
		$query_obj  = $_wpdb->get_results("SELECT sql FROM sqlite_master WHERE tbl_name='{$tokenized_query['table_name']}'");
		$_wpdb = null;
		for ($i = 0; $i < count($query_obj); $i++) {
			$index_queries[$i] = $query_obj[$i]->sql;
		}
		$create_query = array_shift($index_queries);
		$create_query = preg_replace("/{$tokenized_query['table_name']}/i", $temp_table, $create_query);
		if (preg_match("/\\b{$tokenized_query['old_column']}\\s*(.+?)(?=,)/ims", $create_query, $match)) {
			if (stripos(trim($match[1]), $column_def) !== false) {
				return 'SELECT 1=1';
			} else {
				$create_query = preg_replace("/\\b{$tokenized_query['old_column']}\\s*.+?(?=,)/ims", "{$column_name} {$column_def}", $create_query, 1);
			}
		} elseif (preg_match("/\\b{$tokenized_query['old_column']}\\s*(.+?)(?=\))/ims", $create_query, $match)) {
			if (stripos(trim($match[1]), $column_def) !== false) {
				return 'SELECT 1=1';
			} else {
				$create_query = preg_replace("/\\b{$tokenized_query['old_column']}\\s*.*(?=\))/ims", "{$column_name} {$column_def}", $create_query, 1);
			}
		}
		$query[] = $create_query;
		$query[] = "INSERT INTO $temp_table ($new_fields) SELECT $old_fields FROM {$tokenized_query['table_name']}";
		$query[] = "DROP TABLE IF EXISTS {$tokenized_query['table_name']}";
		$query[] = "ALTER TABLE $temp_table RENAME TO {$tokenized_query['table_name']}";
		foreach ($index_queries as $index) {
			$query[] = $index;
		}
		return $query;
	}
private function handle_change_command ( $ queries ) { $ col_check = false ; $ old_fields = '' ; $ new_fields = '' ; $ tokenized_query = $ queries ; $ temp_table = 'temp_' . $ tokenized_query [ 'table_name' ] ; if ( isset ( $ tokenized_query [ 'new_column' ] ) ) { $ column_name = $ tokenized_query [ 'new_column' ] ; } else { $ column_name = $ tokenized_query [ 'old_column' ] ; } $ column_def = $ this -> convert_field_types ( $ column_name , $ tokenized_query [ 'column_def' ] ) ; $ _wpdb = new PDODB ( ) ; $ col_obj = $ _wpdb -> get_results ( " SHOW COLUMNS FROM  { $ tokenized_query [ 'table_name' ] } " ) ; foreach ( $ col_obj as $ col ) { if ( stripos ( $ col -> Field , $ tokenized_query [ 'old_column' ] ) !== false ) $ col_check = true ; $ old_fields .= $ col -> Field . ',' ; } if ( $ col_check == false ) { $ _wpdb = null ; return 'SELECT 1=1' ; } $ old_fields = rtrim ( $ old_fields , ',' ) ; $ new_fields = str_ireplace ( $ tokenized_query [ 'old_column' ] , $ column_name , $ old_fields ) ; $ query_obj = $ _wpdb -> get_results ( " SELECT sql FROM sqlite_master WHERE tbl_name=' { $ tokenized_query [ 'table_name' ] } ' " ) ; $ _wpdb = null ; for ( $ i = 0 ; $ i < count ( $ query_obj ) ; $ i ++ ) { $ index_queries [ $ i ] = $ query_obj [ $ i ] -> sql ; } $ create_query = array_shift ( $ index_queries ) ; $ create_query = preg_replace ( " / { $ tokenized_query [ 'table_name' ] } /i " , $ temp_table , $ create_query ) ; if ( preg_match ( " / \\ b { $ tokenized_query [ 'old_column' ] } \\ s*(.+?)(?=,)/ims " , $ create_query , $ match ) ) { if ( stripos ( trim ( $ match [ 1 ] ) , $ column_def ) !== false ) { return 'SELECT 1=1' ; } else { $ create_query = preg_replace ( " / \\ b { $ tokenized_query [ 'old_column' ] } \\ s*.+?(?=,)/ims " , " { $ column_name } { $ column_def } " , $ create_query , 1 ) ; } } elseif ( preg_match ( " / \\ b { $ tokenized_query [ 'old_column' ] } \\ s*(.+?)(?=\))/ims " , $ create_query , $ match ) ) { if ( stripos ( trim ( $ match [ 1 ] ) , $ column_def ) !== false ) { return 'SELECT 1=1' ; } else { $ create_query = preg_replace ( " / \\ b { $ tokenized_query [ 'old_column' ] } \\ s*.*(?=\))/ims " , " { $ column_name } { $ column_def } " , $ create_query , 1 ) ; } } $ query [ ] = $ create_query ; $ query [ ] = " INSERT INTO  $ temp_table  ( $ new_fields ) SELECT  $ old_fields  FROM  { $ tokenized_query [ 'table_name' ] } " ; $ query [ ] = " DROP TABLE IF EXISTS  { $ tokenized_query [ 'table_name' ] } " ; $ query [ ] = " ALTER TABLE  $ temp_table  RENAME TO  { $ tokenized_query [ 'table_name' ] } " ; foreach ( $ index_queries as $ index ) { $ query [ ] = $ index ; } return $ query ; }
Function to handle CHANGE COLUMN.
Function to handle CHANGE COLUMN .