Recent

Author Topic: SqlDB Field Attributes  (Read 5656 times)

RudieD

  • Full Member
  • ***
  • Posts: 234
SqlDB Field Attributes
« on: March 06, 2006, 02:41:40 pm »
Does any one know how to extract the Required attribute of a result field on MySQL 4.1/5.0 database ?
The FRED Trainer. (Training FRED with Lazarus/FPC)

RudieD

  • Full Member
  • ***
  • Posts: 234
RE: SqlDB Field Attributes
« Reply #1 on: March 06, 2006, 09:18:46 pm »
I have now tried to Open "describe TableName" but something is blocking it with message "Cannot open a non-select statement". Any other ideas ?
The FRED Trainer. (Training FRED with Lazarus/FPC)

matthijs

  • Hero Member
  • *****
  • Posts: 537
RE: SqlDB Field Attributes
« Reply #2 on: March 07, 2006, 08:25:50 am »
You could check the required property of the field.
Something like:
Code: [Select]

  if SQLQuery1.Fields[0].Required then ShowMessage('required')
What's in a sig? Would my posting look less if it didnot have a sig? (Free after William S.) :)

:( Why cannot I upload my own Avatar? :(

RudieD

  • Full Member
  • ***
  • Posts: 234
RE: SqlDB Field Attributes
« Reply #3 on: March 07, 2006, 09:38:52 am »
Thats the problem, the Required (as well as Prcision) property is not extracted from the result. It has been hard-code as far as I could see.
Any other ideas ?
The FRED Trainer. (Training FRED with Lazarus/FPC)

matthijs

  • Hero Member
  • *****
  • Posts: 537
RE: SqlDB Field Attributes
« Reply #4 on: March 07, 2006, 12:15:12 pm »
Then you have to ask your DB-server for this information. You could enter a query like
Code: [Select]
SELECT COLUMN_NAME, DATA_TYPE, IS_NULLABLE, COLUMN_DEFAULT
  FROM INFORMATION_SCHEMA.COLUMNS
  WHERE table_name = 'tbl_name'
  AND table_schema = 'db_name'
  AND column_name LIKE 'column_name'

If Is_Nullable then it will not be a required field.

Information like this can be easily found on online mysql docs. ;)

[edit]Added just one word, but rather important.  :oops:
What's in a sig? Would my posting look less if it didnot have a sig? (Free after William S.) :)

:( Why cannot I upload my own Avatar? :(

RudieD

  • Full Member
  • ***
  • Posts: 234
RE: SqlDB Field Attributes
« Reply #5 on: March 08, 2006, 11:32:38 am »
Thanks matthijs, I'll go have a look there.
The FRED Trainer. (Training FRED with Lazarus/FPC)

 

TinyPortal © 2005-2018