Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Interbase, Can't get DEFAULT Values to work

Posted on 2001-08-03
10
Medium Priority
?
162 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
Independent Software Vendors: 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!

 

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 600 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

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!

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

963 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