Repository navigation
Conversation
|
I was about to write a patch for this very thing! I reviewed swieton's changes and they look good, please pull! |
There was a problem hiding this comment.
I think even the sql srv driver needs top_N style...eg some paris:
$debt = Model::factory('Debt')->find_one(653178);
$accounts = $debt->account()->find_many();
the error:
PHP Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: [Microsoft][SQL Server Native Client
10.0][SQL Server]Incorrect syntax near 'LIMIT'.' in C:\Users\jporter\Desktop\agency_import2\idiorm\idiorm.php:966
Stack trace:
#0 C:\Users\jporter\Desktop\agency_import2\idiorm\idiorm.php(966): PDOStatement->execute(Array)
#1 C:\Users\jporter\Desktop\agency_import2\idiorm\idiorm.php(362): ORM->_run()
#2 C:\Users\jporter\Desktop\agency_import2\paris\paris.php(115): ORM->find_one(653178)
#3 C:\Users\jporter\Desktop\agency_import2\take2.php(13): ORMWrapper->find_one(653178)
#4 {main}
thrown in C:\Users\jporter\Desktop\agency_import2\idiorm\idiorm.php on line 966
PS C:\Users\jporter\Desktop\agency_import2>
There was a problem hiding this comment.
Hi Jim,
I'm glad to hear my work is useful to someone!
What's the issue you're having? Is it simply that we need another
option in that switch statement? Or is it something more significant
missing?
Thanks!
Mike
On Mon, Dec 5, 2011 at 10:22 AM, Jim Porter
reply@reply.github.com
wrote:
@@ -232,6 +249,20 @@
}/**
- * Returns a constant for the "limit clause style" for MS Sql Server
- * versus grown up databases.
- */
- protected static function _detect_limit_clause_style() {
- switch(self::$_db->getAttribute(PDO::ATTR_DRIVER_NAME)) {
- case 'sqlsrv':
I think even the sql srv driver needs top_N style...eg some paris:
$debt = Model::factory('Debt')->find_one(653178);
$accounts = $debt->account()->find_many();the error:
PHP Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: [Microsoft][SQL Server Native Client
10.0][SQL Server]Incorrect syntax near 'LIMIT'.' in C:\Users\jporter\Desktop\agency_import2\idiorm\idiorm.php:966
Stack trace:
#0 C:\Users\jporter\Desktop\agency_import2\idiorm\idiorm.php(966): PDOStatement->execute(Array)
#1 C:\Users\jporter\Desktop\agency_import2\idiorm\idiorm.php(362): ORM->_run()
#2 C:\Users\jporter\Desktop\agency_import2\paris\paris.php(115): ORM->find_one(653178)
#3 C:\Users\jporter\Desktop\agency_import2\take2.php(13): ORMWrapper->find_one(653178)
#4 {main}
thrown in C:\Users\jporter\Desktop\agency_import2\idiorm\idiorm.php on line 966
PS C:\Users\jporter\Desktop\agency_import2>
Reply to this email directly or view it on GitHub:
https://github.com/j4mie/idiorm/pull/37/files#r269955
There was a problem hiding this comment.
Actually I got it working once I merged your branch in. Now I'm just trying to figure out how I can get the types of relationships I need.
debt has one account
account has no debt_id
so in Debt extends Model function account(){ return $this->has_one('Account'); }
But every way I try it won't create the correct query. I need for the debt object to fetch an account where debt->account_id == account->id
I've been fiddling with various ways of tricking paris into using a different foreign key.
So recap:
$debt = Model::factory('Debt')->find_one(653178);
//i has a debt!! it has properties!
$debt->account()->find_one();
// no worky, it's trying to find an account with "debt_id" column on account table.
|
+1 This looks good, and should be merged. |
|
I am really not keen on including database specific switches into the core library. It seems like this patch is necessary with no cross compatible way of handling query limiting. I don't run MS SQL so can you guys who are please feedback on this patch and the comments in the diff? I will remove it from the 1.2.0 milestone for now. Have you tested this with real tables @schmod ? |
|
This pull request has now slipped again to the 1.4.0 release. Please can someone running MS SQL comment on this patch. This patch will be closed (without merge) in 2013 if there are no comments or further requests for this feature. |
|
Thank you for the pull request, but unfortunately in this case I am going to be closing it without merge. |
This quick patch will allow Idiorm to generate correct limit clauses for SQL Server. If it detects the driver is "mssql" or "sqlsrv", or alternately the "limit_clause_style" configuration option is set, it will generate a statement like "SELECT TOP 5 * FROM widgets" instead of the more traditional "SELECT * FROM widgets LIMIT 5".
This is by no means a complete implementation of a SQL generator for MSSQL - but it's a start and allows basic functionality. Notably missing is support for the "OFFSET" clause, which is not handled at all (that is, it will generate invalid SQL and the driver will throw an exception in that case).
Also included are updates to the test framework that uses a different mock for the DummyPDO class. By using a new class instead of inheriting from the PDO base class, it's easy to fake things like the driver it claims to be using. This required a little bit more code and less flexibility in the mock, but it does allow us to test the different SQL generation for MSSQL (which includes the differing quote character which does not appear to have been tested previously.