Part of the EllisLab Network
   
 
CI 1.7 - Forge Problems
Posted: 24 October 2008 10:19 AM   [ Ignore ]  
Lab Assistant
RankRank
Total Posts:  172
Joined  03-27-2008

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:

$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:

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:

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!

Profile
 
 
Posted: 24 October 2008 12:44 PM   [ Ignore ]   [ # 1 ]  
Lab Assistant
RankRank
Total Posts:  172
Joined  03-27-2008

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.

$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.

Profile
 
 
Posted: 24 October 2008 02:12 PM   [ Ignore ]   [ # 2 ]  
Lab Assistant
RankRank
Total Posts:  172
Joined  03-27-2008

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.

if (is_array($item))
{
    $array
= array();
            
    foreach(
$item as $one)
    
{
        $array[]
= $this->_protect_identifiers($one, $prefix_single, $protect_identifiers, $field_exists);
    
}
            
    
return $array;
}
Profile
 
 
Posted: 26 October 2008 12:57 PM   [ Ignore ]   [ # 3 ]  
Summer Student
Total Posts:  7
Joined  04-08-2008

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:

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`)

 Signature 


Casey McLaughlin
I’m on Twitter

Profile
 
 
Posted: 02 November 2008 09:52 PM   [ Ignore ]   [ # 4 ]  
Grad Student
Avatar
Rank
Total Posts:  80
Joined  05-10-2007

@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.

 Signature 

Cairns Web Designer
Cairns Web Design

Profile
 
 
Posted: 03 November 2008 08:53 AM   [ Ignore ]   [ # 5 ]  
Lab Assistant
RankRank
Total Posts:  172
Joined  03-27-2008

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

Profile
 
 
Posted: 03 November 2008 05:08 PM   [ Ignore ]   [ # 6 ]  
Grad Student
Avatar
Rank
Total Posts:  80
Joined  05-10-2007

yeah, fair cop.
...and I guess there’s no shortage of demanding ci users tongue laugh

 Signature 

Cairns Web Designer
Cairns Web Design

Profile
 
 
Posted: 18 November 2008 12:14 AM   [ Ignore ]   [ # 7 ]  
Summer Student
Total Posts:  11
Joined  11-18-2008

Just started exploring db_forge and found this problem mentioned in this thread… has anyone developed a steady solution yet?

Profile
 
 
Posted: 18 November 2008 12:24 AM   [ Ignore ]   [ # 8 ]  
Grad Student
Avatar
Rank
Total Posts:  80
Joined  05-10-2007

graf, the fix that AgentPhoenix put in above gets it going.

 Signature 

Cairns Web Designer
Cairns Web Design

Profile
 
 
Posted: 18 November 2008 10:36 AM   [ Ignore ]   [ # 9 ]  
Summer Student
Total Posts:  4
Joined  11-18-2008

Look like I also added “another” fix :(
http://codeigniter.com/forums/viewthread/97202/

Profile
 
 
Posted: 18 November 2008 10:39 AM   [ Ignore ]   [ # 10 ]  
Summer Student
Total Posts:  4
Joined  11-18-2008
ctype - 18 November 2008 10:36 AM

Look like I also added “another” fix :(
http://codeigniter.com/forums/viewthread/97202/

Sorry. This posted by error

Profile
 
 
Posted: 08 December 2008 09:54 AM   [ Ignore ]   [ # 11 ]  
Grad Student
Avatar
Rank
Total Posts:  67
Joined  02-04-2008

This was very helpful for me - I just added the logic at the top of the method and voila!

Many thanks!

 Signature 

“...‘Beyond Civilization’ isn’t a geographical space up in the mountains or on some remote desert isle. It’s a cultural space that opens up among people with new minds.” -Daniel Quinn, Beyond Civilization

Profile
 
 
Posted: 09 December 2008 08:13 AM   [ Ignore ]   [ # 12 ]  
Lab Assistant
RankRank
Total Posts:  172
Joined  03-27-2008

No problem!  Here’s to hoping the fix (this or a better one) lands in CI 1.7.1.  smile

Profile
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 819, on March 11, 2010 11:15 AM
Total Registered Members: 120127 Total Logged-in Users: 47
Total Topics: 126264 Total Anonymous Users: 2
Total Replies: 664081 Total Guests: 371
Total Posts: 790345    
Members ( View Memberlist )