[REBOL] Re: [COMMAND] Database null values
From: edanaii:cox at: 26-Jan-2003 8:11
Davide Gessi wrote:
>if I want to append new records to a table I can insert into a command port
>insert cmd-port [
> "INSERT INTO tab (f1,f2,f3) VALUES (?,?,?)"
> v1 v2 v3
>but how can I handle null values ?
>if f1 is a text field and v1 is none, then f1 will set to [to-string none]
>Could be the following a good approach ?
>to-sql-value: func [
> v [any-type!]
> either none? v [
> return "null"
> either string? v [
> return rejoin ["'" to-string v "'"]
> either date? v [
> return rejoin ["#" to-string v "#"]
> return to-string v
>sql-str: rejoin ["INSER INTO tab (f1,f2,f3) VALUES (" to-sql-value v1 ","
>to-sql-value v2 "," to-sql-value v3 ")"]
>insert cmd-port sql-str
>Any hint ?
Are you inserting into an Oracle database? If so, just use the SQL
keyword NULL. It should be true of any database that uses SQL.
If you are replacing "NONE" with "NULL" in your example, above, that
should work fine.
Sincerely, | Control is an illusion, you infantile egomaniac!
Ed Dana | Nobody knows what's gonna happen next: not on a
Software Developer | freeway, not in an airplane, not inside our own
1Ghz Athlon Amiga | bodies and certainly not on a racetrack with 40
| other infantile egomaniacs!
| -- Nicole Kidman, Days of Thunder