Default values

Posts   
 
    
tomc
User
Posts: 31
Joined: 28-Jun-2006
# Posted on: 10-Oct-2006 22:13:44   

It does not appear that there is any way to determine if a given field is assigned a default value. It would be nice if there were, at the very least, a HasDefaultValue property. I am, of course, referring to default values that are assigned by the DBMS.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39859
Joined: 17-Aug-2003
# Posted on: 11-Oct-2006 09:59:07   

In which context do you want to know this? At runtime, when you created a new entity? Or when you save an entity and fetch it back?

Frans Bouma | Lead developer LLBLGen Pro
tomc
User
Posts: 31
Joined: 28-Jun-2006
# Posted on: 17-Oct-2006 18:17:28   

I do not believe that a context is really required; the default value is a property of the field is it not? I consider default values to be part of the meta-data and therefore processed during the LLBLGen code generation, i.e. I do not expect any queries to be performed when I create a new entity. As I stated, it would be nice if it were possible to determine if a field would be assigned a default value. Better still would be the actual default value; I am aware that this can be more problematic because default values may be calling system functions, etc., but some exposure would be better than none :-)

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39859
Joined: 17-Aug-2003
# Posted on: 18-Oct-2006 10:35:21   

Ok, with 'context' I didn't mean the Context class wink

The default value as defined in the database schema isn't emitted into the generated code. This thus means that you can't determine using the generated code if a field has a default value defined in the DB.

If you want that, you can generate such a structure yourself, as the meta-data is available to you in the project. You could create a small .lpt template which generates a static class which provides this info to you based on a specified field.

Frans Bouma | Lead developer LLBLGen Pro
tomc
User
Posts: 31
Joined: 28-Jun-2006
# Posted on: 02-Nov-2006 22:32:11   

Frans,

In pursuing your suggested approach, I wrote a small lpt template into which I put the following code.

<~ 
private EntityDefinition _entity;
~>
<% _entity = ((Hashtable) _activeObject)["CurrentEntity"] as EntityDefinition; %>
<% foreach(EntityFieldDefinition  entityFieldDefinition in _entity.Fields) { %>
<%=entityFieldDefinition.FieldName%>:<%=entityFieldDefinition.MappedField.HasDefaultValue %>:<%=entityFieldDefinition.MappedField.DefaultValue%>
<% } %>

The HasDefaultValue property always returns False and the DefaultValue is an empty string even if the field is assigned a default value in the database.

I am using the Oracle 10g driver.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39859
Joined: 17-Aug-2003
# Posted on: 03-Nov-2006 11:46:32   

Hmm, the default value is read from the meta-data, as in: (example)

SELECT COLUMN_NAME, DATA_TYPE, DATA_LENGTH, DATA_PRECISION, DATA_SCALE, NULLABLE, DATA_DEFAULT FROM ALL_TAB_COLUMNS WHERE OWNER='SCOTT' AND TABLE_NAME = 'EMP' ORDER BY TABLE_NAME ASC, COLUMN_ID ASC

if you run that query on the oraclebox for the table/schema in which you've defined a default, does it show up under DATA_DEFAULT?

Frans Bouma | Lead developer LLBLGen Pro
tomc
User
Posts: 31
Joined: 28-Jun-2006
# Posted on: 03-Nov-2006 21:37:28   

Yes.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39859
Joined: 17-Aug-2003
# Posted on: 05-Nov-2006 13:09:29   

Hmm. Then it IS read into the table field properties. Which llblgen pro version are you using, 1.0 or 2.0? If you're using 2.0, you can use the project inspector plugin by right-clicking the project node -> run plugin. And then browse to the catalog, table, field and check if the default value is indeed read into the catalog element. Could you check that for me please?

Frans Bouma | Lead developer LLBLGen Pro
tomc
User
Posts: 31
Joined: 28-Jun-2006
# Posted on: 07-Nov-2006 17:51:21   

I am using 2.0. All the default values are blank in the inspector plugin.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39859
Joined: 17-Aug-2003
# Posted on: 07-Nov-2006 18:14:54   

tomc wrote:

I am using 2.0. All the default values are blank in the inspector plugin.

Ok, I'll check it out. It won't be included in the build we'll roll out in half an hour, so a fix (if required) will be in the next build after this one.

Frans Bouma | Lead developer LLBLGen Pro
tomc
User
Posts: 31
Joined: 28-Jun-2006
# Posted on: 07-Nov-2006 18:32:00   

Thank you.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39859
Joined: 17-Aug-2003
# Posted on: 08-Nov-2006 11:34:35   

They're indeed empty. Odd. I'll check it out.

(edit). Very strange. when I execute the meta-data retrieval query: SELECT TABLE_NAME, COLUMN_NAME, DATA_TYPE, DATA_LENGTH, DATA_PRECISION, DATA_SCALE, NULLABLE, DATA_DEFAULT FROM ALL_TAB_COLUMNS WHERE OWNER='SCOTT' AND DATA_DEFAULT IS NOT NULL ORDER BY TABLE_NAME ASC, COLUMN_ID ASC

I get some results, (I have some tables in this schema with defaults), and when I execute the query on the db using the ODP.NET provider, fetching the data into a datatable, and break there, the DATA_DEFAULT columns is empty, always! confused

When I use the MS Oracle provider using driver, it works. Apparently Oracle's ODP.NET doesn't return this value, which is VERY strange to say the least. The column IS there when I view the datatable in the .net 2.0 debugger visualizer for datatables, it's just empty...

It's also not a rights issue, when I login with SYSTEM I can see the results in Aqua Data Studio executing the query directly on oracle, but not in the results returned from the OracleDataAdapter.Fill method in the driver.

The code and query executed using the ms provider or odp.net provider is the same....

Frans Bouma | Lead developer LLBLGen Pro
tomc
User
Posts: 31
Joined: 28-Jun-2006
# Posted on: 28-Nov-2006 19:00:00   

Are there any plans to fix/address this?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39859
Joined: 17-Aug-2003
# Posted on: 28-Nov-2006 19:56:13   

It's not something I can do unfortunately... The data (the result of the query) I get from odp.net doesn't contain the data and then there's no other way to obtain the data...

See my previous post.

Frans Bouma | Lead developer LLBLGen Pro