Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Convert DateTime to a string to send to SQL serv
Message
 
 
To
05/09/2010 16:50:20
John Ryan
Captain-Cooker Appreciation Society
Taumata Whakatangi ..., New Zealand
General information
Forum:
Visual FoxPro
Category:
Other
Environment versions
Visual FoxPro:
VFP 9 SP1
Miscellaneous
Thread ID:
01480183
Message ID:
01480223
Views:
50
>Dmitry, rather than concatenating values, use parameterized SQL.
>
tDatetime=datetime()
>lcSQL="update MyTable Set DateTimeColumn = ?tdatetime where Pk = ?nPk"
>
>
>Apart from taking care of the conversions for you, in SQL Server 7 and later a parameterized query like this will be cached at the server, giving significant improvement benefits.
>
>The other advantage is that parameters prevent SQL Injection. The concatenated examples in this thread are all wide open to injection if a hacker can sneak a quote character into the parameter followed by their own SQL command that could be a SELECT * to steal your customer list or a DROP if they are malicious. You can write code to watch for quotes and other injection attempts, but using parameters makes it a complete non-event.
>
>FWIW for those who have not encountered SQL Injection, here's a simple example of concatenated SQL:
>
"SELECT * FROM members WHERE username = "'+lcusername+"'"
>If the hacker can enter their username as bob'; DROP table members; -- then the SQL becomes
>
SELECT * FROM members WHERE username='bob'; DROP table members; --'
>and you get the idea. yes you can write code to prevent use of quote characters etc but this cannot occur at all if you use parameters.

John, thank you for the warning of SQL Injection and for illustrating the case. In this particular case, for which I asked the question, there is no danger of injection since the SQL command is created in code by the application and not taking user entry into account.

But, having said it, I am not sure, in general how I can use the parametrized command with Cursor Adapter approach. For example, say I have a user entry form where Cursor Adapter is created, fills cursor with data from the back end (SQL Server). Then, when user makes changes, the program simply executes TableUpdate() which updates the table in the SQL Server. Could someone enter the "malicious" entry (similar to your example) in one of the fields and cause the table dropped or something like this on TableUpdate()?
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform