my-simon 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +3 -20
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/my-simon.gemspec +3 -78
- metadata +2 -77
- data/DOC/Launch Check List.docx +0 -0
- data/DOC/Launch Check List.pdf +0 -0
- data/build/rakefile.rb +0 -12
- data/config.rb +0 -24
- data/scaffolding/simon/controller.tpl +0 -9
- data/scaffolding/simon/model.tpl +0 -10
- data/scaffolding/simon/view.tpl +0 -5
- data/scaffolding/standards/html_template.html +0 -44
- data/scaffolding/standards/html_template.php +0 -44
- data/scaffolding/standards/jquery_plugin_template.js +0 -45
- data/scaffolding/standards/js_template.js +0 -43
- data/www/.htaccess +0 -488
- data/www/404.html +0 -32
- data/www/crossdomain.xml +0 -25
- data/www/favicon.ico +0 -0
- data/www/index.php +0 -17
- data/www/lib/js/homePage.js +0 -43
- data/www/lib/js/jquery/JQbook.js +0 -809
- data/www/lib/js/jquery/jquery-1.8.0.min.js +0 -27
- data/www/lib/js/jquery/jquery.alphanumeric.js +0 -82
- data/www/lib/js/jquery/jquery.cookie.js +0 -96
- data/www/lib/js/jquery/jquery.easing.1.3.js +0 -207
- data/www/lib/js/main.js +0 -117
- data/www/lib/js/master.js +0 -6
- data/www/lib/js/plugins/handlebars-1.0.rc.1.js +0 -1920
- data/www/lib/js/plugins/modernizr-1.7.min.js +0 -2
- data/www/lib/js/plugins/swfobject.js +0 -777
- data/www/lib/js/plugins_mod/README.txt +0 -3
- data/www/lib/php/app.php +0 -53
- data/www/lib/php/controller/index.php +0 -10
- data/www/lib/php/controller/regex.php +0 -23
- data/www/lib/php/model/Book.php +0 -8
- data/www/lib/php/model/Model.php +0 -8
- data/www/lib/php/plugins/php-activerecord/ActiveRecord.php +0 -44
- data/www/lib/php/plugins/php-activerecord/lib/CallBack.php +0 -226
- data/www/lib/php/plugins/php-activerecord/lib/Column.php +0 -155
- data/www/lib/php/plugins/php-activerecord/lib/Config.php +0 -288
- data/www/lib/php/plugins/php-activerecord/lib/Connection.php +0 -456
- data/www/lib/php/plugins/php-activerecord/lib/ConnectionManager.php +0 -38
- data/www/lib/php/plugins/php-activerecord/lib/DateTime.php +0 -45
- data/www/lib/php/plugins/php-activerecord/lib/Exceptions.php +0 -137
- data/www/lib/php/plugins/php-activerecord/lib/Expressions.php +0 -183
- data/www/lib/php/plugins/php-activerecord/lib/Inflector.php +0 -115
- data/www/lib/php/plugins/php-activerecord/lib/Model.php +0 -1673
- data/www/lib/php/plugins/php-activerecord/lib/Reflections.php +0 -86
- data/www/lib/php/plugins/php-activerecord/lib/Relationship.php +0 -637
- data/www/lib/php/plugins/php-activerecord/lib/SQLBuilder.php +0 -396
- data/www/lib/php/plugins/php-activerecord/lib/Serialization.php +0 -302
- data/www/lib/php/plugins/php-activerecord/lib/Singleton.php +0 -57
- data/www/lib/php/plugins/php-activerecord/lib/Table.php +0 -547
- data/www/lib/php/plugins/php-activerecord/lib/Utils.php +0 -351
- data/www/lib/php/plugins/php-activerecord/lib/Validations.php +0 -833
- data/www/lib/php/plugins/php-activerecord/lib/adapters/MysqlAdapter.php +0 -73
- data/www/lib/php/plugins/php-activerecord/lib/adapters/OciAdapter.php +0 -121
- data/www/lib/php/plugins/php-activerecord/lib/adapters/PgsqlAdapter.php +0 -104
- data/www/lib/php/plugins/php-activerecord/lib/adapters/SqliteAdapter.php +0 -81
- data/www/lib/php/system/Config.php +0 -174
- data/www/lib/php/system/config.routes.php +0 -29
- data/www/lib/php/system/router.php +0 -220
- data/www/lib/php/template/footer.php +0 -59
- data/www/lib/php/template/header.php +0 -74
- data/www/lib/php/view/index.php +0 -5
- data/www/media/images/facebook_share.jpg +0 -0
- data/www/robots.txt +0 -5
- data/www/sandbox/readme.txt +0 -3
- data/www/sass/javascript.scss +0 -1
- data/www/sass/layout.scss +0 -128
- data/www/sass/master.scss +0 -4
- data/www/sass/reset.scss +0 -47
- data/www/sass/typography.scss +0 -24
- data/www/styles/javascript.css +0 -1
- data/www/styles/layout.css +0 -186
- data/www/styles/master.css +0 -4
- data/www/styles/reset.css +0 -60
- data/www/styles/typography.css +0 -24
@@ -1,288 +0,0 @@
|
|
1
|
-
<?php
|
2
|
-
/**
|
3
|
-
* @package ActiveRecord
|
4
|
-
*/
|
5
|
-
namespace ActiveRecord;
|
6
|
-
use Closure;
|
7
|
-
|
8
|
-
/**
|
9
|
-
* Manages configuration options for ActiveRecord.
|
10
|
-
*
|
11
|
-
* <code>
|
12
|
-
* ActiveRecord::initialize(function($cfg) {
|
13
|
-
* $cfg->set_model_home('models');
|
14
|
-
* $cfg->set_connections(array(
|
15
|
-
* 'development' => 'mysql://user:pass@development.com/awesome_development',
|
16
|
-
* 'production' => 'mysql://user:pass@production.com/awesome_production'));
|
17
|
-
* });
|
18
|
-
* </code>
|
19
|
-
*
|
20
|
-
* @package ActiveRecord
|
21
|
-
*/
|
22
|
-
class Config extends Singleton
|
23
|
-
{
|
24
|
-
/**
|
25
|
-
* Name of the connection to use by default.
|
26
|
-
*
|
27
|
-
* <code>
|
28
|
-
* ActiveRecord\Config::initialize(function($cfg) {
|
29
|
-
* $cfg->set_model_directory('/your/app/models');
|
30
|
-
* $cfg->set_connections(array(
|
31
|
-
* 'development' => 'mysql://user:pass@development.com/awesome_development',
|
32
|
-
* 'production' => 'mysql://user:pass@production.com/awesome_production'));
|
33
|
-
* });
|
34
|
-
* </code>
|
35
|
-
*
|
36
|
-
* This is a singleton class so you can retrieve the {@link Singleton} instance by doing:
|
37
|
-
*
|
38
|
-
* <code>
|
39
|
-
* $config = ActiveRecord\Config::instance();
|
40
|
-
* </code>
|
41
|
-
*
|
42
|
-
* @var string
|
43
|
-
*/
|
44
|
-
private $default_connection = 'development';
|
45
|
-
|
46
|
-
/**
|
47
|
-
* Contains the list of database connection strings.
|
48
|
-
*
|
49
|
-
* @var array
|
50
|
-
*/
|
51
|
-
private $connections = array();
|
52
|
-
|
53
|
-
/**
|
54
|
-
* Directory for the auto_loading of model classes.
|
55
|
-
*
|
56
|
-
* @see activerecord_autoload
|
57
|
-
* @var string
|
58
|
-
*/
|
59
|
-
private $model_directory;
|
60
|
-
|
61
|
-
/**
|
62
|
-
* Switch for logging.
|
63
|
-
*
|
64
|
-
* @var bool
|
65
|
-
*/
|
66
|
-
private $logging = false;
|
67
|
-
|
68
|
-
/**
|
69
|
-
* Contains a Logger object that must impelement a log() method.
|
70
|
-
*
|
71
|
-
* @var object
|
72
|
-
*/
|
73
|
-
private $logger;
|
74
|
-
|
75
|
-
/**
|
76
|
-
* The format to serialize DateTime values into.
|
77
|
-
*
|
78
|
-
* @var string
|
79
|
-
*/
|
80
|
-
private $date_format = \DateTime::ISO8601;
|
81
|
-
|
82
|
-
/**
|
83
|
-
* Allows config initialization using a closure.
|
84
|
-
*
|
85
|
-
* This method is just syntatic sugar.
|
86
|
-
*
|
87
|
-
* <code>
|
88
|
-
* ActiveRecord\Config::initialize(function($cfg) {
|
89
|
-
* $cfg->set_model_directory('/path/to/your/model_directory');
|
90
|
-
* $cfg->set_connections(array(
|
91
|
-
* 'development' => 'mysql://username:password@127.0.0.1/database_name'));
|
92
|
-
* });
|
93
|
-
* </code>
|
94
|
-
*
|
95
|
-
* You can also initialize by grabbing the singleton object:
|
96
|
-
*
|
97
|
-
* <code>
|
98
|
-
* $cfg = ActiveRecord\Config::instance();
|
99
|
-
* $cfg->set_model_directory('/path/to/your/model_directory');
|
100
|
-
* $cfg->set_connections(array('development' =>
|
101
|
-
* 'mysql://username:password@localhost/database_name'));
|
102
|
-
* </code>
|
103
|
-
*
|
104
|
-
* @param Closure $initializer A closure
|
105
|
-
* @return void
|
106
|
-
*/
|
107
|
-
public static function initialize(Closure $initializer)
|
108
|
-
{
|
109
|
-
$initializer(parent::instance());
|
110
|
-
}
|
111
|
-
|
112
|
-
/**
|
113
|
-
* Sets the list of database connection strings.
|
114
|
-
*
|
115
|
-
* <code>
|
116
|
-
* $config->set_connections(array(
|
117
|
-
* 'development' => 'mysql://username:password@127.0.0.1/database_name'));
|
118
|
-
* </code>
|
119
|
-
*
|
120
|
-
* @param array $connections Array of connections
|
121
|
-
* @param string $default_connection Optionally specify the default_connection
|
122
|
-
* @return void
|
123
|
-
* @throws ActiveRecord\ConfigException
|
124
|
-
*/
|
125
|
-
public function set_connections($connections, $default_connection=null)
|
126
|
-
{
|
127
|
-
if (!is_array($connections))
|
128
|
-
throw new ConfigException("Connections must be an array");
|
129
|
-
|
130
|
-
if ($default_connection)
|
131
|
-
$this->set_default_connection($default_connection);
|
132
|
-
|
133
|
-
$this->connections = $connections;
|
134
|
-
}
|
135
|
-
|
136
|
-
/**
|
137
|
-
* Returns the connection strings array.
|
138
|
-
*
|
139
|
-
* @return array
|
140
|
-
*/
|
141
|
-
public function get_connections()
|
142
|
-
{
|
143
|
-
return $this->connections;
|
144
|
-
}
|
145
|
-
|
146
|
-
/**
|
147
|
-
* Returns a connection string if found otherwise null.
|
148
|
-
*
|
149
|
-
* @param string $name Name of connection to retrieve
|
150
|
-
* @return string connection info for specified connection name
|
151
|
-
*/
|
152
|
-
public function get_connection($name)
|
153
|
-
{
|
154
|
-
if (array_key_exists($name, $this->connections))
|
155
|
-
return $this->connections[$name];
|
156
|
-
|
157
|
-
return null;
|
158
|
-
}
|
159
|
-
|
160
|
-
/**
|
161
|
-
* Returns the default connection string or null if there is none.
|
162
|
-
*
|
163
|
-
* @return string
|
164
|
-
*/
|
165
|
-
public function get_default_connection_string()
|
166
|
-
{
|
167
|
-
return array_key_exists($this->default_connection,$this->connections) ?
|
168
|
-
$this->connections[$this->default_connection] : null;
|
169
|
-
}
|
170
|
-
|
171
|
-
/**
|
172
|
-
* Returns the name of the default connection.
|
173
|
-
*
|
174
|
-
* @return string
|
175
|
-
*/
|
176
|
-
public function get_default_connection()
|
177
|
-
{
|
178
|
-
return $this->default_connection;
|
179
|
-
}
|
180
|
-
|
181
|
-
/**
|
182
|
-
* Set the name of the default connection.
|
183
|
-
*
|
184
|
-
* @param string $name Name of a connection in the connections array
|
185
|
-
* @return void
|
186
|
-
*/
|
187
|
-
public function set_default_connection($name)
|
188
|
-
{
|
189
|
-
$this->default_connection = $name;
|
190
|
-
}
|
191
|
-
|
192
|
-
/**
|
193
|
-
* Sets the directory where models are located.
|
194
|
-
*
|
195
|
-
* @param string $dir Directory path containing your models
|
196
|
-
* @return void
|
197
|
-
* @throws ConfigException if specified directory was not found
|
198
|
-
*/
|
199
|
-
public function set_model_directory($dir)
|
200
|
-
{
|
201
|
-
if (!file_exists($dir))
|
202
|
-
throw new ConfigException("Invalid or non-existent directory: $dir");
|
203
|
-
|
204
|
-
$this->model_directory = $dir;
|
205
|
-
}
|
206
|
-
|
207
|
-
/**
|
208
|
-
* Returns the model directory.
|
209
|
-
*
|
210
|
-
* @return string
|
211
|
-
*/
|
212
|
-
public function get_model_directory()
|
213
|
-
{
|
214
|
-
return $this->model_directory;
|
215
|
-
}
|
216
|
-
|
217
|
-
/**
|
218
|
-
* Turn on/off logging
|
219
|
-
*
|
220
|
-
* @param boolean $bool
|
221
|
-
* @return void
|
222
|
-
*/
|
223
|
-
public function set_logging($bool)
|
224
|
-
{
|
225
|
-
$this->logging = (bool)$bool;
|
226
|
-
}
|
227
|
-
|
228
|
-
/**
|
229
|
-
* Sets the logger object for future SQL logging
|
230
|
-
*
|
231
|
-
* @param object $logger
|
232
|
-
* @return void
|
233
|
-
* @throws ConfigException if Logger objecct does not implement public log()
|
234
|
-
*/
|
235
|
-
public function set_logger($logger)
|
236
|
-
{
|
237
|
-
$klass = Reflections::instance()->add($logger)->get($logger);
|
238
|
-
|
239
|
-
if (!$klass->getMethod('log') || !$klass->getMethod('log')->isPublic())
|
240
|
-
throw new ConfigException("Logger object must implement a public log method");
|
241
|
-
|
242
|
-
$this->logger = $logger;
|
243
|
-
}
|
244
|
-
|
245
|
-
/**
|
246
|
-
* Return whether or not logging is on
|
247
|
-
*
|
248
|
-
* @return boolean
|
249
|
-
*/
|
250
|
-
public function get_logging()
|
251
|
-
{
|
252
|
-
return $this->logging;
|
253
|
-
}
|
254
|
-
|
255
|
-
/**
|
256
|
-
* Returns the logger
|
257
|
-
*
|
258
|
-
* @return object
|
259
|
-
*/
|
260
|
-
public function get_logger()
|
261
|
-
{
|
262
|
-
return $this->logger;
|
263
|
-
}
|
264
|
-
|
265
|
-
/**
|
266
|
-
* Returns the date format.
|
267
|
-
*
|
268
|
-
* @return string
|
269
|
-
*/
|
270
|
-
public function get_date_format()
|
271
|
-
{
|
272
|
-
return $this->date_format;
|
273
|
-
}
|
274
|
-
|
275
|
-
/**
|
276
|
-
* Sets the date format.
|
277
|
-
*
|
278
|
-
* Accepts date formats accepted by PHP's date() function.
|
279
|
-
*
|
280
|
-
* @link http://us.php.net/manual/en/function.date.php
|
281
|
-
* @param string $format
|
282
|
-
*/
|
283
|
-
public function set_date_format($format)
|
284
|
-
{
|
285
|
-
$this->date_format = $format;
|
286
|
-
}
|
287
|
-
};
|
288
|
-
?>
|
@@ -1,456 +0,0 @@
|
|
1
|
-
<?php
|
2
|
-
/**
|
3
|
-
* @package ActiveRecord
|
4
|
-
*/
|
5
|
-
namespace ActiveRecord;
|
6
|
-
|
7
|
-
require 'Column.php';
|
8
|
-
|
9
|
-
use PDO;
|
10
|
-
use PDOException;
|
11
|
-
use Closure;
|
12
|
-
|
13
|
-
/**
|
14
|
-
* The base class for database connection adapters.
|
15
|
-
*
|
16
|
-
* @package ActiveRecord
|
17
|
-
*/
|
18
|
-
abstract class Connection
|
19
|
-
{
|
20
|
-
/**
|
21
|
-
* The PDO connection object.
|
22
|
-
* @var mixed
|
23
|
-
*/
|
24
|
-
public $connection;
|
25
|
-
|
26
|
-
/**
|
27
|
-
* The last query run.
|
28
|
-
* @var string
|
29
|
-
*/
|
30
|
-
public $last_query;
|
31
|
-
|
32
|
-
/**
|
33
|
-
* Switch for logging.
|
34
|
-
*
|
35
|
-
* @var bool
|
36
|
-
*/
|
37
|
-
private $logging = false;
|
38
|
-
|
39
|
-
/**
|
40
|
-
* Contains a Logger object that must impelement a log() method.
|
41
|
-
*
|
42
|
-
* @var object
|
43
|
-
*/
|
44
|
-
private $logger;
|
45
|
-
|
46
|
-
/**
|
47
|
-
* Default PDO options to set for each connection.
|
48
|
-
* @var array
|
49
|
-
*/
|
50
|
-
static $PDO_OPTIONS = array(
|
51
|
-
PDO::ATTR_CASE => PDO::CASE_LOWER,
|
52
|
-
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
53
|
-
PDO::ATTR_ORACLE_NULLS => PDO::NULL_NATURAL,
|
54
|
-
PDO::ATTR_STRINGIFY_FETCHES => false);
|
55
|
-
|
56
|
-
/**
|
57
|
-
* The quote character for stuff like column and field names.
|
58
|
-
* @var string
|
59
|
-
*/
|
60
|
-
static $QUOTE_CHARACTER = '`';
|
61
|
-
|
62
|
-
/**
|
63
|
-
* Default port.
|
64
|
-
* @var int
|
65
|
-
*/
|
66
|
-
static $DEFAULT_PORT = 0;
|
67
|
-
|
68
|
-
/**
|
69
|
-
* Retrieve a database connection.
|
70
|
-
*
|
71
|
-
* @param string $connection_string_or_connection_name A database connection string (ex. mysql://user:pass@host[:port]/dbname)
|
72
|
-
* Everything after the protocol:// part is specific to the connection adapter.
|
73
|
-
* OR
|
74
|
-
* A connection name that is set in ActiveRecord\Config
|
75
|
-
* If null it will use the default connection specified by ActiveRecord\Config->set_default_connection
|
76
|
-
* @return Connection
|
77
|
-
* @see parse_connection_url
|
78
|
-
*/
|
79
|
-
public static function instance($connection_string_or_connection_name=null)
|
80
|
-
{
|
81
|
-
$config = Config::instance();
|
82
|
-
|
83
|
-
if (strpos($connection_string_or_connection_name,'://') === false)
|
84
|
-
{
|
85
|
-
$connection_string = $connection_string_or_connection_name ?
|
86
|
-
$config->get_connection($connection_string_or_connection_name) :
|
87
|
-
$config->get_default_connection_string();
|
88
|
-
}
|
89
|
-
else
|
90
|
-
$connection_string = $connection_string_or_connection_name;
|
91
|
-
|
92
|
-
if (!$connection_string)
|
93
|
-
throw new DatabaseException("Empty connection string");
|
94
|
-
|
95
|
-
$info = static::parse_connection_url($connection_string);
|
96
|
-
$fqclass = static::load_adapter_class($info->protocol);
|
97
|
-
|
98
|
-
try {
|
99
|
-
$connection = new $fqclass($info);
|
100
|
-
$connection->protocol = $info->protocol;
|
101
|
-
$connection->logging = $config->get_logging();
|
102
|
-
$connection->logger = $connection->logging ? $config->get_logger() : null;
|
103
|
-
} catch (PDOException $e) {
|
104
|
-
throw new DatabaseException($e);
|
105
|
-
}
|
106
|
-
return $connection;
|
107
|
-
}
|
108
|
-
|
109
|
-
/**
|
110
|
-
* Loads the specified class for an adapter.
|
111
|
-
*
|
112
|
-
* @param string $adapter Name of the adapter.
|
113
|
-
* @return string The full name of the class including namespace.
|
114
|
-
*/
|
115
|
-
private static function load_adapter_class($adapter)
|
116
|
-
{
|
117
|
-
$class = ucwords($adapter) . 'Adapter';
|
118
|
-
$fqclass = 'ActiveRecord\\' . $class;
|
119
|
-
$source = dirname(__FILE__) . "/adapters/$class.php";
|
120
|
-
|
121
|
-
if (!file_exists($source))
|
122
|
-
throw new DatabaseException("$fqclass not found!");
|
123
|
-
|
124
|
-
require_once($source);
|
125
|
-
return $fqclass;
|
126
|
-
}
|
127
|
-
|
128
|
-
/**
|
129
|
-
* Use this for any adapters that can take connection info in the form below
|
130
|
-
* to set the adapters connection info.
|
131
|
-
*
|
132
|
-
* <code>
|
133
|
-
* protocol://username:password@host[:port]/dbname
|
134
|
-
* protocol://urlencoded%20username:urlencoded%20password@host[:port]/dbname?decode=true
|
135
|
-
* protocol://username:password@unix(/some/file/path)/dbname
|
136
|
-
* </code>
|
137
|
-
*
|
138
|
-
* @param string $connection_url A connection URL
|
139
|
-
* @return object the parsed URL as an object.
|
140
|
-
*/
|
141
|
-
public static function parse_connection_url($connection_url)
|
142
|
-
{
|
143
|
-
$url = @parse_url($connection_url);
|
144
|
-
|
145
|
-
if (!isset($url['host']))
|
146
|
-
throw new DatabaseException('Database host must be specified in the connection string.');
|
147
|
-
|
148
|
-
$info = new \stdClass();
|
149
|
-
$info->protocol = $url['scheme'];
|
150
|
-
$info->host = $url['host'];
|
151
|
-
$info->db = isset($url['path']) ? substr($url['path'],1) : null;
|
152
|
-
$info->user = isset($url['user']) ? $url['user'] : null;
|
153
|
-
$info->pass = isset($url['pass']) ? $url['pass'] : null;
|
154
|
-
|
155
|
-
if ($info->host == 'unix(')
|
156
|
-
{
|
157
|
-
$socket_database = $info->host . '/' . $info->db;
|
158
|
-
|
159
|
-
if (preg_match_all('/^unix\((.+)\)\/(.+)$/', $socket_database, $matches) > 0)
|
160
|
-
{
|
161
|
-
$info->host = $matches[1][0];
|
162
|
-
$info->db = $matches[2][0];
|
163
|
-
}
|
164
|
-
}
|
165
|
-
|
166
|
-
if (isset($url['port']))
|
167
|
-
$info->port = $url['port'];
|
168
|
-
|
169
|
-
if (strpos($connection_url,'decode=true') !== false)
|
170
|
-
{
|
171
|
-
if ($info->user)
|
172
|
-
$info->user = urldecode($info->user);
|
173
|
-
|
174
|
-
if ($info->pass)
|
175
|
-
$info->pass = urldecode($info->pass);
|
176
|
-
}
|
177
|
-
|
178
|
-
return $info;
|
179
|
-
}
|
180
|
-
|
181
|
-
/**
|
182
|
-
* Class Connection is a singleton. Access it via instance().
|
183
|
-
*
|
184
|
-
* @param array $info Array containing URL parts
|
185
|
-
* @return Connection
|
186
|
-
*/
|
187
|
-
protected function __construct($info)
|
188
|
-
{
|
189
|
-
try
|
190
|
-
{
|
191
|
-
// unix sockets start with a /
|
192
|
-
if ($info->host[0] != '/')
|
193
|
-
{
|
194
|
-
$host = "host=$info->host";
|
195
|
-
|
196
|
-
if (isset($info->port))
|
197
|
-
$host .= ";port=$info->port";
|
198
|
-
}
|
199
|
-
else
|
200
|
-
$host = "unix_socket=$info->host";
|
201
|
-
|
202
|
-
$this->connection = new PDO("$info->protocol:$host;dbname=$info->db",$info->user,$info->pass,static::$PDO_OPTIONS);
|
203
|
-
} catch (PDOException $e) {
|
204
|
-
throw new DatabaseException($e);
|
205
|
-
}
|
206
|
-
}
|
207
|
-
|
208
|
-
/**
|
209
|
-
* Retrieves column meta data for the specified table.
|
210
|
-
*
|
211
|
-
* @param string $table Name of a table
|
212
|
-
* @return array An array of {@link Column} objects.
|
213
|
-
*/
|
214
|
-
public function columns($table)
|
215
|
-
{
|
216
|
-
$columns = array();
|
217
|
-
$sth = $this->query_column_info($table);
|
218
|
-
|
219
|
-
while (($row = $sth->fetch()))
|
220
|
-
{
|
221
|
-
$c = $this->create_column($row);
|
222
|
-
$columns[$c->name] = $c;
|
223
|
-
}
|
224
|
-
return $columns;
|
225
|
-
}
|
226
|
-
|
227
|
-
/**
|
228
|
-
* Escapes quotes in a string.
|
229
|
-
*
|
230
|
-
* @param string $string The string to be quoted.
|
231
|
-
* @return string The string with any quotes in it properly escaped.
|
232
|
-
*/
|
233
|
-
public function escape($string)
|
234
|
-
{
|
235
|
-
return $this->connection->quote($string);
|
236
|
-
}
|
237
|
-
|
238
|
-
/**
|
239
|
-
* Retrieve the insert id of the last model saved.
|
240
|
-
*
|
241
|
-
* @param string $sequence Optional name of a sequence to use
|
242
|
-
* @return int
|
243
|
-
*/
|
244
|
-
public function insert_id($sequence=null)
|
245
|
-
{
|
246
|
-
return $this->connection->lastInsertId($sequence);
|
247
|
-
}
|
248
|
-
|
249
|
-
/**
|
250
|
-
* Execute a raw SQL query on the database.
|
251
|
-
*
|
252
|
-
* @param string $sql Raw SQL string to execute.
|
253
|
-
* @param array &$values Optional array of bind values
|
254
|
-
* @return mixed A result set object
|
255
|
-
*/
|
256
|
-
public function query($sql, &$values=array())
|
257
|
-
{
|
258
|
-
if ($this->logging)
|
259
|
-
$this->logger->log($sql);
|
260
|
-
|
261
|
-
$this->last_query = $sql;
|
262
|
-
|
263
|
-
try {
|
264
|
-
if (!($sth = $this->connection->prepare($sql)))
|
265
|
-
throw new DatabaseException($this);
|
266
|
-
} catch (PDOException $e) {
|
267
|
-
throw new DatabaseException($this);
|
268
|
-
}
|
269
|
-
|
270
|
-
$sth->setFetchMode(PDO::FETCH_ASSOC);
|
271
|
-
|
272
|
-
try {
|
273
|
-
if (!$sth->execute($values))
|
274
|
-
throw new DatabaseException($this);
|
275
|
-
} catch (PDOException $e) {
|
276
|
-
throw new DatabaseException($sth);
|
277
|
-
}
|
278
|
-
return $sth;
|
279
|
-
}
|
280
|
-
|
281
|
-
/**
|
282
|
-
* Execute a query that returns maximum of one row with one field and return it.
|
283
|
-
*
|
284
|
-
* @param string $sql Raw SQL string to execute.
|
285
|
-
* @param array &$values Optional array of values to bind to the query.
|
286
|
-
* @return string
|
287
|
-
*/
|
288
|
-
public function query_and_fetch_one($sql, &$values=array())
|
289
|
-
{
|
290
|
-
$sth = $this->query($sql,$values);
|
291
|
-
$row = $sth->fetch(PDO::FETCH_NUM);
|
292
|
-
return $row[0];
|
293
|
-
}
|
294
|
-
|
295
|
-
/**
|
296
|
-
* Execute a raw SQL query and fetch the results.
|
297
|
-
*
|
298
|
-
* @param string $sql Raw SQL string to execute.
|
299
|
-
* @param Closure $handler Closure that will be passed the fetched results.
|
300
|
-
*/
|
301
|
-
public function query_and_fetch($sql, Closure $handler)
|
302
|
-
{
|
303
|
-
$sth = $this->query($sql);
|
304
|
-
|
305
|
-
while (($row = $sth->fetch(PDO::FETCH_ASSOC)))
|
306
|
-
$handler($row);
|
307
|
-
}
|
308
|
-
|
309
|
-
/**
|
310
|
-
* Returns all tables for the current database.
|
311
|
-
*
|
312
|
-
* @return array Array containing table names.
|
313
|
-
*/
|
314
|
-
public function tables()
|
315
|
-
{
|
316
|
-
$tables = array();
|
317
|
-
$sth = $this->query_for_tables();
|
318
|
-
|
319
|
-
while (($row = $sth->fetch(PDO::FETCH_NUM)))
|
320
|
-
$tables[] = $row[0];
|
321
|
-
|
322
|
-
return $tables;
|
323
|
-
}
|
324
|
-
|
325
|
-
/**
|
326
|
-
* Starts a transaction.
|
327
|
-
*/
|
328
|
-
public function transaction()
|
329
|
-
{
|
330
|
-
if (!$this->connection->beginTransaction())
|
331
|
-
throw new DatabaseException($this);
|
332
|
-
}
|
333
|
-
|
334
|
-
/**
|
335
|
-
* Commits the current transaction.
|
336
|
-
*/
|
337
|
-
public function commit()
|
338
|
-
{
|
339
|
-
if (!$this->connection->commit())
|
340
|
-
throw new DatabaseException($this);
|
341
|
-
}
|
342
|
-
|
343
|
-
/**
|
344
|
-
* Rollback a transaction.
|
345
|
-
*/
|
346
|
-
public function rollback()
|
347
|
-
{
|
348
|
-
if (!$this->connection->rollback())
|
349
|
-
throw new DatabaseException($this);
|
350
|
-
}
|
351
|
-
|
352
|
-
/**
|
353
|
-
* Tells you if this adapter supports sequences or not.
|
354
|
-
*
|
355
|
-
* @return boolean
|
356
|
-
*/
|
357
|
-
function supports_sequences() { return false; }
|
358
|
-
|
359
|
-
/**
|
360
|
-
* Return a default sequence name for the specified table.
|
361
|
-
*
|
362
|
-
* @param string $table Name of a table
|
363
|
-
* @param string $column_name Name of column sequence is for
|
364
|
-
* @return string sequence name or null if not supported.
|
365
|
-
*/
|
366
|
-
public function get_sequence_name($table, $column_name)
|
367
|
-
{
|
368
|
-
return "{$table}_seq";
|
369
|
-
}
|
370
|
-
|
371
|
-
/**
|
372
|
-
* Return SQL for getting the next value in a sequence.
|
373
|
-
*
|
374
|
-
* @param string $sequence_name Name of the sequence
|
375
|
-
* @return string
|
376
|
-
*/
|
377
|
-
public function next_sequence_value($sequence_name) { return null; }
|
378
|
-
|
379
|
-
/**
|
380
|
-
* Quote a name like table names and field names.
|
381
|
-
*
|
382
|
-
* @param string $string String to quote.
|
383
|
-
* @return string
|
384
|
-
*/
|
385
|
-
public function quote_name($string)
|
386
|
-
{
|
387
|
-
return $string[0] === static::$QUOTE_CHARACTER || $string[strlen($string)-1] === static::$QUOTE_CHARACTER ?
|
388
|
-
$string : static::$QUOTE_CHARACTER . $string . static::$QUOTE_CHARACTER;
|
389
|
-
}
|
390
|
-
|
391
|
-
/**
|
392
|
-
* Return a date time formatted into the database's date format.
|
393
|
-
*
|
394
|
-
* @param DateTime $datetime The DateTime object
|
395
|
-
* @return string
|
396
|
-
*/
|
397
|
-
public function date_to_string($datetime)
|
398
|
-
{
|
399
|
-
return $datetime->format('Y-m-d');
|
400
|
-
}
|
401
|
-
|
402
|
-
/**
|
403
|
-
* Return a date time formatted into the database's datetime format.
|
404
|
-
*
|
405
|
-
* @param DateTime $datetime The DateTime object
|
406
|
-
* @return string
|
407
|
-
*/
|
408
|
-
public function datetime_to_string($datetime)
|
409
|
-
{
|
410
|
-
return $datetime->format('Y-m-d H:i:s T');
|
411
|
-
}
|
412
|
-
|
413
|
-
/**
|
414
|
-
* Converts a string representation of a datetime into a DateTime object.
|
415
|
-
*
|
416
|
-
* @param string $string A datetime in the form accepted by date_create()
|
417
|
-
* @return DateTime
|
418
|
-
*/
|
419
|
-
public function string_to_datetime($string)
|
420
|
-
{
|
421
|
-
$date = date_create($string);
|
422
|
-
$errors = \DateTime::getLastErrors();
|
423
|
-
|
424
|
-
if ($errors['warning_count'] > 0 || $errors['error_count'] > 0)
|
425
|
-
return null;
|
426
|
-
|
427
|
-
return new DateTime($date->format('Y-m-d H:i:s T'));
|
428
|
-
}
|
429
|
-
|
430
|
-
/**
|
431
|
-
* Adds a limit clause to the SQL query.
|
432
|
-
*
|
433
|
-
* @param string $sql The SQL statement.
|
434
|
-
* @param int $offset Row offset to start at.
|
435
|
-
* @param int $limit Maximum number of rows to return.
|
436
|
-
* @return string The SQL query that will limit results to specified parameters
|
437
|
-
*/
|
438
|
-
abstract function limit($sql, $offset, $limit);
|
439
|
-
|
440
|
-
/**
|
441
|
-
* Query for column meta info and return statement handle.
|
442
|
-
*
|
443
|
-
* @param string $table Name of a table
|
444
|
-
* @return PDOStatement
|
445
|
-
*/
|
446
|
-
abstract public function query_column_info($table);
|
447
|
-
|
448
|
-
/**
|
449
|
-
* Query for all tables in the current database. The result must only
|
450
|
-
* contain one column which has the name of the table.
|
451
|
-
*
|
452
|
-
* @return PDOStatement
|
453
|
-
*/
|
454
|
-
abstract function query_for_tables();
|
455
|
-
};
|
456
|
-
?>
|