public final function get_value_query_format() { if ($this->value === null) { return moojon_db_driver::get_null(); } else { return moojon_db_driver::get_value_query_format($this); } }
private static function get_add_column_string(moojon_base_column $column) { switch (get_class($column)) { case 'moojon_binary_column': return '`' . $column->get_name() . '` BINARY(' . $column->get_limit() . ') ' . moojon_db_driver::get_null_string($column) . ' ' . self::get_default_string($column); break; case 'moojon_boolean_column': return '`' . $column->get_name() . '` TINYINT(1) ' . self::get_null_string($column) . ' ' . self::get_default_string($column); break; case 'moojon_date_column': return '`' . $column->get_name() . '` DATE ' . self::get_null_string($column) . ' ' . self::get_default_string($column); break; case 'moojon_datetime_column': return '`' . $column->get_name() . '` DATETIME ' . self::get_null_string($column) . ' ' . self::get_default_string($column); break; case 'moojon_decimal_column': return '`' . $column->get_name() . '` DECIMAL(' . $column->get_limit() . ', ' . $column->get_decimals() . ') ' . self::get_null_string($column) . ' ' . self::get_default_string($column); break; case 'moojon_float_column': return '`' . $column->get_name() . '` FLOAT(' . $column->get_limit() . ', ' . $column->get_decimals() . ') ' . self::get_null_string($column) . ' ' . self::get_default_string($column); break; case 'moojon_integer_column': return '`' . $column->get_name() . '` INTEGER(' . $column->get_limit() . ') ' . self::get_null_string($column) . ' ' . self::get_default_string($column); break; case 'moojon_primary_key': return '`' . $column->get_name() . '` INTEGER(' . $column->get_limit() . ') ' . self::get_null_string($column) . ' ' . self::get_default_string($column) . ' ' . $column->get_options(); break; case 'moojon_string_column': return '`' . $column->get_name() . '` VARCHAR(' . $column->get_limit() . ') ' . self::get_null_string($column) . ' ' . self::get_default_string($column); break; case 'moojon_text_column': $binary_string = !$column->get_binary() ? '' : 'BINARY '; return '`' . $column->get_name() . "` TEXT {$binary_string}" . self::get_null_string($column); break; case 'moojon_time_column': return '`' . $column->get_name() . '` TIME ' . self::get_null_string($column) . ' ' . self::get_default_string($column); break; case 'moojon_timestamp_column': return '`' . $column->get_name() . '` TIMESTAMP ' . self::get_null_string($column) . ' ' . self::get_default_string($column); break; default: throw new moojon_exception('create_table can only accept columns of moojon_base_column (' . get_class($column) . ' found).'); break; } }
public static function model($table) { moojon_files::attempt_mkdir(moojon_paths::get_project_models_directory()); moojon_files::attempt_mkdir(moojon_paths::get_project_base_models_directory()); $model = moojon_inflect::singularize($table); $swaps = array('model' => $model); $model_path = moojon_paths::get_project_models_directory() . "{$model}.model.class.php"; self::run(moojon_paths::get_moojon_templates_directory() . 'model.template', $model_path, $swaps, false, false); $swaps['columns'] = moojon_db_driver::get_add_columns($table); $swaps['read_all_bys'] = moojon_db_driver::get_read_all_bys($table); $swaps['read_bys'] = moojon_db_driver::get_read_bys($table); $swaps['destroy_bys'] = moojon_db_driver::get_destroy_bys($table); $swaps['read_or_create_bys'] = moojon_db_driver::get_read_or_create_bys($table); self::run(moojon_paths::get_moojon_templates_directory() . 'base.model.template', moojon_paths::get_project_base_models_directory() . "base.{$model}.model.class.php", $swaps, true, false); }
protected final function get_order($order = null, $cascade = false) { $order = moojon_db_driver::escapes($order, $this->get_table(), $this->get_column_names()); if (!$order) { $order_columns = $this->get_order_column_names(); if (count($order_columns)) { foreach ($order_columns as $key => $value) { $order_columns[$key] = $order_columns[$key] . ' ' . $this->order_direction; } $order = implode(', ', $order_columns); } else { $order = $this->order_column . ' ' . $this->order_direction; } $order = moojon_db_driver::escapes($order, $this->get_table(), $this->get_column_names()); } if ($cascade) { foreach ($this->get_relationships() as $relationship) { $instance = self::factory($relationship->get_foreign_class()); $order = moojon_db_driver::escapes($order, $instance->get_table(), $instance->get_column_names()); } } return $order; }
public static function count($table, $column, $where = null, $param_values = array(), $param_data_types = array()) { $return = self::run(self::prepare(moojon_db_driver::count($table, $column, $where)), $param_values, $param_data_types); return $return[0]; }
public final function get_param_data_types(moojon_base_model $accessor) { return moojon_db_driver::get_relationship_param_data_types($this, $accessor); }