Results 1 to 4 of 4

Thread: Problems with hard coded sql statements

  1. #1

    Thread Starter
    Hyperactive Member Krokonoster's Avatar
    Join Date
    Jan 2010
    Location
    Cape Town
    Posts
    448

    Problems with hard coded sql statements

    Just for the record, I would never hard-code sql statements in my code. All my data access goes via MS Enterprise Library to stored procedures.

    However, had to take over this one guy's code (several projects) and all his code uses hard coded sql statements.
    Would have loved to change it all, but there's no time for that, and have to use the programs as is, and fix issues as they arise (while going on with my own projects!!!)

    Just now I found that he does not escape single colon's in his sql strings, and therefore (in this case) insert statement will fail if a single colon in it.

    What would be the quickest way to address this problem. Perhaps create a method that escape sql strings and change his code from
    string sql = "" to
    string sql = MyCleaningFunction("Insert into aaa blah blah blah");
    ?


  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Problems with hard coded sql statements

    you mean tick marks ' ... not colons, which is :

    I don't know that creating a cleaning function would be any easier and faster than converting the queries into parameterized ones, I'm not suggesting using sprocs... keep the SQL inline, but use parameters instead. You're going to have to modify all those lines anyways... might as well do it proper and right.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    Hyperactive Member Krokonoster's Avatar
    Join Date
    Jan 2010
    Location
    Cape Town
    Posts
    448

    Re: Problems with hard coded sql statements

    hell what was I thinking. meant single quotes...or ticks (first time I hear it called that).

    dude, it's really a LOT of code (though I agree with you).

    either case, will see. thought there might be a .net function for this (other than string.replace....)


  4. #4
    PowerPoster Evil_Giraffe's Avatar
    Join Date
    Aug 2002
    Location
    Suffolk, UK
    Posts
    2,555

    Re: Problems with hard coded sql statements

    I'd second a vote for converting the queries to parameterised queries.

    There's nothing inherently wrong with hard coded SQL (modulo parameterised queries and other safety techniques of course) if the scale of the application is small. Sometimes a big framework will be over-engineering.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width