ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

DataMapper ORM v1.8.2

November 30, 2011 3:43pm

Subscribe [100]
  • #46 / Dec 07, 2011 5:44pm

    WanWizard

    4475 posts

    The manual is fully up to date.

    I should find the time to bring the example up to date, it is still build using a lot of PHP4 techniques, common in the CI 1.6-1.7 days. All I did was a quick scan for obvious issues, like PHP short tags.

  • #47 / Dec 09, 2011 2:13pm

    diZzyCoDeR

    25 posts

    Quick question (hopefully) is there any way to get Datamapper to utilize the _escape_table() function (from sqlsrv_driver.php)  I guess since it’s not an overloaded function of DB_driver then I’ll have to implement it directly in datamapper.php

    Unless there is a way to add it to the model somehow?  But I fear there’s lots of code in datamapper.php that generates SQL and will need to implement same method.

    (I have to enclose my [table.Names] b/c there’s a frigging period in the name.  =/

  • #48 / Dec 09, 2011 5:57pm

    WanWizard

    4475 posts

    You can call any internal method using $this->db->dm_call_method(‘methodname’).
    If the method needs arguments, just add them after the methodname.

    As to the escaping: the _escape_table() method in the sqlsrv driver is a dummy (in CI 2.1.0), it doesn’t do anything? Maybe it is there that it should be fixed?

  • #49 / Dec 09, 2011 6:11pm

    diZzyCoDeR

    25 posts

    #FACT!  But I had added:

    $return "[".$table."]";

    Which works fine for straight up queries, but in particular the JOIN queries generated by DM do not escape the tables.

    I looked in the code, but doesn’t look like there’s a single place to add _escape_table($table) call.  (?)

    I mean, I managed to convince others to rename the tables, but, probably it should do this anyway?  =)  (maybe not seeing as no one is complaining =)

    Thanks for getting back to me!

  • #50 / Dec 10, 2011 4:02am

    WanWizard

    4475 posts

    Which works fine for straight up queries, but in particular the JOIN queries generated by DM do not escape the tables.

    DataMapper calls $this->db->join to create the joins.

    Looking into the CI driver code, I see that it uses escape_table() on a few utility calls, and on insert, update and delete queries. But not on any other ones. This particular issue is on DB_active_rec.php#L340 (CI 2.1.0) where the JOIN is constructed. So CI has to abstract the join method so the drivers can deal with the platform specifics. You should create an issue for this in the bug tracker.

    I mean, I managed to convince others to rename the tables, but, probably it should do this anyway?  =)  (maybe not seeing as no one is complaining =)

    You’re probably one of the unlucky few that has to work with Microsoft crap… 😉

  • #51 / Dec 13, 2011 11:21am

    diZzyCoDeR

    25 posts

    Excellent!  Cheers.

    You’re probably one of the unlucky few that has to work with Microsoft crap…

    Ha! Ain’t that the truth.  And I’m made to look like the ass who wants to use stupid MySQL. lol.

    #ProTip for those that want to use this lovely, lovely ORM for their project but are constrained by the DB design of others.  “Views” are your friends.  Easy to create, you map aliases of your column names and even denormalize where appropriate.  Saved my bacon when I started to ditch DM b/c my DB schema didn’t conform to standard normalization practices.  Persistence FTW!

  • #52 / Dec 14, 2011 4:56pm

    Onema

    14 posts

    So I fixed the issue that I had with the DSN, I set what I believe is the correct hostname:

    $db['default']['hostname'] = 'mysql:host=localhost';
    $db['default']['username'] = $username;
    $db['default']['password'] = $password;
    $db['default']['database'] = 'my_database_name';

    , but now I’m getting this error

    PHP Fatal error:  Call to a member function field_data() on a non-object in /system/database/DB_driver.php on line 889
     PHP Stack trace:
     PHP   1. {main}() /index.php:0
     PHP   2. require_once() /index.php:212
     PHP   3. call_user_func_array() /system/core/CodeIgniter.php:359
     PHP   4. Site->dashboard() /system/core/CodeIgniter.php:359
     PHP   5. BlogPost->__construct() /application/controllers/site.php:50
     PHP   6. DataMapper->__construct() /application/models/blogpost.php:45
     PHP   7. DataMapper->DataMapper() /application/libraries/Datamapper.php:451
     PHP   8. CI_DB_driver->field_data() /application/libraries/Datamapper.php:645

    Site.php line 50 has the following code

    $Blog_Post = new BlogPost();

    and blogpost.php (model file) is just the constructor calling the parent

    public function __construct($id = null) {
          parent::__construct($id);
        }

    This happens as soon as I try to create any model!

    any ideas?

    Remember I’m using the PDO driver.

    Thank you

  • #53 / Dec 15, 2011 4:37am

    WanWizard

    4475 posts

    In your trace I see CI_DB_driver being mentioned. This means that either you’re not using 1.8.2, or you haven’t installed the DataMapper bootloader in your index.php.

    edit: I may also mean you’re using a very early 1.8.2, which had an issue with recreating $this->db under certain circumstances, which can also trigger this message.

    If so update your DataMapper installation from Bitbucket, download ‘tip’ from https://bitbucket.org/wanwizard/datamapper/downloads to make sure you have the latest code.

  • #54 / Dec 15, 2011 10:19am

    Onema

    14 posts

    When you say bootloader, you are talking about the bootstrap?

    require_once APPPATH.'third_party/datamapper/bootstrap.php';

    or is it something additional I need?

    I downloaded the latest from your bit bucket repo and replace every file manually. According to my DIFF, nothing had changed except for the extension htmlform.php, and the result of my test is the same (I still get the same error message). I upgraded from CI 2.0.2 usign ORM 1.8.1 to CI 2.1 using ORM 1.8.2. It works perfect with the mysql driver!

  • #55 / Dec 15, 2011 10:51am

    WanWizard

    4475 posts

    That is indeed the addition I was referring too.

    But looking in the PDO driver, I found the issue. Whoever worked on the PDO driver is appearantly a TransactSQL user, because to determine the field data, the PDO driver executes “SELECT TOP 1 FROM tablename”. Which causes an error when you connect to MySQL (which doesn’t speak TSQL), which causes the query result to be FALSE, instead of a result object. Which gives you this error.

    A bit more snooping shows that one “timw4mail” is the culprit, so it looks like someone at Ellislab or the Reactor team failed to screen the code properly.

    In short, The CI PDO driver is not SQL dialect neutral. Open a ticket on http://github.com/ellislab/codeigniter/issues to have this fixed.

  • #56 / Dec 15, 2011 11:08am

    Onema

    14 posts

  • #57 / Dec 16, 2011 12:37pm

    Nguyen Huy

    3 posts

    Then you haven’t read the docs, and didn’t install the bootstrap in your index.php file.

    This is new since 1.8.2, see http://datamapper.wanwizard.eu/pages/installation.html

    thank’s works for me. Just some advice, maybe you should update the offline documentation. :D

    Hi elmizan, how did you fix this bug?
    I did following the installing guide but it still does not work.
    Please tell my how did you do. Thanks so much.

    Note: I added the DataMapper bootstrap, directly BEFORE the Codeigniter bootstrap in index.php file.

  • #58 / Dec 16, 2011 1:57pm

    WanWizard

    4475 posts

    That should solve the problem.

    Otherwise, load the database library in the welcome controller, and var_dump(get_class($this->db)). What class is it pointing too? It should be “DM_DB_Driver”. If you see “CI_DB_Driver”, the bootstrap isn’t loaded, or isn’t loaded properly.

    Note that DataMapper 1.8.2 requires CI 2.0.3 or above.

  • #59 / Dec 23, 2011 10:59am

    AdamM

    5 posts

    Two issues:

    1) Invalid constructor

    In method DataMapper, from line 481, we have following code:

    // Load stored config settings by reference
      foreach (DataMapper::$config as $config_key => &$config_value)
      {      
       // Only if they're not already set
       if (property_exists($this, $config_key))
       {
        $this->{$config_key} =& $config_value;
       }
      }

    In version 1.8.1 instead of property_exists was empty method. Now if you set some params (like db_params) they are all cleaned, so I think that both methods should be used (than everything working).

    2) Create “normal” CI database object when I set db_params value

    I downloaded tip from bitbucket. I have CI 2.1 and configured everything properly (I read all topic about this version). But I still get errors:

    Fatal error: Call to undefined method CI_DB_mysql_driver::dm_call_method() in D:\usr\www\nolearn\application\libraries\datamapper.php on line 3550

    Fatal error: Call to undefined method CI_DB_mysql_driver::dm_call_method() in D:\usr\www\nolearn\application\libraries\datamapper.php on line 1508

    I get them only when I set db_params before constructor. I think that new connection to database is not creating a DM_DB_Driver, but CI_DB_Driver… How can I deal with it?

     

  • #60 / Dec 23, 2011 1:53pm

    WanWizard

    4475 posts

    1. That is indeed a bug, it should be

    if ( ! property_exists($this, $config_key) )

    2. You need to add the bootloader to your index.php, this creates the DM_DB_Driver, it should always be there.

    When you get to the lines that generate these errors, $this->db should already be loaded. What is your db_params value when this happens? And how and where do you define it?

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases