2 import(
'Dataface/Table.php');
47 if ( mysql_num_rows(mysql_query(
'show tables like \''.addslashes(
$name).
'\'',
$app->db())) > 0 ){
55 if ( strtolower($field[
'Key']) ==
'pri' ){
59 $this->
fields[
'id'] = Dataface_Table::_newSchema(
'int(11)',
'id',$this->name);
60 $this->
fields[
'id'][
'Key'] =
'PRI';
61 $this->
fields[
'id'][
'Extra'] =
'auto_increment';
70 if ( isset( $this->table ) ){
71 $keys =& $this->table->keys();
74 foreach ( array_keys($this->
fields) as $key ){
75 if ( strtolower($this->
fields[$key][
'Key']) ==
'pri' ){
87 if ( isset($this->table) )
return $this->
update();
102 $sql =
'create table `'.addslashes($this->name).
'` (
105 $sql .=
'`'.addslashes($field[
'Field']).
'` '.addslashes($field[
'Type']).
' '.addslashes($field[
'Extra']);
107 if ( !$field[
'Null'] ) $sql .=
' NOT NULL';
108 if ( $field[
'Default'] ) $sql .=
' DEFAULT \''.addslashes($field[
'Default']).
'\'';
114 $sql .=
' PRIMARY KEY (`'.implode(
'`,`',array_keys($this->
keys())).
'`)
117 $res = mysql_query($sql,
$app->db());
134 $res = mysql_query(
"show columns from `".str_replace(
'`',
'\\`',$this->table->tablename).
"`",
$app->db());
135 $existing_fields = array();
136 while ( $row = mysql_fetch_assoc($res) ){
137 $existing_fields[$row[
'Field']] = $row;
141 foreach ( $this->table->fields() as
$field ){
142 if ( !isset($existing_fields[
$field[
'Field']]) ){
146 }
else if ( $this->
compareFields($field, $existing_fields[$field[
'Field']]) !== 0 ){
147 $res = $this->
alterFieldInDB($field, $existing_fields[$field[
'Field']]);
153 $table_fields =& $this->table->fields();
154 foreach ( $existing_fields as
$field ){
155 if ( !isset($table_fields[$field[
'Field']]) ){
174 $sql =
'alter table `'.str_replace(
'`',
'\\`',$this->table->tablename).
'` ';
175 if ( strtolower(
$field[
'Type']) ==
'container') {
176 $type =
'varchar(128)';
180 $sql .=
' '.$op.
' column `'.str_replace(
'`',
'\\`',
$field[
'Field']).
'` '.$type.
' ';
181 if ( isset(
$field[
'Extra']) ) $sql .=
' '.$field[
'Extra'];
182 if ( !isset(
$field[
'Null']) ) $sql .=
' NOT NULL';
183 if ( isset(
$field[
'Default']) ) $sql .=
' DEFAULT \''.$field[
'Default'].
'\'';
184 $res = mysql_query($sql,
$app->db());
206 $res = mysql_query(
"alter table `".str_replace(
'`',
'\\`', $this->table->tablename).
"`
207 drop `".str_replace(
'`',
'\\`',
$field[
'Field']).
"`",
$app->db());
208 if ( !$res )
return PEAR::raiseError(
"Failed to remove field '$field[Field]': ".mysql_error(
$app->db()));
220 if ( isset($params[
'fields']) )
$fields = $params[
'fields'];
221 else if ( isset($this->table) )
$fields = $this->table->fields();
225 if ( !file_exists(
$path) ) mkdir(
$path,0777,
true);
226 $fieldsinipath =
$path.
'/fields.ini';
227 $fh = fopen($fieldsinipath,
'w');
231 if ( flock($fh, LOCK_EX) ){
233 $flatfield = array();
235 fwrite($fh,
'['.$field[
'name'].
"]\n");
236 foreach ( $flatfield as $key=>$value ){
237 if ( $key ==
'name' )
continue;
238 fwrite($fh, $key .
'= "'.str_replace(
'"',
'\\"', $value).
'"'.
"\n");
260 foreach (
$field as $key=>$value ){
261 $full_key = ( empty($prefix) ? $key : $prefix.
':'.$key);
262 if ( is_array($value) ){
265 $arr[$full_key] = $value;
277 $indicators = array(
'Field',
'Type',
'Null',
'Default',
'Extra');
278 foreach ($indicators as $indicator){
279 if ( @$field1[$indicator] != @$field2[$indicator] )
return 1;
289 if ( isset($this->table) )
$fields =& $this->table->fields();
306 if ( !isset(
$field[
'Field']) and !isset(
$field[
'name']) ){
314 $schema = Dataface_Table::_newSchema(
$field[
'Type'],
$field[
'name'], $this->name);
323 foreach ( array_keys($conf) as $key){
346 $path = explode(
':', $paramname);
347 foreach (
$path as $key ){
348 if ( !isset($param[$key]) )
return null;
349 $temp =& $param[$key];
362 $path = explode(
':', $paramname);
365 foreach (
$path as $key ){
366 if ( !isset($param[$key]) && $key != $last) $param[$key] = array();
367 if ( $key == $last ) {
368 $param[$key] = $paramvalue;
371 $temp =& $param[$key];
377 trigger_error(
"Something went wrong settingn parameter $paramname to value $paramvalue on line ".__LINE__.
" of file ".__FILE__, E_USER_ERROR);