Bug Report #3587

ORM and sqlite virtual tables not accessed properly breaking object

Added by tomek gruschsky over 1 year ago. Updated 4 months ago.

Status:Closed Start date:01/14/2011
Priority:Normal Due date:
Assignee:Isaiah DeRose-Wilson % Done:

100%

Category:-
Target version:Kohana v3.x - v3.1.5
Resolution:fixed Points:

Description

sqlite has virtual tables which can be used for (amongst other things) powerful full text searches. virtual tables are special in that they don't have any indexes, they don't have any field types, and nor do they have a pk you define. they automatically come with a pk called 'rowid'. the problem is when a user searches on a virtual table using the wildcard *, all fields are returned, EXCEPT the rowid. you need to specifically ask for the rowid should you need it, so: select rowid, * from foo;

This seems to have a knock-on effect for the _loaded property of ORM classes, in that, even if a row is found from something like: ORM::factory('foo')->where('bar', '=', 'asdf')->find(),as the pk isn't returned, _loaded seems to be wrongly set to false, and neither is the pk accessible in the orm object;

as i understand there are two solutions, to not rely on the pk being present for such a situation when setting _loaded, using other fields as well, or, instead of searching with tbl.*, listing each field specifically in the query. as the $_primary_key is specified in the model as 'rowid', it would solve the above problem as the id would be specifically asked for it.


Subtasks

Bug Report #3729: ORM and sqlite virtual tables not accessed properly break...ClosedIsaiah DeRose-Wilson

Associated revisions

Revision c1d5f2f1
Added by Isaiah DeRose-Wilson 4 months ago

Fixes #3587 - Select columns by name instead of doing select *

History

Updated by tomek gruschsky over 1 year ago

This seems to be an issue for any ORM model that uses a custom PK name other than 'id'; The PK isn't returned with the ORM object, making deleting / updating impossible rendering ORM useless for those objects.

Updated by Isaiah DeRose-Wilson over 1 year ago

  • Status changed from New to Review
  • Target version changed from v3.1.0 to v3.1.1

Updated by tomek gruschsky over 1 year ago

sample code to replicate
virtual tables have a pk called rowid

sqlite3
create virtual table foo using fts3 (txt);
insert into foo values ('foo bar foo');

kohana model
class Foo extends ORM{
// need to change pk name as it's a virtual table
protected $_primary_key = 'rowid';
protected $_table_columns = array(
'rowid' => array('data_type' => 'int', 'is_nullable' => FALSE),
'txt' => array('data_type' => 'string', 'is_nullable' => TRUE),
);
.
.
.
$f = ORM::factory('foo', 1);
echo $f->rowid.":".$f->txt.":".(bool) $f->loaded();

untested, but that should replicate the problem

Updated by Jeremy Bush over 1 year ago

  • Target version changed from v3.1.1 to v3.0.10

This sounds like it would also apply to 3.0, so I'm moving the base version there.

Updated by Isaiah DeRose-Wilson over 1 year ago

  • Status changed from Review to Assigned
  • Assignee set to Isaiah DeRose-Wilson

tomek gruschsky wrote:

This seems to be an issue for any ORM model that uses a custom PK name other than 'id'; The PK isn't returned with the ORM object, making deleting / updating impossible rendering ORM useless for those objects.

This is only an issue for fields that don't get included with select *. Custom PK work fine for me. Can you explain what issue you are having with custom PKs? Or is it just with temporary fields in sqlite because they aren't included in select *?

Updated by Jeremy Bush about 1 year ago

  • Target version changed from v3.0.10 to v3.0.11

Updated by Jeremy Bush about 1 year ago

  • Target version changed from v3.0.11 to v3.0.12

Updated by Lorenzo Pisani 10 months ago

  • Target version changed from v3.0.12 to v3.1.4

Updated by Isaiah DeRose-Wilson 10 months ago

  • Target version changed from v3.1.4 to v3.1.5

Updated by Isaiah DeRose-Wilson 4 months ago

  • Status changed from Assigned to Closed
  • % Done changed from 0 to 100

Updated by Isaiah DeRose-Wilson 4 months ago

  • Resolution set to fixed

Also available in: Atom PDF