Results 1 to 19 of 19
  1. #1
    009
    009 is offline Member
    Join Date
    May 2014
    Posts
    22
    Rep Power
    0

    Default how to avoid hard coded values

    hi i have code which query value from database,the use case is the user can enter value as 1,01,11 in database but when the user enter value in xml file he can only enter 11,01,12 in database there is two columns lets say column test1=1 and test2=2 combination of this is 12,which is the value the use will enter in xml,but sometime the use can enter test1=04 than column test2=00 how can i approch this

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,958
    Rep Power
    8

    Default Re: how to avoid hard coded values

    I'm not really sure what you're asking. Can you provide some example input and the desired output?
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    009
    009 is offline Member
    Join Date
    May 2014
    Posts
    22
    Rep Power
    0

    Default Re: how to avoid hard coded values

    hi i got table called card with column crdind,crdpos1,cardpos2 as primary key
    the use can enter value as

    crdind=1
    crdpos1=5
    crdpos2=3
    inactivedate=2013-05-24
    activedate=null

    another row

    crdind=1
    crdpos1=5
    crdpos2=5
    inactivedate=2013-05-24
    activedate=null

    another row
    crdind=6
    crdpos1=02
    crdpos2=00
    inactivedate=2013-05-24
    activedate=null

    the rule say if you enter one number in crdpos1 eg 2 than you must enter value in crdpos2 it can be any number 1-9 but if you enter 00-09 in crdpos1 than crdpos2 is 00

    the challenge i have
    is to query this value after they been enter
    i have xml file which got field crdpos the use enter 15 which is the combination of colunm crdpos1=1 and crdpos2=5
    how can i spilt the value crdpos and got and able to query in database in two separete column

  4. #4
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    835
    Rep Power
    6

    Default Re: how to avoid hard coded values

    still not clear about the requirement...please explain in detail to help u.
    Ramya:cool:

  5. #5
    009
    009 is offline Member
    Join Date
    May 2014
    Posts
    22
    Rep Power
    0

    Default Re: how to avoid hard coded values

    i what a query which would return values based on what the use enter in parameter



    select inactivedate from card

    where crdind = ' 1'

    and crdpos1=:p

    and crdpos2=:p



    the problem is the use can only enter one value 15 which is splilt in two crdpos1=1 and crdpos2=5



    now how can i query this record



    crdind=1

    crdpos1=1

    crdpos2=5

    inactivedate=2013-05-24

    activedate=null



    but the use only enter 15



    i already split the values,the problem is when the user enter crdpos1=06 and than crdpos2=00

    String s_field1 = s_pos.substring(0, 1);
    String s_field2 = s_pos.substring(1);

  6. #6
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    835
    Rep Power
    6

    Default Re: how to avoid hard coded values

    instead of accepting as a number value from user ,try to ask him to key in string value inorder to get rid of 0 trim.got me?
    Ramya:cool:

  7. #7
    009
    009 is offline Member
    Join Date
    May 2014
    Posts
    22
    Rep Power
    0

    Default Re: how to avoid hard coded values

    the user is entering value as string,which trim,i don't undestand

  8. #8
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,006
    Rep Power
    20

    Default Re: how to avoid hard coded values

    "the problem is when the user enter crdpos1=06 and than crdpos2=00"

    OK, so what should happen if the user enters:
    crdpos1 = 06
    crdpos2 = 00
    ?

    What should be the query, if you had to write it in a SQL editor?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  9. #9
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,997
    Rep Power
    5

    Default Re: how to avoid hard coded values

    Not surprisingly, this has been crossposted:

    https://community.oracle.com/thread/3573767
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  10. #10
    009
    009 is offline Member
    Join Date
    May 2014
    Posts
    22
    Rep Power
    0

    Default Re: how to avoid hard coded values

    hi this is the sql i have to put now in dynamic after the value have been spilt
    String inp1 = s_pos.substring(0, 1);
    String inp2 = s_pos.substring(1);
    SELECT *

    FROM card

    WHERE crdpos1 = CASE WHEN :inp1 = '0' THEN :inp1||:inp2 ELSE :inp1 END

    AND crdpos2 = CASE WHEN :inp1 = '0' THEN '00' ELSE :inp2 END;
    this sql is working in sql editor
    Last edited by 009; 06-18-2014 at 02:52 PM.

  11. #11
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    835
    Rep Power
    6

    Default Re: how to avoid hard coded values

    each one have different assumptions.So,no need to explain... what input u give what output u want...

    just give different combinations.
    Ramya:cool:

  12. #12
    009
    009 is offline Member
    Join Date
    May 2014
    Posts
    22
    Rep Power
    0

    Default Re: how to avoid hard coded values

    lets say the value in database is

    crdpos1=01

    crdpos2=0



    this one user enter 01



    sorry crdpos2 must be 0 not 00 as i say before



    and another value in database is

    crdpos1=1

    crdpos2=6



    and use enter 16



    another value in database



    crdpos1=1

    crdpos2=0



    the user enter 10 to query the record

  13. #13
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,006
    Rep Power
    20

    Default Re: how to avoid hard coded values

    So.
    Split the String into the two characters.
    If the first character is zero then crdpos1 is the original String and crdpos2 is 0.
    Otherwise crdpos1 is the first character and crdpos2 is the second.

    Stick those in your prepared statement.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  14. #14
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,519
    Blog Entries
    7
    Rep Power
    20

    Default Re: how to avoid hard coded values

    Am I missing something? Are these the rites of a secret kaballah club? I don't understand anything from this thread ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  15. #15
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,997
    Rep Power
    5

    Default Re: how to avoid hard coded values

    You're not alone. Even when I read Tolls' solution, I then go back to the last problem "description" and my head spins anyway.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  16. #16
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,519
    Blog Entries
    7
    Rep Power
    20

    Default Re: how to avoid hard coded values

    Quote Originally Posted by gimbal2 View Post
    You're not alone. Even when I read Tolls' solution, I then go back to the last problem "description" and my head spins anyway.
    To me this thread is about juggling with numbers (that are not supposed to be single numbers) and some database blahblah and some XML; talk about separation of concerns ... or maybe this thread is about the largest prime number ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  17. #17
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,006
    Rep Power
    20

    Default Re: how to avoid hard coded values

    I have no idea where the xml comes into it.
    I just took the last description and ran with it.

    I really wouldn't like to bet it's correct...:)
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  18. #18
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,519
    Blog Entries
    7
    Rep Power
    20

    Default Re: how to avoid hard coded values

    Quote Originally Posted by Tolls View Post
    I have no idea where the xml comes into it.
    I just took the last description and ran with it.

    I really wouldn't like to bet it's correct...:)
    Read the OP again: it has buzzwords such as 'database' and 'xml' in it ;-)

    kind regards,

    Jos

    ps. I still don't understand anything of this thread ...
    cenosillicaphobia: the fear for an empty beer glass

  19. #19
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,997
    Rep Power
    5

    Default Re: how to avoid hard coded values

    Yeah, language barriers.

    I think it is something like this:

    - user inputs one number consisting of two digits

    - IF that number starts with a 0 (06)
    -- crdpos1 = number
    -- crdpos2 = 00

    - ELSE
    -- application splits the one number into two numbers of each one digit
    -- crdpos1 = digit1
    -- crdpos2 = digit2

    - query database selecting on crdpos1 and crdpos2
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

Similar Threads

  1. AVOID RE-Printing of Duplicate Values in an Array!
    By NoviceJavaNoob in forum New To Java
    Replies: 5
    Last Post: 03-28-2014, 11:57 AM
  2. Replies: 7
    Last Post: 11-01-2010, 02:04 PM
  3. offline inspection is not reporting "Hard coded String" errors
    By g_madhu_krishna in forum IntelliJ IDEA
    Replies: 0
    Last Post: 09-17-2010, 08:02 AM
  4. Coded Life Lesson :)
    By MuslimCoder in forum Forum Lobby
    Replies: 7
    Last Post: 07-29-2009, 08:16 PM
  5. Coded Message... Help Please
    By maxpower1000sa in forum New To Java
    Replies: 2
    Last Post: 05-03-2009, 08:27 PM

Posting Permissions

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