EllisLab text mark
Advanced Search
6 of 62
6
   
DMZ 1.7.1 (DataMapper OverZealous Edition)
Posted: 22 March 2010 10:08 PM   [ # 81 ]   [ Rating: 0 ]
Avatar
Joined: 2008-10-08
1039 posts

@Frank Liu
Wow, that’s great!  Thanks for the research.

I added a link back to your post on the System Requirements page so that others can find this if they need to.

Hopefully you will be able to upgrade your PHP soon, though!

 Signature 

Phil DeJarnett
  OverZealous Creations, LLC

 
Posted: 23 March 2010 07:40 PM   [ # 82 ]   [ Rating: 0 ]
Avatar
Joined: 2009-03-19
103 posts

Hey Phill,

I have something to show you that I cant send in this forum.

Is there a email where I can send you a message ?

Thanks

 
Posted: 23 March 2010 08:27 PM   [ # 83 ]   [ Rating: 0 ]
Avatar
Joined: 2008-10-08
1039 posts

@PoetaWD
It’s on the troubleshooting page of the manual, in the first gray box.

(I don’t want to publish it on a public forum, obviously.)

 Signature 

Phil DeJarnett
  OverZealous Creations, LLC

 
Posted: 23 March 2010 11:18 PM   [ # 84 ]   [ Rating: 0 ]
Avatar
Joined: 2008-10-08
1039 posts

Code Theft

I feel the need to write this.  I’ve been contacted by several individuals—in just the last few weeks—who have felt the need to share their pride in copying source code from proprietary and non-free applications.

This is an incredibly misinformed view of the world.  Rationalizing this by saying you are just learning, or something similar, does not take away from the fact that:

  1) It is completely unnecessary.  There is a huge wealth of legally free software, with 100% visible source code to look at.

  2) It damages the entire software industry.  I assume that the majority of people who use CodeIgniter are in the software industry.  When you take from someone else’s hard work, and redistribute it against their will, you are stealing from that person or company.

  3) You don’t learn by doing things right the first time.  You learn by making mistakes.  This is the point of going to class, of practicing, of any skilled trade.  I don’t know how to write code because I saw it written correctly once before—I know how to write code correctly because I’ve written a lot of messed up crap that I had to rewrite many times.

  4) The saddest thing is when you do this, and then brag about it to a person who writes software for a living, that’s like going to an independent film director and bragging about how you download all your favorite movies from bittorrent.  That’s really nice.  Why don’t you spit in their face, too?

Please, if you are trying to learn something, look at the open-source community.  Don’t steal closed-source code.  Just because you can decrypt PHP and JavaScript, doesn’t mean you should.  And don’t steal FOSS code either!  Attribute it, follow the licenses as provided, and be respectful of other software developers.

As this isn’t the correct forum to discuss this, if you have a response to this message, we can continue the discussion here.

 Signature 

Phil DeJarnett
  OverZealous Creations, LLC

 
