Solved

Interbase, Can't get DEFAULT Values to work

Posted on 2001-08-03
10
154 Views
Last Modified: 2010-08-05
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
Comment
Question by:elkiors
  • 6
  • 3
10 Comments
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6349648
? 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
 

Author Comment

by:elkiors
ID: 6349727
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
 
LVL 4

Expert Comment

by:YodaMage
ID: 6350318
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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:elkiors
ID: 6351054
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
 

Author Comment

by:elkiors
ID: 6355185
Upping the points 'cos I could really do with some help on this now.

thanks in advance

Darren
0
 
LVL 27

Accepted Solution

by:
kretzschmar earned 200 total points
ID: 6362848
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
 

Author Comment

by:elkiors
ID: 6362903
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
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6363051
>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
 

Author Comment

by:elkiors
ID: 6363114
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
 

Author Comment

by:elkiors
ID: 6363116
As promised :-)
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question