Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Convert DateTime to a string to send to SQL serv
Message
De
05/09/2010 16:50:20
John Ryan
Captain-Cooker Appreciation Society
Taumata Whakatangi ..., Nouvelle Zélande
 
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Versions des environnements
Visual FoxPro:
VFP 9 SP1
Divers
Thread ID:
01480183
Message ID:
01480217
Vues:
85
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.
"... They ne'er cared for us
yet: suffer us to famish, and their store-houses
crammed with grain; make edicts for usury, to
support usurers; repeal daily any wholesome act
established against the rich, and provide more
piercing statutes daily, to chain up and restrain
the poor. If the wars eat us not up, they will; and
there's all the love they bear us.
"
-- Shakespeare: Coriolanus, Act 1, scene 1
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform