Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Weird and The Wonderful
  4. In the midst of reviewing some code my client got back from and outsourced refactoring effort...

In the midst of reviewing some code my client got back from and outsourced refactoring effort...

Scheduled Pinned Locked Moved The Weird and The Wonderful
databasetestingbeta-testinghelpquestion
4 Posts 4 Posters 3 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Austin Harris
    wrote on last edited by
    #1

    We ran into the following nice bit of code.

    public static bool UniqueAssetNo(int assetId, string assetNo)
    {
    //--string sql = @"Select Count(*) From Asset " +
    //-- @"Where ({0} = 0 Or AssetId <> {0}) " +
    //-- @"And (LoanNum Not Like '%[A-Z]%') " +
    //-- @"And (Cast('{1}' As bigint) = Cast(LoanNum As bigint))";
    //We ran into an error during testing. I think it has to do with the indexes not being created properly. In either case, this one works.
    try
    {
    string sql = @"Select Count(*) " +
    @"From (Select AssetId, LoanNum " +
    @" From Asset (NOLOCK) " +
    @" Where ({0} = 0 Or AssetId <> {0}) " +
    @" And (LoanNum Not Like '%[A-Z]%') And LTrim(RTrim(LoanNum)) <> '') qry " +
    @"Where Cast('{1}' As bigint) = Case When qry.LoanNum = '' Then 0 else Cast(qry.LoanNum as bigint) end";
    ...
    ...

    What do you think? :P

    P A 2 Replies Last reply
    0
    • A Austin Harris

      We ran into the following nice bit of code.

      public static bool UniqueAssetNo(int assetId, string assetNo)
      {
      //--string sql = @"Select Count(*) From Asset " +
      //-- @"Where ({0} = 0 Or AssetId <> {0}) " +
      //-- @"And (LoanNum Not Like '%[A-Z]%') " +
      //-- @"And (Cast('{1}' As bigint) = Cast(LoanNum As bigint))";
      //We ran into an error during testing. I think it has to do with the indexes not being created properly. In either case, this one works.
      try
      {
      string sql = @"Select Count(*) " +
      @"From (Select AssetId, LoanNum " +
      @" From Asset (NOLOCK) " +
      @" Where ({0} = 0 Or AssetId <> {0}) " +
      @" And (LoanNum Not Like '%[A-Z]%') And LTrim(RTrim(LoanNum)) <> '') qry " +
      @"Where Cast('{1}' As bigint) = Case When qry.LoanNum = '' Then 0 else Cast(qry.LoanNum as bigint) end";
      ...
      ...

      What do you think? :P

      P Offline
      P Offline
      PIEBALDconsult
      wrote on last edited by
      #2

      Glad I haven't eaten yet. X|

      1 Reply Last reply
      0
      • A Austin Harris

        We ran into the following nice bit of code.

        public static bool UniqueAssetNo(int assetId, string assetNo)
        {
        //--string sql = @"Select Count(*) From Asset " +
        //-- @"Where ({0} = 0 Or AssetId <> {0}) " +
        //-- @"And (LoanNum Not Like '%[A-Z]%') " +
        //-- @"And (Cast('{1}' As bigint) = Cast(LoanNum As bigint))";
        //We ran into an error during testing. I think it has to do with the indexes not being created properly. In either case, this one works.
        try
        {
        string sql = @"Select Count(*) " +
        @"From (Select AssetId, LoanNum " +
        @" From Asset (NOLOCK) " +
        @" Where ({0} = 0 Or AssetId <> {0}) " +
        @" And (LoanNum Not Like '%[A-Z]%') And LTrim(RTrim(LoanNum)) <> '') qry " +
        @"Where Cast('{1}' As bigint) = Case When qry.LoanNum = '' Then 0 else Cast(qry.LoanNum as bigint) end";
        ...
        ...

        What do you think? :P

        A Offline
        A Offline
        Andrew Rissing
        wrote on last edited by
        #3

        :omg: Aside from the obvious, you might also want to do some reviews for SQL injection vulnerabilities.

        P 1 Reply Last reply
        0
        • A Andrew Rissing

          :omg: Aside from the obvious, you might also want to do some reviews for SQL injection vulnerabilities.

          P Offline
          P Offline
          Paul Conrad
          wrote on last edited by
          #4

          :omg: pretty much sums it up, here too.

          Andrew Rissing wrote:

          do some reviews for SQL injection vulnerabilities

          Yes, they should. They ought to do a search on this site for Colin Mackay's article on such topic :)

          "The clue train passed his station without stopping." - John Simmons / outlaw programmer "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon "Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups