Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 165
  • Last Modified:

Interbase, Can't get DEFAULT Values to work

I'm trying to get to grips with Interbase6/D5. For some reason I can't get records to produce default values.

eg.

CREATE TABLE "TEST"
(
  "P1"     VARCHAR(10) NOT NULL,
  "U1"     VARCHAR(31) DEFAULT USER,
  "T1"     VARCHAR(5) DEFAULT 'abcde',
  "BLAH" DATE DEFAULT 'NOW',
CONSTRAINT "PK_P1" PRIMARY KEY ("P1")
);

Nothing gets given a default value when I do a new record, not even in IBConsole.

Any ideas what I'm doing wrong ?
Do I have to set triggers or something ?
0
elkiors
Asked:
elkiors
  • 6
  • 3
1 Solution
 
kretzschmarCommented:
? didn't have any problem with this,
must only remove the doublequotes from the create statement

CREATE TABLE TEST
(
P1     VARCHAR(10) NOT NULL,
U1     VARCHAR(31) DEFAULT USER,
T1     VARCHAR(5) DEFAULT 'abcde',
BLAH DATE DEFAULT 'NOW',
CONSTRAINT PK_P1 PRIMARY KEY (P1)
)

tested with SQL-Explorer

meikl ;-)
0
 
elkiorsAuthor Commented:
Meikl,

A while since we've spoken.

the metadata for the example was copy pasted straight from IBConsole, so I assume the syntax is ok. It's just that I can't get this table to generate the default values when I connect to it through IBX components or through the data view of IBConsole. I also tried doing the same with the example employee.gdb with the same problem.

If I try to do a 'new record' no defaults appear in DB aware components - and posting a record with just the primary key field filled doesn't store any defaults in the DB.

Your further thoughts are appreciated.

Thanks,

Darren
0
 
YodaMageCommented:
I ran it through using IBExpert to IB 6.01 without any problem. (Dialect 3, No Charset), though I did use the BDE and therefore had to drop the Date field type in favor of a Timestamp due to BDE Dialect restrictions.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
elkiorsAuthor Commented:
ok, I think I'm slowly getting a bit more of an idea about this now.

if I do a pure 'INSERT INTO' through ISQL and only specify a value for 'p1' then IB generates the default values ... yipee !. But if I try and create a record through a DBGrid, null values get stored where there should be the defaults. What do I need to do to stop this happening ?

thanks

Darren
0
 
elkiorsAuthor Commented:
Upping the points 'cos I could really do with some help on this now.

thanks in advance

Darren
0
 
kretzschmarCommented:
hi darren,

not so easy to force the default values,
because the components do explicit inserts null-values,
if the content is empty.

you could do a bit dynamic-sql byself in the before post event of the dataset and insert the record by skipping the fields, which content is empty

so you could bypass the default insert of the dataset-component

meikl ;-)
0
 
elkiorsAuthor Commented:
thanks meikl,

now I know it's not just me going insane :)

I've managed to get around it for now by not using data-aware controls and doing the insert with a stored procedure on the server side in my real app.

Is there a way to get the default values passed into data-aware controls on a IBdataset.insert event? I know I can use a trigger to handle a generator value but what about none primary fields ?

Is this a problem with all SQL servers or just a quirk of Interbase ?

thanks for your continued support

Darren
0
 
kretzschmarCommented:
>Is this a problem with all SQL servers or just a quirk of Interbase ?

i guess its a problem of all sql-servers, because the server do only provide the default-value if the field is not in the insert-statement.

hmm, about to forward the defaults to the controls,
i must take a look to the systemtables, where the defaults are stored somewhere. you could just read out there the default-value in the ongettext-event of the tfield

meikl ;-)
0
 
elkiorsAuthor Commented:
thanks meikl,

it really helps me alot to be able to bounce these problems/ideas off people - I guess it's the only way we can learn and move ourselves forward :-)

I suppose I need to accept your comment stamp 08/08/2001 12:08AM PST as an answer for this q since it most closely represents the solution of stored proc.

thanks for the idea of using the ongettext event, I'll investigate that a bit more.

It's a shame that IBX components don't have the extra handling for what must be a common problem built into them :-)

Cheers

Darren
0
 
elkiorsAuthor Commented:
As promised :-)
0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

  • 6
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now