Posted: 23 March 2010 11:45 PM   [ # 85 ]   [ Rating: 0 ]
Joined: 2009-08-09
14 posts

So more Oracle woes…

turns out whenever one tries to do a $o->save() that uses an insert, datamapper needs the following:

// around line 1700 in libraries/datamapper.php
// Create new record
$this->db->insert($this->table, $data);

if( ! $this->_force_save_as_new)
{
// Assign new ID
$this->id = $this->db->insert_id(); // UNSUPPORTED for oci8 driver
}

Since the oci8 driver does not support this (Oracle doesn’t support auto incrementing keys), this would raise an error.

To fix this put this around the same area:

$query = $this->db->query(“select {$this->table}_SQ.NEXTVAL ID FROM DUAL”);
$query_result = $query->row();
$data[‘id’] = $query_result->id;

// Create new record
$this->db->insert($this->table, $data);

if( ! $this->_force_save_as_new)
{
// Assign new ID
$this->id = $data['id'];
}

Note that here we assume, for each table that one creates, there’s a corresponding sequence with the name ($table_name}_SQ.

In addition, make sure that your oci8_result.php also contain the following code:

function field_data()
{
$retval = array();
$fieldCount = $this->num_fields();
for ($c = 1; $c <= $fieldCount; $c++)
{
$F = new stdClass();
$F->name = strtolower(ocicolumnname($this->stmt_id, $c)); // IMPORTANT
$F->type = ocicolumntype($this->stmt_id, $c);
$F->max_length = ocicolumnsize($this->stmt_id, $c);

$retval[] = $F;
}

  return $retval;
}

Generally, to make sure oci8 works properly, one really needs to change the driver to convert field names to lowercased. I wrote a separate thread in this forum somewhere else that contain some of those fixes.

Anyway, did I mention I hate Oracle?

 
Posted: 23 March 2010 11:53 PM   [ # 86 ]   [ Rating: 0 ]
Avatar
Joined: 2008-10-08
1039 posts

@Frank Liu
Wow.  I love PostgreSQL more every day tongue wink

I’m glad you solved these problems.  I’m pretty sure there’s no way to integrate this into DMZ in a non-problematic manner.  confused

If you don’t mind posting the link to the other thread, though, I’ll add a link to it to the DMZ docs.

Edit: Corrected poorly written sentence.

 Signature 

Phil DeJarnett
  OverZealous Creations, LLC

 
Posted: 24 March 2010 12:26 AM   [ # 87 ]   [ Rating: 0 ]
Joined: 2009-08-09
14 posts
OverZealous - 24 March 2010 03:53 AM

@Frank Liu
Wow.  I love PostgreSQL more every day tongue wink

I’m glad you solved these problems.  I’m pretty sure there’s no way to integrate this into DMZ in a non-problematic manner.  confused

If you don’t mind posting the link to the other thread, though, I’ll add a link to it to the DMZ docs.

Edit: Corrected poorly written sentence.

Here’s the link to the other thread. But these are just hacks; one should be careful about using them. Too bad I don’t know CI well enough to write a library. And it seems that CI is written in a way that is difficult to extend the database drivers.

 
Posted: 24 March 2010 12:36 AM   [ # 88 ]   [ Rating: 0 ]
Avatar
Joined: 2008-10-08
1039 posts
Frank Liu - 24 March 2010 04:26 AM

And it seems that CI is written in a way that is difficult to extend the database drivers.

That is, sadly, the biggest problem I have with CI.  If I could override them, I could easily fix all of my issues with _protect_identifiers.  I rather hate editing the core CI files directly.

One thing: if you are only modifying the Oracle drivers (and not CI_DB, CI_DB_driver, or CI_DB_activerecord), you could try to copy the oracle drivers and give them a new name.  At least this way, upgrading CI wouldn’t override your customizations.  It’s probably not worth the renaming effort, though.

 Signature 

Phil DeJarnett
  OverZealous Creations, LLC

 
Posted: 24 March 2010 01:05 AM   [ # 89 ]   [ Rating: 0 ]
Joined: 2009-08-09
14 posts
OverZealous - 24 March 2010 04:36 AM
Frank Liu - 24 March 2010 04:26 AM

And it seems that CI is written in a way that is difficult to extend the database drivers.

That is, sadly, the biggest problem I have with CI.  If I could override them, I could easily fix all of my issues with _protect_identifiers.  I rather hate editing the core CI files directly.

One thing: if you are only modifying the Oracle drivers (and not CI_DB, CI_DB_driver, or CI_DB_activerecord), you could try to copy the oracle drivers and give them a new name.  At least this way, upgrading CI wouldn’t override your customizations.  It’s probably not worth the renaming effort, though.

The problem is as far as I know, you do have to change the DB_active_rec.php file. The update and insert query executes a compiled string. This is not enough to properly deal with clob objects.

 
Posted: 24 March 2010 01:37 PM   [ # 90 ]   [ Rating: 0 ]
Avatar
Joined: 2008-03-04
59 posts

Hello, DataMapper OverZealous Edition is great for me. But i have a question.
Can i set the primary key field name?. I have a lot of tables that primary key field name is “xxx_id”. And i don’t want to change it to “id”.

I want to do something like this:

class Test extends DataMapper {
    
    
var $table 'testing';
    var 
$pk_filedname 'test_id'//<----

    
function __construct($id NULL)
    
{
        parent
::__construct($id);
    
}

is this possible ?

Thanks.

 Signature 

?

 
Posted: 24 March 2010 01:39 PM   [ # 91 ]   [ Rating: 0 ]
Avatar
Joined: 2008-10-08
1039 posts

@Atas

No.  DMZ requires certain concessions in the database design.

Also, this is clearly stated in the manual.

 Signature 

Phil DeJarnett
  OverZealous Creations, LLC

 
Posted: 24 March 2010 01:50 PM   [ # 92 ]   [ Rating: 0 ]
Avatar
Joined: 2008-03-04
59 posts

Ok,

I am going to rename my Primary Keys…

Thanks!

 Signature 

?

 
Posted: 24 March 2010 05:57 PM   [ # 93 ]   [ Rating: 0 ]
Joined: 2009-06-18
279 posts

I have one question, and please don’t send me to read the manual.

I have one parent table, and 4 other child tables. One field from my parent is present in the other 4 child tables. Is there any way I can do this: update only the main parent table and all child table will get updated automatically?

 
Posted: 24 March 2010 06:03 PM   [ # 94 ]   [ Rating: 0 ]
Avatar
Joined: 2008-10-08
1039 posts

@Mareshal
No.  Write a custom method on the parent table’s model, or override the save function on the parent table:

class Parent extends DataMapper {
    
function save($object ''$related_field ''{
        $needs_update 
= ($this->shared_field === $this->stored->shared_field);
        
$ret parent::$save();
        if(
$need_update && $ret{
            
if($this->other_object->get()->exists()) {
                $this
->other_object->shared_field $this->shared_field;
                
$this->other_object->save();
            
}
            
// repeat for each object
        
}
        
return $ret;
    
}

You may need to add in special code to check for new objects.  This is just an example, so don’t take it as gospel.

 Signature 

Phil DeJarnett
  OverZealous Creations, LLC

 
Posted: 25 March 2010 12:38 AM   [ # 95 ]   [ Rating: 0 ]
Avatar
Joined: 2008-03-04
59 posts

Hello, i have the following models and tables:

CREATE TABLE `provincia` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `nombre` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1;

class Provincia extends DataMapper {
    
    
var $table 'provincia';
    var 
$has_many = array("localidad");
    
    function 
__construct($id NULL)
    
{
        parent
::__construct($id);
    
}
    

CREATE TABLE `localidad` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `nombre` varchar(255) DEFAULT NULL,
  `provincia_id` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1;

class Localidad extends DataMapper {
    
    
var $table 'localidad';

    function 
__construct($id NULL)
    
{
        parent
::__construct($id);
    
}
    

I am triying to get all “localidades” by “provincia” but an error message appears saying “DataMapper Error: ‘provincia’ is not a valid parent relationship for Localidad. Are your relationships configured correctly?”

I don’t know what i am doing wrong.

Provincia is State and Localidad is like City.

Sorry my english, i am learning…

Thanks…

 Signature 

?

 
6 of 62
6