Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 3 of 3 total
Thread How to insert a NULL value in a parameterized query?
Tue, Feb 2 2010 12:34 PMPermanent Link

Dave
This has me stumped. One or more of the values for my Insert statement may be NULL. But
how can I get DBISAM 4 to accept it? I thought I could in this example clear QueryId
parameter and that would store a NULL value for QueryId. But it gives me an error "quTMp:
Field 'QueryId' is of an unknown type".  So without modifying SQLStr for each set of
parameters, how can I insert a NULL value when using parameters?

TIA
Dave

   SqlStr := 'Insert into Log '+
             '(User_Id, Elapsed_Time, Query_Id, Msg_Type, Oper, Msg_Short, Msg_Long) '+
              'Values (:UserId,:ElapsedTime,:QueryId,:MsgType,:Oper,:MsgShort,:MsgLong)';


     with quTmp do
       begin
         Sql.Text := SqlStr;
         ParamByName('UserId').AsInteger       := aUserId;
         ParamByName('ElapsedTime').AsFloat    := aElapsedTime;
         ParamByName('QueryId').Clear;
         //ParamByName('QueryId').AsInteger      := aQueryId;
         ParamByName('MsgType').AsString       := aMsgType;
         ParamByName('Oper').AsString          := aOper;
         ParamByName('MsgShort').AsString      := aMsgShort;
         ParamByName('MsgLong').AsString       := aMsgLong;
         Prepare;
       end;
     quTmp.ExecSql;
Tue, Feb 2 2010 12:45 PMPermanent Link

Dave
Ok, I found a solution to a prior post that Tim responded to.

I have to do:
         ParamByName('QueryId').DataType := ftInteger;
         ParamByName('QueryId').Clear;
         ParamByName('QueryId').Bound   := true;

which solves the problem. It would have been nice if this was in the manual.Smiley

Dave


Dave wrote:

This has me stumped. One or more of the values for my Insert statement may be NULL. But
how can I get DBISAM 4 to accept it? I thought I could in this example clear QueryId
parameter and that would store a NULL value for QueryId. But it gives me an error "quTMp:
Field 'QueryId' is of an unknown type".  So without modifying SQLStr for each set of
parameters, how can I insert a NULL value when using parameters?

TIA
Dave

   SqlStr := 'Insert into Log '+
             '(User_Id, Elapsed_Time, Query_Id, Msg_Type, Oper, Msg_Short, Msg_Long) '+
              'Values (:UserId,:ElapsedTime,:QueryId,:MsgType,:Oper,:MsgShort,:MsgLong)';


     with quTmp do
       begin
         Sql.Text := SqlStr;
         ParamByName('UserId').AsInteger       := aUserId;
         ParamByName('ElapsedTime').AsFloat    := aElapsedTime;
         ParamByName('QueryId').Clear;
         //ParamByName('QueryId').AsInteger      := aQueryId;
         ParamByName('MsgType').AsString       := aMsgType;
         ParamByName('Oper').AsString          := aOper;
         ParamByName('MsgShort').AsString      := aMsgShort;
         ParamByName('MsgLong').AsString       := aMsgLong;
         Prepare;
       end;
     quTmp.ExecSql;
Wed, Feb 3 2010 10:34 AMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Dave,

<< which solves the problem. It would have been nice if this was in the
manual.Smiley>>

I'll make a note to add this for the next DBISAM build.

--
Tim Young
Elevate Software
www.elevatesoft.com

Image