pg.ddx.io pgsql-odbc@postgresql.org mailing list archive
help / color / mirror / Atom feedRe: Representing Empty DATE values as NULL
4+ messages / 2 participants
[nested] [flat]
* Re: Representing Empty DATE values as NULL
@ 2006-10-06 23:17 Avery Payne <apayne@pcfruit.com>
0 siblings, 1 reply; 4+ messages in thread
From: Avery Payne @ 2006-10-06 23:17 UTC (permalink / raw)
To: Hiroshi Inoue <inoue@tpf.co.jp>; +Cc: pgsql-odbc
I'm sorry that I haven't written in awhile with my findings. I have
completed the FoxPro->ODBC->Access test and the Access ODBC driver
returns a NULL for empty dates. I've also read up a bit more on ODBC
and have figured out the following:
1. ODBC doesn't really support the idea of an empty date. There just
isn't a representation for it. However...
2. ODBC does support returning NULL values, so...
3. Empty dates represented as NULL will have to be an adequate solution
to the issue. This means...
4. ODBC sending data from client->odbc->server with empty dates
translating as NULL should be acceptable, maybe even for the majority of
cases, and
5. ODBC sending data from server->odbc->client with NULL as a date is
the only real representation that can be afforded to any client.
The option to pass "empty dates" as NULLs in client->odbc->server might
be one you wish to make available on a permanent basis; or better yet,
just quietly perform the translation in all cases as a default
behavior. Any comments or suggestions about making it permanent? Will
it mess something up elsewhere?
P.S. I want to personally thank you, Hiroshi, for your tireless time and
effort in looking into this issue. Your willingness to entertain this
new feature is a refreshing break from other open source projects that I
have interacted with in the past, many of which didn't bother to even
look at requests, much less think about them. My hat is off to you.
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Representing Empty DATE values as NULL
@ 2006-10-07 05:23 Dmitriy Ivanov <divanov-NOSP@M-aha.ru>
parent: Avery Payne <apayne@pcfruit.com>
0 siblings, 0 replies; 4+ messages in thread
From: Dmitriy Ivanov @ 2006-10-07 05:23 UTC (permalink / raw)
To: pgsql-odbc
Hello Avery,
"Avery Payne" <apayne@pcfruit.com> wrote:
AP> I'm sorry that I haven't written in awhile with my findings. I
AP> have completed the FoxPro->ODBC->Access test and the Access ODBC
AP> driver returns a NULL for empty dates. I've also read up a bit
AP> more on ODBC and have figured out the following:
AP>
AP> 1. ODBC doesn't really support the idea of an empty date. There
AP> just isn't a representation for it. However...
AP> 2. ODBC does support returning NULL values, so...
AP> 3. Empty dates represented as NULL will have to be an adequate
AP> solution to the issue. This means...
AP> 4. ODBC sending data from client->odbc->server with empty dates
AP> translating as NULL should be acceptable, maybe even for the
AP> majority of cases, and
AP> 5. ODBC sending data from server->odbc->client with NULL as a date
AP> is the only real representation that can be afforded to any client.
AP>
AP> The option to pass "empty dates" as NULLs in client->odbc->server
AP> might be one you wish to make available on a permanent basis; or
AP> better yet, just quietly perform the translation in all cases as a
AP> default behavior. Any comments or suggestions about making it
AP> permanent? Will it mess something up elsewhere?
Excuse my interrupting, I also have no idea what an empty date is. IFAIK,
such a concept neither exists in ODBC nor in Access. What is it?
In my experience, Access can do with NULL quite fine and the Access ODBC
driver too.
--
Sincerely,
Dmitriy Ivanov
Common Lisp ODBC interface - lisp.ystok.ru/ysql.html
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Representing Empty DATE values as NULL
@ 2006-10-12 17:22 Avery Payne <apayne@pcfruit.com>
0 siblings, 1 reply; 4+ messages in thread
From: Avery Payne @ 2006-10-12 17:22 UTC (permalink / raw)
To: pgsql-odbc
>Excuse my interrupting, I also have no idea what an empty date is. IFAIK,
>such a concept neither exists in ODBC nor in Access. What is it?
>
>In my experience, Access can do with NULL quite fine and the Access ODBC
>driver too.
"Empty Date" is a Visual FoxPro concept. It is exactly what it sounds like:
a date field "empty", but not set to NULL. Such fields are directly stored in FoxPro tables
in a pseudo-BCD format; so the date 2001-12-31 is stored as 20011231, with each
digit taking one byte. The problem with this is that FoxPro uses what is commonly
called "data centric" commands to move data around; one of those commands is
APPEND, which takes one table and attempts to "append" all of the data onto the
end of another table, matching fields by name, and discarding data that has
no matching field name. When you attempt to APPEND data that has a row
with an empty date in it, PostgreSQL immediately rejects it (because it's nonsensical)
and the APPEND stops in its tracks. This is but one of many different methods that
can be used to insert data into a table without performing validity checks, there are
others like SCATTER/GATHER, UPDATE FROM, INSERT INTO, etc. that also
perform no validity checks. Because of this, most FoxPro programs perform
data validation up-front, during the point of entry; but this is error-prone and
it is often easier for the programmer to simply accept "empty" fields into a
table than it is to hunt down all fields that are missing data and force them
to a default value of NULL. Note that NULL is also treated much differently in
FoxPro than elsewhere, so most programs don't even bother with NULL and
instead just pass along data in a "raw" format directly to the table. There is
also the EMPTY() function which looks at any field or variable and returns
a value of True if the data passed to it is considered "empty". Taken together,
the net affect on FoxPro programming is to focus on data movement, and worry
about data validation either before, or typically after, the data is "moved".
I know this is horrid and represents many different (and very poor) programming
practices that people should avoid, but it is unfortunately quite common. One of
my primary job functions is to make modifications to the accounting package at
my work to adapt it to changing business needs (let's just say that the environment
I work in constant shifts and it's not unusual to need as many as three
different patches a week to accommodate new business practices). I can't name the
package here in the forum, but anyone with a little sense and some google searching
can determine which of the major medium-sized accounting packages are
written in FoxPro exclusively.
The latest version of this accounting package has the option to switch to SQL Server,
which would fix several technical issues that we encounter (like table size limits of
just 2 Gbyte). The switchover is possible because the package was written
with a "data API" layer that you call in place of the native FoxPro commands,
which abstract away what kind of backend you are using. However, my employer
operates on a very thin profit margin, so money is very tight. This means it is very
attractive to attempt to write our own data API that intercepts calls from the package
and redirects them to some other database, like, oh, I don't know, maybe one
with an elephant for a mascot? :-) But in order to accommodate existing designs and
make the transition much easier, I need to resolve this "empty date" issue. Hiroshi to
the rescue! His work allows me to make this a reality. Now all I have to do is check for
NULL values when fetching dates, something that I can work around using a special
option that allows me to substitute data that is remotely fetched using a type of
"pseudo-view" option. To bad that same option doesn't work in reverse, otherwise
I wouldn't have to bother with this mess.
Note that you can also see "empty" dates in Access. Create a new table with an autonumber
field named "MyID", a date field named "MyDate", and a text field named "MyText".
Open the table after you have saved its definition; then proceed to fill in several rows of data
using just the "MyText" field alone. Each time you do this, the MyID field will auto-increment
and a new number appears; and your text is saved as you move off of each row; but
the "MyDate" field remains -->>EMPTY<<--, which is not the same as NULL. This is a common
theme in Microsoft's smaller database products, where the "databases" function more like
storage containers than actual database engines. Use this with Visual Basic and you
have an environment where MS programmers are most likely to take the raw value
of a field (typically an empty string, "") and pass it directly into the table that is mapped
to the form's field. To prevent PostgreSQL from choking on this, set "Server Side Prepare"
to ON and select option 0x8 when using Hiroshi's experimental driver, and the empty date
fields will be automagically translated to a sane value, NULL, instead of just " / / ".
Hope this has answered your questions...
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Representing Empty DATE values as NULL
@ 2006-10-13 06:41 Dmitriy Ivanov <divanov-NOSP@M-aha.ru>
parent: Avery Payne <apayne@pcfruit.com>
0 siblings, 0 replies; 4+ messages in thread
From: Dmitriy Ivanov @ 2006-10-13 06:41 UTC (permalink / raw)
To: pgsql-odbc
Hello Avery,
"Avery Payne" <apayne@pcfruit.com> wrote:
AP> "Empty Date" is a Visual FoxPro concept.
AP> |...snip...|
I see.
AP> Note that you can also see "empty" dates in Access. Create a new
AP> table with an autonumber field named "MyID", a date field named
AP> "MyDate", and a text field named "MyText". Open the table after you
AP> have saved its definition; then proceed to fill in several rows of
AP> data using just the "MyText" field alone. Each time you do this,
AP> the MyID field will auto-increment and a new number appears; and
AP> your text is saved as you move off of each row; but the "MyDate"
AP> field remains -->>EMPTY<<--, which is not the same as NULL. This
AP> is a common theme in Microsoft's smaller database products, where
AP> the "databases" function more like storage containers than actual
AP> database engines. Use this with Visual Basic and you have an
AP> environment where MS programmers are most likely to take the raw
AP> value of a field (typically an empty string, "") and pass it
AP> directly into the table that is mapped to the form's field.
In Access, the Empty constant and IsEmpty() function are pure VB/front-end
concepts. They can only be used in front-end stuff, i.e. modules, forms,
reports, and macros. You cannot mention them in SQL statements, especially
passed to Jet via ODBC.
OT1H, when using so-called "bound forms", the empty fields is automatically
converted to/from NULL. Within VB code, the Value property of any bound
control equals to NULL (unless it is defaulted). OTOH, for an unbound
control that knows nothing about database, the Value property is Empty
initially.
AP> To prevent PostgreSQL from choking on this, set "Server Side
AP> Prepare" to ON and select option 0x8 when using Hiroshi's
AP> experimental driver, and the empty date fields will be automagically
AP> translated to a sane value, NULL, instead of just " / / ".
Thanks to driver developers for making the option look encrypted, so
"conformant" ODBC clients need not bother about that :-).
AP> Hope this has answered your questions...
Yes, thanks.
--
Sincerely,
Dmitriy Ivanov
Common Lisp ODBC interface - lisp.ystok.ru/ysql.html
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2006-10-13 06:41 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2006-10-06 23:17 Re: Representing Empty DATE values as NULL Avery Payne <apayne@pcfruit.com>
2006-10-07 05:23 ` Dmitriy Ivanov <divanov-NOSP@M-aha.ru>
2006-10-12 17:22 Re: Representing Empty DATE values as NULL Avery Payne <apayne@pcfruit.com>
2006-10-13 06:41 ` Dmitriy Ivanov <divanov-NOSP@M-aha.ru>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox