and1_hotsauce
Registered User.
- Local time
- Yesterday, 20:13
- Joined
- Aug 29, 2011
- Messages
- 17
hi
I have a table with two fields like below. The sender sends an sms with an ID eg. AA and gets a reply from the server ($1). However, I'm having trouble trying to decode the sql statement below
ID................. VALUE
AA...................$1
BB...................$3.59
CC..................$2.12
DD..................$3
EE..................$21
select all rows from the stocks table where the ID = ??. This is where I'm confused. I am not sure why its being concanetated twice.
full code is below if further information is needed.
I have a table with two fields like below. The sender sends an sms with an ID eg. AA and gets a reply from the server ($1). However, I'm having trouble trying to decode the sql statement below
ID................. VALUE
AA...................$1
BB...................$3.59
CC..................$2.12
DD..................$3
EE..................$21
select all rows from the stocks table where the ID = ??. This is where I'm confused. I am not sure why its being concanetated twice.
Code:
strQuery = "SELECT * FROM Stocks WHERE ID = '" & strSymbol &"'"
full code is below if further information is needed.
Code:
' // ========================================================================
' // C:\Program Files (x86)\ActiveXperts\SMS Messaging Server\Projects\uni project\Triggers\uni project.vbs
' // ------------------------------------------------------------------------
' //
' //
' // ========================================================================
Option Explicit
CONST STR_DEBUGFILE = "C:\Program Files (x86)\ActiveXperts\SMS Messaging Server\Sys\Tmp\uni project.txt"
CONST STR_DATABASEFILE = "C:\Program Files (x86)\ActiveXperts\SMS Messaging Server\Projects\uni project\Database\Stock.mdb"
' Declaration of global objects
Dim g_objMessageDB, g_objDebugger, g_objConstants
' Creation of global objects
Set g_objConstants = CreateObject( "AxSmsServer.Constants" )
Set g_objMessageDB = CreateObject( "AxSmsServer.MessageDB" )
Set g_objDebugger = CreateObject( "ActiveXperts.VbDebugger" )
' Set Debug file - for troubleshooting purposes
g_objDebugger.DebugFile = STR_DEBUGFILE
g_objDebugger.Enabled = False
' // ========================================================================
' // Function: ProcessMessage
' // ------------------------------------------------------------------------
' // ProcessMessage trigger function to process incoming messages
' // ========================================================================
Function ProcessMessage( numMessageID )
Dim objMessageIn, objMessageOut
g_objDebugger.WriteLine ">> ProcessMessage"
' Open the Message Database
g_objMessageDB.Open
If( g_objMessageDB.LastError <> 0 ) Then
g_objDebugger.WriteLine "<< ProcessMessage, unable to open database"
Exit Function
End If
' Retrieve the message that has just been received. If it fails then exit script
Set objMessageIn = g_objMessageDB.FindFirstMessage ( "ID = " & numMessageID )
If g_objMessageDB.LastError <> 0 Then
g_objMessageDB.Close
g_objDebugger.WriteLine "<< ProcessMessage, FindFirstMessage failed, error: [" & g_objMessageDB.LastError & "]"
Exit Function
End If
' Change Status to from Pending to Success. If you don't do it, the message will be processed by subsequent triggers (if defined) because message is still pending
objMessageIn.Status = g_objConstants.MESSAGESTATUS_SUCCESS
g_objMessageDB.Save objMessageIn
g_objDebugger.WriteLine "Incoming message saved, result: [" & g_objMessageDB.LastError & "]"
ProcessQuery ( objMessageIn )
' Close the Message Database
g_objMessageDB.Close
g_objDebugger.WriteLine "<< ProcessMessage"
End Function
' // ========================================================================
' // ProcessQuery
' // ------------------------------------------------------------------------
' // Parse the SMS and send a response back
' // ========================================================================
Function ProcessQuery ( objMessageIn )
Dim objMessageOut, curCurrentPrice, strReplymessage
g_objDebugger.WriteLine ">> ProcessQuery"
g_objDebugger.WriteLine "Selected Stock: " & objMessageIn.Body
If( QueryStock ( objMessageIn.Body, curCurrentPrice ) = False ) Then
strReplymessage = "Stock symbol not found. Please send a valid stock to query the current price, for instance: AXP"
Else
strReplymessage = "Current Price for " & objMessageIn.Body & ": $" & curCurrentPrice
End If
' Create the reply message
Set objMessageOut = g_objMessageDB.Create
If( g_objMessageDB.LastError = 0 ) Then
objMessageOut.Direction = g_objConstants.MESSAGEDIRECTION_OUT
objMessageOut.Type = g_objConstants.MESSAGETYPE_SMS
objMessageOut.Status = g_objConstants.MESSAGESTATUS_PENDING
objMessageOut.Recipient = objMessageIn.Sender
objMessageOut.ChannelID = objMessageIn.ChannelID
objMessageOut.Body = strReplymessage
g_objMessageDB.Save objMessageOut
End If
g_objDebugger.WriteLine "<< ProcessQuery"
End Function
' // ========================================================================
' // Query stock
' // ------------------------------------------------------------------------
' // Lookup the current price of the selected stock ( use ticker symbol )
' // ========================================================================
Function QueryStock( strSymbol, BYREF curCurrentPrice )
Dim objConn, RS
Dim strQuery
QueryStock = False
g_objDebugger.WriteLine ">> QueryStock"
Set objConn = CreateObject("ADODB.Connection")
objConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & STR_DATABASEFILE & ";"
strQuery = "SELECT * FROM Stocks WHERE ID = '" & strSymbol &"'"
Set RS = objConn.Execute ( strQuery )
If( RS.EOF = False ) Then
curCurrentPrice = RS( "Value" )
QueryStock = True
Else
QueryStock = False
End If
' Close database
objConn.Close
Set objConn = Nothing
g_objDebugger.WriteLine "<< QueryStock"
End Function
Last edited: