Jump to content

Normal Query Syntax Not Working, '' For Numeric


Recommended Posts

On one customer website, the customer cannot insert any rows if a field is left blank and the column is a number. In short...

''

... is not being accepted for numeric or decimal columns.

 

I've never had this on any other customer site, and it's pretty standard to use '' for column values in by MySQL (and even MS-SQL).

 

What would be preventing this? I assume it's a MySQL setting somehow? For what it's worth, this customer is on a Windows server, much to my chagrin.

MS-SQL allows this, too.

 

I think it depends on the language; PHP is weakly-typed so its database pretty much needs to allow this type of syntax. If you're in C# with an MS-SQL back-end, then you'll know the data type and quoting isn't necessary.

 

Again, without writing all sorts of code and/or performing extra reads, quoted values is the only way to go. There's no easy solution without it.

I'm saying, how can the code dynamically generate the query without quotes? (Without doing extra reads or writing lots of extra code.)

 

You can't. You get data from a form, and you don't know anything except that you have data. The code doesn't know that some textbox is numeric only, or that some select box values are ints.

Chest-thump? Really? Grow up.

 

You leave out quotes for values that are going into a numeric data type field in the database, after validating the data/casting it as the correct type.

You have yet to answer my question. How does the app know the data type?

 

You either write a bunch of extra code or you do extra DB reads. Or you use quotes, like all DB engines allow, and everything works as expected.

Edited by timneu22

Who's on first??

 

But how does the app KNOW WHAT THE CORRECT DATA TYPE IS? Come on, how many times can you not answer the question?

 

You either write lots of extra code or do lots of extra DB reads. Or you use quotes like all DB engines allow.

No, you don't "write lots of extra code". Where do you even get that idea? If you wrote the code, you designed the database, you know what data comes from where, then you know what data type it is, and where it should be going. How can you NOT know what data type should be going in which field in the database? If you don't understand this, it certainly isn't because I haven't answered the question.

You clearly have never written an application that uses abstraction and base classes. This is basic stuff.

 

The base class doesn't know about every field for every column. It knows "I have these POST values" and "here's my table". That's all it knows. The base class generates a query from that. It's unaware of every column type.

 

So the answer is .... quoted columns in the query string. A standard feature in DB engines.

 

I'm got the answer to my specific question a while ago. Our conversation, while enjoyable, didn't help anyone. I'm no longer following this thread.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.