Solved

Interbase, Can't get DEFAULT Values to work

Posted on 2001-08-03
10
148 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
Comment Utility
? 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
Comment Utility
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
Comment Utility
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
 

Author Comment

by:elkiors
Comment Utility
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
Comment Utility
Upping the points 'cos I could really do with some help on this now.

thanks in advance

Darren
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 27

Accepted Solution

by:
kretzschmar earned 200 total points
Comment Utility
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
Comment Utility
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
Comment Utility
>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
Comment Utility
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
Comment Utility
As promised :-)
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

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 this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

771 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now