Results 1 to 8 of 8

Thread: No one else knows...

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2000
    Posts
    142
    I've posted the following in other forums, but no one seems to know....

    I have an SQL database, which has a table that has constraints on the data that can go in. (ie constrain is that numbers must be between 4000-4999).

    what i would like to do, is find out the contraint programatically from ASP. can this be done?

    the reason i want to do this, is so that if the user enters bad data, i don't want a bad ADO error thrown...

    and i don't want to do client side validation, because the constraint may change....

    please let me know if/how it can be done!

    dvst8


    Secret to long life:
    Keep breathing as long as possible.

  2. #2
    Lively Member
    Join Date
    Jul 2000
    Location
    Stockholm, Sweden
    Posts
    83

    Lightbulb

    I am sure you can do it but they way to succed my differ from DBengine to DBengine.

    Dianne Siebold wrote VB Programmer's Journal (No.7) about accessing SQL Server Metadata. For others you might use ODBC to get the Metadata.

    When you recive the Metadata just parse it and there you have it.

    Not an easy task but usefull.

    Best luck, AKA
    Yesterday, all my troubles seemed so far away...
    Help, I need somebody, Help...
    Now MCSD and still locking for intresting job in the south parts of Stockholm, Sweden.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    May 2000
    Posts
    142
    VB Programmer's Journal is a magazine?

    I don't know anything about accessing metadata...I've searched the web and come up empty-handed. Do you know where I could find such info?

    Thanks.

    dvst8
    Secret to long life:
    Keep breathing as long as possible.

  4. #4
    Guru Clunietp's Avatar
    Join Date
    Oct 1999
    Location
    USA
    Posts
    1,844
    Is this a trigger that you have? I'm assuming by "SQL Database" you mean SQL Server

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    May 2000
    Posts
    142
    yes SQL server.

    it's not a trigger, it's a constraint.
    Secret to long life:
    Keep breathing as long as possible.

  6. #6
    Lively Member
    Join Date
    Jul 2000
    Location
    Stockholm, Sweden
    Posts
    83

    Thumbs up

    I have tested a littlie and here is my result, but be aware that I have not gone to the bottom of the problem and that this is a start for you.

    I made a CHECK constraint named X on a table with the column Id that I want to check that it is bigger than 0.

    I made this SQL statement in the query analyzer

    select sc.text from syscomments sc,sysobjects so where so.id=sc.id and so.name="X"

    and got this result

    text
    ------------------------------------------------------
    ([id] > 0)

    I think that you can go on from here. I will leave for a three weeks vacation today so dont sitt up wating for more help from me AKA

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    May 2000
    Posts
    142

    Thumbs up

    thank you AKA.

    it was very frustrating not being able to find anything in my reference resources about this.

    you have given me a starting point, from which I should be able to solve my problem.

    i shall post the entire solution when i get it going.

    dvst8
    Secret to long life:
    Keep breathing as long as possible.

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    May 2000
    Posts
    142

    here is my solution

    for any who care, here is how i solved my problem.
    many thanks to AKA for directing me to the proper tables where to find the data.

    Code:
    <%
    
    function removespace(myString)
    	mx = Len(myString)
    	for i = 1 to mx
    		cur = Mid(myString, i, 1)
    		if cur <> " " then
    			good = good & cur
    		end if
    	next
    removespace = good
    
    end function
    
    function num(myString, operator)
    	mx = Len(myString)
    	
    	for i = 1 to mx-1
    		cur = Mid(myString,i,2)
    		if cur = operator then
    			idx = i + 2
    			nextChar = Mid(myString,idx,1)
    			result = ""
    			do while nextChar >= chr(48) and nextChar <= chr(57)
    				result = result & nextChar
    				idx = idx + 1
    				nextChar = Mid(myString,idx,1)
    			loop
    			num = result
    			exit function
    		end if
    	next
    end function
    
    
    stmSQL = "SELECT syscomments.text as constr FROM syscomments INNER JOIN sysobjects ON syscomments.id = sysobjects.id WHERE sysobjects.name = 'CK_CodeID'"
    set oRS = Server.CreateObject("ADODB.recordset")
    oRS.open stmSQL,"DSN=labdata"
    
    oRS.MoveFirst
    constraint = removespace(oRS("constr"))
    Response.Write constraint & "<br>"
    Response.Write "The minimum number is "&num(constraint, ">=") & "<br>"
    Response.Write "The maximum number is "&num(constraint, "<=") & "<br>"
    
    
    %>

    dvst8
    Secret to long life:
    Keep breathing as long as possible.

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