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.

[Deprecated] DMZ 1.6.2 (DataMapper OverZealous Edition)

November 23, 2009 11:54pm

Subscribe [46]
  • #226 / Feb 02, 2010 7:51am

    OverZealous

    1030 posts

    Doh - I’m tired!  I’ve been upgrading my main workstation to Snow Leopard…, and it’s now 7AM.

    Well, I’ll keep thinking about it.

  • #227 / Feb 02, 2010 7:53am

    mrtavo

    15 posts

    Maybe… that function only works with one parameter ?

    If thats the problem… then I should try to create a full query.

    [Edit]
    Thanks for your effort, I’ll be careful if you have any solution.

  • #228 / Feb 02, 2010 1:58pm

    Conerck

    15 posts

    Well, I’ll keep thinking about it.

    I just ran into the same problem as mrtavo and it seems to apply to all _func() calls where the SQL Function has more than 1 parameter.

    I tracked the problem down to CodeIgniter’s ActiveRecord. In the select() function CI splits the passed select arguement with

    $select = explode(',', $select)

    (DB_active_record.php @ l 83)
    which hacks up the multi-argument SQL function into seperate select fields as far as CI is concerned (This is kinda ugly, but not exactly the source of the problem).
    Then when you call get() later, CI goes ahead and calls protect_identifiers on every field again (in _compile_select(), l. 1511), which causes the Syntax errors.
    So, the problem is that protect_identifers is only temporarily disabled by DMZ during the select_func() call, it is turned back on before get() is called.
    You’d have to keep protect_identifiers set to FALSE until after the query has been completed.

    Since I don’t know the inner workings of DMZ too well I didn’t attempt to make a patch for it, since I don’t know what side effects this could cause, but I hope I could help you with tracking down the problem.

  • #229 / Feb 02, 2010 7:39pm

    OverZealous

    1030 posts

    Thank you for tracking that down.  Sadly, that’s about what I expected to find.

    CodeIgniter’s often unnecessary and aggressive “identifier protection” has caused me more headaches than it ever has done good.

    The way it insists on splitting values with commas is my other headache.  I don’t understand why they insist on parsing the SQL string when you need a full lexer to really do any good.  (I’ve asked then to write the code to ignore any strings that contain open parentheses, which would allow a developer to override the protections whenever they choose.  The select methods should also listen to this.)

    The problem with turning off protect-identifiers for the duration is that stops it from protecting even when you might want it to.  I’ll look at adding (yet another) flag that tells me to set protect_identifiers to FALSE just before compiling the SQL query.

    I’m tempted to completely stop using CodeIgniter’s ActiveRecord, and just replicate those components manually in DMZ.

  • #230 / Feb 03, 2010 3:59am

    mrtavo

    15 posts

    Thanks for the interest on this problem.

    I don’t know very well how DMZ works, I get a little bit dizzy reading the code; I haven’t got enough php knoledge to patch it by my self.

    Please, keep me informed on any change because I would like to use this functionality instead of typing a plain query (I’ll patch my code to that…).

    Thanks again and good luck!

  • #231 / Feb 03, 2010 4:02am

    tdktank59

    322 posts

    @tdktank59

    Hey I had a similar problem with my e-commerce shop just couple of days ago. I had a table called products and one field was “model”. I was using where_related. I got quite “interesting” sql. I changed the field to model2 and which made things work again. Sorry OverZealous, didnt have the time to do a bug report because of deadline and I dont have the time right now give proper details. But tdktank59, I just wanted to inform you are not alone with the problem 😊

    Awesome thanks man,

    I decided to just save it manualy… $object->model_id = $model->id;

    Either way it works, just not very elegant lol…

  • #232 / Feb 03, 2010 4:11am

    OverZealous

    1030 posts

    @tdktank59, cahva

    I think the problem you are both having is that model is a DMZ keyword.  You can’t use it for an object’s name, because this will always result in a string:

    $my_model = $widget->model;
    // $my_model => 'widget'

    It’s impossible for DMZ to save it, because it relies on the fact that $this->{"model"} resolves into an object.

    It’s just incorrect.  I would change the name of the object before you get too much further in your application.

  • #233 / Feb 03, 2010 1:41pm

    Mirage

    273 posts

    Something wrong with how DMZ (or CI???) opens database connections - I’m running out of connections when saving objects in a loop:

    public function shuffle_questions($exam_id)
        {
            // Load the questions in entered order
            $question = new Sae_Question();
            $question->where('exam_id' , $exam_id)
                     ->order_by('id')
                     ->get();
    
            $questions = $question->all;
            shuffle($questions);
            
            foreach ($questions as $i => $q) 
            {
                $q->seq = ($i+1);
                $q->save();
            }
    
            redirect('/admin/sae/questions');
            
        }

    Apparently a new db connection is established on every save() call for some reason. That doesn’t seem right. A quick look at the log shows this:

    DEBUG - 2010-02-03 11:44:45 --> Database Driver Class Initialized
    DEBUG - 2010-02-03 11:44:45 --> Database Driver Class Initialized
    DEBUG - 2010-02-03 11:44:45 --> Database Driver Class Initialized
    DEBUG - 2010-02-03 11:44:45 --> Database Driver Class Initialized
    DEBUG - 2010-02-03 11:44:45 --> Database Driver Class Initialized
    DEBUG - 2010-02-03 11:44:45 --> Database Driver Class Initialized
    DEBUG - 2010-02-03 11:44:45 --> Database Driver Class Initialized
    DEBUG - 2010-02-03 11:44:45 --> Database Driver Class Initialized
    DEBUG - 2010-02-03 11:44:45 --> Database Driver Class Initialized
    DEBUG - 2010-02-03 11:44:45 --> Database Driver Class Initialized
    DEBUG - 2010-02-03 11:44:45 --> Database Driver Class Initialized
    DEBUG - 2010-02-03 11:44:45 --> Database Driver Class Initialized
    DEBUG - 2010-02-03 11:44:45 --> Database Driver Class Initialized
    DEBUG - 2010-02-03 11:44:45 --> Database Driver Class Initialized
    DEBUG - 2010-02-03 11:44:45 --> Database Driver Class Initialized
    ERROR - 2010-02-03 11:44:45 --> Severity: Warning  --> mysql_connect() [<a href="http://function.mysql-connect">function.mysql-connect</a>]: Too many connections /Users/juesch/Sites/childneurologysociety.org/www/system_172/database/drivers/mysql/mysql_driver.php 70
    ERROR - 2010-02-03 11:44:45 --> Unable to connect to the database

    Help?

  • #234 / Feb 03, 2010 2:48pm

    TheJim

    35 posts

    @Mirage

    In your DataMapper config file set:

    $config[‘db_params’] = FALSE;

    Then the database instance will be shared across your DataMapper objects.  Of course, that turns off subqueries, but that’s usually fine.

  • #235 / Feb 03, 2010 2:57pm

    Mirage

    273 posts

    Thanks!

  • #236 / Feb 03, 2010 3:42pm

    OverZealous

    1030 posts

    @Mirage, TheJim

    If you set db_params to FALSE, you will not be able to use sub-queries or anything that relies on them (such as include_related_count).

    If possible, a better option is to make sure that your DataBase connection is configured for persistent connections, by having this in your CI database settings file:

    $db[/*connection id*/]['pconnect'] = TRUE;

    If your database did not support persistent connections, either due to PHP’s driver or the DB itself, then you would have to follow TheJim’s suggestion.  However, MySQL supports it, so it should work.

    Basically, even though DMZ is creating many db objects, there should only be a single database connection.

    If this does not work, then I need to find a way to release the database connection when it is not in use.  (Alternatively, this goes back to the idea of not using CI’s ActiveRecord any more, which would eliminate the problem in a different way.)

  • #237 / Feb 04, 2010 4:35am

    ak_85

    2 posts

    Fatal error: Class name must be a valid object or a string in D:\aplikasi_coba_coba\www\simpeg\application\libraries\datamapper.php on line 1730

    when i make my own pagination and routes.
    and segment array more then 5

    And in my controller i write:

    function index()
        {
            $offset     = $this->uri->segment(5);
            
            $data = new Jabatan_Struktural();
            $data->order_by('order','asc');
            $data->limit(25, $offset)->get();
            
            $config['base_url']        = site_url('referensi/jabatan/struktural/index/');
            $config['total_rows']    = $data->count();
            
            $this->pagination->initialize($config);
            
            $items['data'] = $data->all;
            $this->page['index'] = 'referensi/jabatan/struktural/lists';
            $this->template->view($this->page['index'], $items);
        }

    can anyone help me…

  • #238 / Feb 04, 2010 4:46am

    OverZealous

    1030 posts

    @ak_85
    My guess is it is a similar error to this one in the troubleshooting section: you probably have two classes with the same name.

    DMZ does not reference the segments in any fashion.

  • #239 / Feb 04, 2010 6:39am

    ak_85

    2 posts

    i have solved the problem…
    i have field name parent in my database, when i change the field name there is no error….

    thanks for the response…

  • #240 / Feb 04, 2010 12:10pm

    Devon Lambert

    139 posts

    How does DMZ handle database tables that do not have “id” set as the primary key?

    Is there a way to change primary key for a model?

    What about unique foreign keys? (This one may not matter as much).

    Thanks 😊

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

ExpressionEngine News!

#eecms, #events, #releases