Jump to content

(Resolved) Sql

Featured Replies

Hi,

 

Im trying to create a constraint which will have a fixed length of 10.

The constraint i have used is:

CHAR(10)constraint

Now according to the books "CHAR" should be a fixed length, in my terms a fixed length of 10, however, i have just tried to insert some values consisting of 9 characters and it was accepted.

 

Do i need to add something to the constraint to allow the user to input exactly a fixed length of 10?

Hmm, I'm not sure about this, but I did a quick look on google for you:

 

http://www.devguru.com/Technologies/jetsql/quickref/constraint.html

 

This is Jet SQL so may be completely wrong, but apparently a constraint just limits what values you can put into your field, and perhaps reference other fields from different tables. Having not used it before, I'm not sure, but I don't think it's what you're after.

Using a constraint like char[10] makes 10 the MAXIMUM, to set a minimum requirement you'll need to script a checker onto the page.

  • Author
Using a constraint like char[10] makes 10 the MAXIMUM,

 

i thougut varchar(2) sets a maximum length.

So what kind oif script checker do i need to check the length?

Varchar(2) is the same as CHAR(2) as far as this example is concerned ;)

 

Like Faf says Ann, you need to validate the length of the string with a script before inserting it.

 

if (strlen($THE_STRING) == 10) {
 // do the insert query
} else {
 // send the user back to the form (or whatever)
 // add a warning message for good measure
}

This is such a small check that it would be better to do it server-side rather than client-side, and thereby reduce the threat to platform independence.

True, although sometimes it's more convenient to do a client-side check if it's only small and supported by most browsers.

 

If you've got a big form for instance, then you don't want to have to re-insert all the information into your fields, and although this could be overcome with some more code on your server-side application, it's easier to write a couple lines of Javascript than 30 lines of php.

True, although it does depend how you parse the info.

Archived

This topic is now archived and is closed to further replies.

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.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.