Why do this?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Steve Holden

    #16
    Re: Why do this?

    Fredrik Lundh wrote:
    Lawrence D'Oliveiro wrote:
    >
    >
    >>Secondly, it's less convenient for cases where a dynamic query is being
    >>built. I previously gave the SQLStringList example. If that's not enough,
    >>here's another (simple) one:
    >>
    >>Conditions = []
    >>if Name != None :
    > Conditions.appe nd("name = %s" % SQLString(Name) )
    >>#end if
    >>if Address != None :
    > Conditions.appe nd("address = %s" % SQLString(Addre ss))
    >>#end if
    >>if PhoneNr != None :
    > Conditions.appe nd("phone_nr = %s" % SQLString(Phone Nr))
    >>#end if
    >>Query = "select * from table"
    >>if len(Conditions) != 0 :
    > Query += " where " + " and ".join(Conditio ns)
    >>#end if
    >
    >
    now that's some remarkably ugly Python code. it's well-known that people can
    write Fortran in all languages, but writing Visual Basic in Python? (shudder)
    [...]
    this is Python, after all, and as we all know, "the joy of coding Python should be
    in seeing short, concise, readable classes that express a lot of action in a small
    amount of clear code - not in reams of trivial code that bores the reader to death".
    >
    I especially liked the #end if comments after the single guarded lines.

    regards
    Steve
    --
    Steve Holden +44 150 684 7255 +1 800 494 3119
    Holden Web LLC/Ltd http://www.holdenweb.com
    Skype: holdenweb http://holdenweb.blogspot.com
    Recent Ramblings http://del.icio.us/steve.holden

    Comment

    • Duncan Booth

      #17
      Re: Why do this?

      Lawrence D'Oliveiro <ldo@geek-central.gen.new _zealandwrote:
      >>I use the above when I can, when I can't I fall back on
      >>><http://groups.google.c o.nz/groups?selm=efc 5b3$can$1@lust. ihug.co.nz>,
      >>><http://groups.google.c o.nz/groups?selm=efh n5v$fia$2@lust. ihug.co.nz>.
      >>
      >Yes, so you said, but you never came up with a convincing use case
      >where that function was better than using the parameterised queries.
      >
      First of all, the parametrization doesn't handle wildcards, as we
      discussed previously.
      No, your separate function for escaping wildcards is fine, and works in
      conjunction with parameterized queries. It's the SQLString function you
      never managed to justify.
      Secondly, it's less convenient for cases where a dynamic query is being
      built. I previously gave the SQLStringList example. If that's not enough,
      here's another (simple) one:
      See Frederik's excellent response on this point.

      Comment

      Working...