CodeIgniter Forums
CI 1.7 - Forge Problems - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: CI 1.7 - Forge Problems (/showthread.php?tid=12588)

Pages: 1 2


CI 1.7 - Forge Problems - El Forum - 10-24-2008

[eluser]AgentPhoenix[/eluser]
Just a repeat of what I had in the other thread, but it really didn't fit in the other thread, so tossing it its own thread (sorry for hijacking!). I'm having major issues with adding a primary key through the Forge. Originally I was trying to use it with my massive install script, but I thought I'd simplify it to see if it was something in my script. Here is what's in my controller:

Code:
$role_id = array(
    'role_id' => array(
        'type' => 'INT',
        'constraint' => 6,
        'auto_increment' => TRUE));
                            
$this->dbforge->add_field($role_id);
$this->dbforge->add_key('role_id', TRUE);
$this->dbforge->create_table('roles', TRUE);

Running that returns the following errors:

Code:
Message: Array to string conversion
Filename: database/DB_driver.php
Line Number: 1206

Message: Array to string conversion
Filename: database/DB_driver.php
Line Number: 1215

Message: Array to string conversion
Filename: database/DB_driver.php
Line Number: 1291

Message: Array to string conversion
Filename: mysql/mysql_driver.php
Line Number: 438

Message: implode() [function.implode]: Invalid arguments passed
Filename: mysql/mysql_forge.php
Line Number: 158

The query it tries to spit out is:

Code:
Error Number: 1064

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') ) DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci' at line 3

CREATE TABLE IF NOT EXISTS `ci170_roles` ( `role_id` INT(6) AUTO_INCREMENT, PRIMARY KEY `role_id` () ) DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;

Any help would be awesome!


CI 1.7 - Forge Problems - El Forum - 10-24-2008

[eluser]AgentPhoenix[/eluser]
I've been trying to track this stuff down and think I have a lead on it. The problem seems to be starting in the MySQL Forge file, lines 157 and 158.

Code:
$primary_keys = $this->db->_protect_identifiers($primary_keys);
$sql .= ",\n\tPRIMARY KEY ".$key_name." (" . implode(', ', $primary_keys) . ")";

Line 157 is being fed an array, but _protect_identifiers doesn't know how to handle an array, it assumes it's a single item coming in. I tried adding some code similar to what's in add_key, but then it just returns a string called Array. Of course, line 158 is expecting an array because it tries to implode the variable. So it seems like the Forge has its wires crossed a little bit. I'm just not sure exactly how to fix it.


CI 1.7 - Forge Problems - El Forum - 10-24-2008

[eluser]AgentPhoenix[/eluser]
Not sure if this is the right fix, so if one of the CI devs could jump in, that'd be awesome. I updated DB_driver.php so that _protect_identifiers knew how to deal with an array. Below is what I added to the top of the method.

Code:
if (is_array($item))
{
    $array = array();
            
    foreach($item as $one)
    {
        $array[] = $this->_protect_identifiers($one, $prefix_single, $protect_identifiers, $field_exists);
    }
            
    return $array;
}



CI 1.7 - Forge Problems - El Forum - 10-26-2008

[eluser]caseyamcl[/eluser]
Yep, This problem is the same for me.

Creating tables without keys seems to work, but adding a key generates the slew of PHP errors -and- the malformed SQL query. Example of the malformed query in my code:

Code:
CREATE TABLE IF NOT EXISTS `usertracking` ( `session_id` varchar(100), `user_identifier` varchar(255), `request_uri` text, `timestamp` varchar(20), `client_ip` varchar(50), `client_user_agent` text, `referer_page` text, `id` INT(9) AUTO_INCREMENT, PRIMARY KEY `id` () ) DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;

Notice the "PRIMARY KEY `id` (), which should be "PRIMARY KEY (`id`)


CI 1.7 - Forge Problems - El Forum - 11-02-2008

[eluser]ImageSmith[/eluser]
@AgentPhoenix
Ta for the fix. Don't know why one of the CI devs hasn't put in an acknowledgement of the issue.

I have never had much joy with DB Forge so had given up on it until v1.7.
Guess they still have work to do here.


CI 1.7 - Forge Problems - El Forum - 11-03-2008

[eluser]AgentPhoenix[/eluser]
Judging from the bug tracker, they're getting pretty swamped with bug reports and they're also trying to finish up EE 2.0. I'm sure they'll get all these issues squared away in no time. Smile


CI 1.7 - Forge Problems - El Forum - 11-03-2008

[eluser]ImageSmith[/eluser]
yeah, fair cop.
...and I guess there's no shortage of demanding ci users :-P


CI 1.7 - Forge Problems - El Forum - 11-17-2008

[eluser]graf[/eluser]
Just started exploring db_forge and found this problem mentioned in this thread... has anyone developed a steady solution yet?


CI 1.7 - Forge Problems - El Forum - 11-17-2008

[eluser]ImageSmith[/eluser]
graf, the fix that AgentPhoenix put in above gets it going.


CI 1.7 - Forge Problems - El Forum - 11-18-2008

[eluser]ctype[/eluser]
Look like I also added "another" fix Sad
http://ellislab.com/forums/viewthread/97202/