Part of the EllisLab Network
   
3 of 3
3
1.6.2 DB bug - empty strings not recognized in AR
Posted: 13 June 2008 05:00 PM   [ Ignore ]   [ # 31 ]  
Summer Student
Total Posts:  29
Joined  12-03-2007

For me the problem arose with the PayPal IPN Library.  Sometimes certain information just isn’t passed back from PayPal.  For instance:

$array = array("address_country" => $this->paypal_lib->ipn_data['address_city'])

Sometimes, depending on the transaction coming back, is not filled in / has no value; which is where my problem lies.

Profile
 
 
Posted: 15 June 2008 12:45 PM   [ Ignore ]   [ # 32 ]  
Summer Student
Total Posts:  29
Joined  12-03-2007

Another note, I was mistaken.  It does not work with the set() function either inside a model.

Profile
 
 
Posted: 15 June 2008 07:30 PM   [ Ignore ]   [ # 33 ]  
Administrator
Avatar
RankRankRankRankRankRank
Total Posts:  6593
Joined  03-23-2006

Patrick, can you write me the simplest test case possible that I need to recreate?

 Signature 

DerekAllard.com - CodeIgniter, ExpressionEngine, and the World of Web Design
BambooInvoice - Open Source, CodeIgniter powered invoicing.

Profile
MSG
 
 
Posted: 15 June 2008 09:17 PM   [ Ignore ]   [ # 34 ]  
Summer Student
Total Posts:  29
Joined  12-03-2007

Derek,

It’s simply where you have the following situation.  You have an array being constructed and you have an insert statement.  You are building the insert via array or set and sometimes data coming back from PayPal may have IPN data for ALL values on the insert array and sometimes it may not.  This used to work pre 1.6.2 no problem, values could be anything.

In the paypal library, the following class var is:
var $ipn_data = array();

Within a controller, you would have something like the following:

class Paypal extends Controller {

     
function __construct() {
    parent
::Controller();
    
$this->load->library('Paypal_Lib');
     
}

     
function paypal_ipn() {
          
// -- Validate the IPN, insert data into DB
          // -- Neither this method, nor the set method works if ipn_data['value'] is NOT set to anything.
          
$insert_arr = array(
                      
"txn_id" => $this->paypal_lib->ipn_data['txn_data'],
                      
"residence_state" => $this->paypal_lib->ipn_data['residence_state']
                     
);
          
$this->db->insert('db_table');
     
}
        
}

I realize this isn’t quite a complete test case but I feel the explanation should suffice as the changes suggested in this thread should solve the problem.

Let’s say $ipn_data array doesn’t have the residence_state value in it because it wasn’t passed from PayPal.  So you have an insert array that accounts for that value at ALL times.  Instead of forcing manual checks and populating the array, it used to be automatic in prior CI versions.

Profile
 
 
Posted: 15 June 2008 09:29 PM   [ Ignore ]   [ # 35 ]  
Administrator
Avatar
RankRankRankRankRankRank
Total Posts:  6593
Joined  03-23-2006

Patrick.  Sorry, I’m not trying to make you work here, but does this error present itself if you don’t use any external libraries?  If so, can you give me sample controller code?  No need for a model or view.

 Signature 

DerekAllard.com - CodeIgniter, ExpressionEngine, and the World of Web Design
BambooInvoice - Open Source, CodeIgniter powered invoicing.

Profile
MSG
 
 
Posted: 15 June 2008 10:20 PM   [ Ignore ]   [ # 36 ]  
Summer Student
Total Posts:  29
Joined  12-03-2007

Derek,

Below is the following controller, obviously you’ll need a test DB table.  Prior to 1.6.2, it didn’t matter if txn_id existed in the array or not.  It basically converted the value of txn_id to null / ’‘ if it wasn’t in the $array.  Now, it just throws an error and doesn’t work….

This was being tested on 1.6.2, I will try the AR_db class in the svn right now.

class Test extends Controller {

    
function __construct() {
        parent
::Controller();
    
}
    
    
function index() {
        
        $array
= array('first_name' => 'John', 'last_name' => 'Doe');
        
        
$this->db->set('first_name', $array['first_name']);
        
$this->db->set('last_name', $array['last_name']);
        
$this->db->set('txn_id', $array['txn_id']);
        
$this->db->insert('test');
    
}
}

Profile
 
 
Posted: 16 June 2008 12:43 AM   [ Ignore ]   [ # 37 ]  
Summer Student
Total Posts:  29
Joined  12-03-2007

Interesting….

Neither method chaining or normal active record queries are working for me with the SVN version.

Profile
 
 
Posted: 16 June 2008 08:46 AM   [ Ignore ]   [ # 38 ]  
Summer Student
Total Posts:  24
Joined  06-26-2007

Just wanted to say thank you for the fix, works perfectly for me. (I was about to file the same bug report before I stumbled upon this thread wink)

Profile
 
 
Posted: 16 June 2008 11:51 AM   [ Ignore ]   [ # 39 ]  
Administrator
Avatar
RankRankRankRankRankRank
Total Posts:  6593
Joined  03-23-2006

Hey Patrick.  This is a different issue.  I don’t think we want AR filling in for undefined variables for a developer.  This is different then the issue of empty quotes discussed in this thread.  If you’d like to open up a new thread to discuss it, that may be the best way to go.

Armchair Samurai, thanks for the feedback.

Stanley, XtraFile, GDias, Newton Wagner, spib - you each had input into this issue.  Does the new version exhibit the same behaviour?  Do you consider it resolved?

 Signature 

DerekAllard.com - CodeIgniter, ExpressionEngine, and the World of Web Design
BambooInvoice - Open Source, CodeIgniter powered invoicing.

Profile
MSG
 
 
   
3 of 3
3
 
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 719, on June 06, 2008 10:16 AM
Total Registered Members: 62653 Total Logged-in Users: 35
Total Topics: 77188 Total Anonymous Users: 0
Total Replies: 416684 Total Guests: 209
Total Posts: 493872    
Members ( View Memberlist )