Subject | Re: [firebird-support] Noobie Null Date and Time woes |
---|---|
Author | David Johnson |
Post date | 2005-12-14T04:15:38Z |
Use a prepared statement. Dynamically constructing SQL is a serious
security loophole and a performance dog.
I am not certain of the syntax for your language, but here it is in
Java. It is similar in Delphi.
// in application initialization
stmt = connection.prepare ("INSERT INTO MYTABLE (MYDATE) VALUES (?)");
/* snip ... */
// in use ...
stmt.clear();
if ((myDate == null) || (myDate.equals ("NULL")))
{
stmt.setNull (1); /* setting null is different from not setting a
param */
}
else
{
stmt.setString (1, myDate); /* JDBC handles the String to Date
conversion */
}
result = stmt.executeQuery ();
security loophole and a performance dog.
I am not certain of the syntax for your language, but here it is in
Java. It is similar in Delphi.
// in application initialization
stmt = connection.prepare ("INSERT INTO MYTABLE (MYDATE) VALUES (?)");
/* snip ... */
// in use ...
stmt.clear();
if ((myDate == null) || (myDate.equals ("NULL")))
{
stmt.setNull (1); /* setting null is different from not setting a
param */
}
else
{
stmt.setString (1, myDate); /* JDBC handles the String to Date
conversion */
}
result = stmt.executeQuery ();
On Tue, 2005-12-13 at 18:59 -0800, Lin XG wrote:
> Hi Jason;
>
> myDate is a string.
>
> Thanks for the tip, but it doesn't work.
>
> If I use 12/13/05 10:00 the query will look like
>
> INSERT INTO MYTABLE (MYDATE) VALUES ('12/13/05
> 10:00');
>
> If I use "NULL" the query comes out looking like
>
> INSERT INTO MYTABLE (MYDATE) VALUES ('NULL');
>
> which generates a string conversion error.
>
> Still scratching my head.
>
> Lin
>
> --- Jason Dodson <jasond@...> wrote:
>
> > Is MyDate a Variant?
> >
> > Anyway, set MyDate = "NULL", quotes and all. The SQL
> > will work fine as long as
> > MyDate holds the STRING "NULL", not a NULL value.
> >
> > Jason
> >
> > sbdlinxg wrote:
> > > I've just discovered Firebird and I'm using VB to
> > experiment with it.
> > > This code works fine
> > >
> > > myDate = Format(Now(), "mm/dd/yy hh:mm")
> > > sql = "INSERT INTO MYTABLE (MYDATE) VALUES ('" &
> > myDate & "');"
> > >
> > > as long as myDate is a date. If I set myDate =
> > NULL the statement
> > > causes an error and I know why the error is
> > occurring.
> > >
> > > What I need to know is how to write this statement
> > to take into
> > > account the possibility that myDate is NULL.
> > >
> > > Thanks
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> >
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> > >
> > > Visit http://firebird.sourceforge.net and click
> > the Resources item
> > > on the main (top) menu. Try Knowledgebase and FAQ
> > links !
> > >
> > > Also search the knowledgebases at
> > http://www.ibphoenix.com
> > >
> > >
> >
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> > >
> > > Yahoo! Groups Links
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> >
> > --
> >
> > The information transmitted herewith is sensitive
> > information intended only for use to the individual
> > or entity to which it is addressed. If the reader
> > of this message is not the intended recipient, you
> > are hereby notified that any review, retransmission,
> > dissemination, distribution, copying or other use
> > of, or taking of any action in reliance upon, this
> > information is strictly prohibited. If you have
> > received this communication in error, please contact
> > the sender and delete the material from your
> > computer.
> >
>
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam? Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
>
>
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>
> Visit http://firebird.sourceforge.net and click the Resources item
> on the main (top) menu. Try Knowledgebase and FAQ links !
>
> Also search the knowledgebases at http://www.ibphoenix.com
>
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>
>
>
>
> SPONSORED LINKS
> Technical support
> Computer technical
> support
> Compaq computer
> technical support
> Compaq technical
> support
> Hewlett packard
> technical support
> Microsoft technical
> support
>
>
> ______________________________________________________________________
> YAHOO! GROUPS LINKS
>
> 1. Visit your group "firebird-support" on the web.
>
> 2. To unsubscribe from this group, send an email to:
> firebird-support-unsubscribe@yahoogroups.com
>
> 3. Your use of Yahoo! Groups is subject to the Yahoo! Terms of
> Service.
>
>
> ______________________________________________________________________
>