Welcome Guest, Not a member yet? Register   Sign In
How does CodeIgniter handle int's when it builds a query statement..
#1

[eluser]Snaver[/eluser]
Ok you'll have to bear with me on this one, hopefully I can explain my problem.

I have a set of data that im saving to the DB and I'm using Codeigniters Active Record Class to automatically handle the building and insertion of the query, like so:

Code:
$this->db->insert('table', $data);

Now with my DB schema, for one of the columns the type is set to decimal. The problem I'm having is that sometimes the data passed in to my data array will be blank and when it comes to building the query, the query will attempt to place a blank string into the decimal field, which i think is causing an error. I've setup a default value for the field but I think its not triggering as doesn't the data being passed in need to be NULL?

Should Codeigniters database insert method build the query strings differently? Below are two identical queries, however the difference comes when inserting the values into the query, ones wrapped with ' and the other is not, as it's a value.

At the moment I think Codeigniter wraps all int's with a '

Code:
INSERT INTO e2_products_alt (txt, dec) VALUES ('asdgds', '345')
Code:
INSERT INTO e2_products_alt (txt, dec) VALUES ('asdgds', 345)


Code:
A Database Error Occurred
Error Number: 1366

Incorrect decimal value: '' for column 'efectivecostmonth' at row 1

INSERT INTO e2_products_alt (code, name, make, model, colour, style, quadband, bluetooth, triband, gprs, wap, radio, camera, video, tcode, tname, tnetwork, tcontractlenght, hsetprice, costpermonth, mins, minstype, text, giftcode, giftname, offerlenght, offerprice, monthsfree, halfprice, cashback, producturl, basketurl, efectivecostmonth, image, thumb, model_url) VALUES ('PAY1800_EOJT_WEB10ETOPUP', 'Nokia 1800', 'Nokia', '1800', 'Black', '', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'EOJT', 'Orange Starter', 'payg', '0', '4.90', '0.00', 'Pay As You Go', 'PA', 'Pay As You Go', 'WEB10ETOPUP', '£10 Airtime Top-Up', '0', '0.00', '0', '0', '0.00', 'http://www.e2save.com/payg-mobile-phone/Nokia-1800/1800?tariffcode=EOJT', 'http://www.e2save.com/?&model=1800&tariff=EOJT&gift=WEB10ETOPUP&hs=PAY1800', '', 'http://www.e2save.com/feedimage.php?id=1800', 'http://www.e2save.com/feedimage.php?id=1800&size=sm', '1800')

Filename: /var/www/vhosts/example.com/httpdocs/addons/modules/phones/controllers/admin.php

Line Number: 217

Sorry if this doesn't make sense, I'll try and clarify a bit more later but just wanted to get this post down.
#2

[eluser]danmontgomery[/eluser]
The issue isn't the quotes, it's that you're trying to insert a blank value into a column which doesn't accept blank values. '0.00' will work just the same as 0.00




Theme © iAndrew 2016 - Forum software by © MyBB