Welcome Guest, Not a member yet? Register   Sign In
1.6.2 DB bug - empty strings not recognized in AR
#31

[eluser]nmormino[/eluser]
[quote author="XtraFile" date="1210909812"]Aww, I just submitted a bug report on this as well.
An empty WHERE statement should be '', WHERE is considered a string by the Database engine and a value, even if empty, IS needed for valid syntax.

I propose the following code change, added after line 463:
Code:
else if($v === '')
{
    $v = " ''";
}

There should be no escaping here, no need to escape nothing.

-Matt[/quote]

This works perfectly fine for me. Funny thing is, i implemented this same fix before having read it. Also for the whole debate about submitting an empty string.
Code:
$this->db->where('field', '');
If you were to ask me, I would say I'm submitting an empty string, not submitting "nothing", submitting nothing would be
Code:
$this->db->where('field', );
and we all know that PHP would choke on this.

But still, thanks DEV team, CodeIgniter has been a staple in my site development for a year now and I find it irreplaceable. The fix for this bug is so simple and it seems that many people have gotten a little bent out over it.

-Noah
#32

[eluser]PV-Patrick[/eluser]
For me the problem arose with the PayPal IPN Library. Sometimes certain information just isn't passed back from PayPal. For instance:

Code:
$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.
#33

[eluser]PV-Patrick[/eluser]
Another note, I was mistaken. It does not work with the set() function either inside a model.
#34

[eluser]Derek Allard[/eluser]
Patrick, can you write me the simplest test case possible that I need to recreate?
#35

[eluser]PV-Patrick[/eluser]
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:
Code:
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.
#36

[eluser]Derek Allard[/eluser]
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.
#37

[eluser]PV-Patrick[/eluser]
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.

Code:
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');
    }
}
#38

[eluser]PV-Patrick[/eluser]
Interesting....

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

[eluser]MaDe[/eluser]
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)
#40

[eluser]Derek Allard[/eluser]
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?




Theme © iAndrew 2016 - Forum software by © MyBB