home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / sys / next / programm / 6092 < prev    next >
Encoding:
Text File  |  1992-09-10  |  3.1 KB  |  96 lines

  1. Newsgroups: comp.sys.next.programmer
  2. Path: sparky!uunet!infoman!jonb
  3. From: jonb@infoman (Jon C. Buffington)
  4. Subject: Re: DBKit- Trying to get a SQL function in a query
  5. Message-ID: <1992Sep10.131204.5022@infoman.com>
  6. Sender: jonb@infoman.com
  7. Reply-To: jonb@infoman.com
  8. Organization: Information Management Inc.
  9. References: <1992Sep9.194037.14018@bmw.mayo.edu>
  10. Date: Thu, 10 Sep 1992 13:12:04 GMT
  11. Lines: 83
  12.  
  13. In article <1992Sep9.194037.14018@bmw.mayo.edu> roder@mayo.edu (Mark N.  
  14. Roder) writes:
  15. >     I am trying to find a easy answer to the following problem.  I am  
  16. > doing a phone-book type application and want to use the SQL function  
  17. > soundex to do fuzzy type of searchs on last name.
  18. >     I (will) have a trigger to create a soundex value in the table  
  19. > whenever a insert/update is done.  We will call that field sl, with the  
  20. > name field being name.  The type of query I want to do is like this:
  21. >     SELECT name FROM entries
  22. >     WHERE sl LIKE SOUNDEX('looking_for_this_name')
  23. > How can I do this with DBKit?.  
  24. >     The way I look at it, there is 2 different ways to approach this.
  25. >     1) try to get a value back from a SQL function.  I can then use  
  26. > that in the building of the qualifier.  In looking at the docs, the  
  27. > evaluateString: method would do the trick, but I don't know how to get  
  28. the  
  29. > value back from that.  I can do the following from withn isql:
  30. > > 1> SELECT SOUNDEX('Anderson')
  31. > > 2> go
  32. > >        
  33. > >  ----- 
  34. > >  A536  
  35. > > 
  36. > > (1 row affected)
  37. > > 1> 
  38. >     Now, If I send it that string using evaluateString, how do I get  
  39. > the value back?   This would also be nice in finding things like MAX,  
  40. MIN,  
  41. > AVG,etc
  42.  
  43. You must tell DBKit about the properties you expect back even though you  
  44. are bypassing the sql composition component of DBKit. DBkit needs to know  
  45. where to copy the results into the client program. Here is a containerless  
  46. binder I use to assign sequence numbers from an oracle server to new rows  
  47. in a recordlist:
  48.  
  49.     aBinder = [[DBBinder allocFromZone:[self zone]] init];
  50.     [aBinder setFlushEnabled:NO];
  51.     ...
  52.     const char *currStatement = "SELECT PURCHASE_GEN.NEXTVAL FROM  
  53. USER_TABLES";
  54.     
  55.     seqNoProp = [[fetchGroup entity] propertyNamed:"IDNO"];
  56.     
  57.         // -- show binder were to store returned values
  58.         //
  59.     nextValProp = [[DBExpression allocFromZone:[self zone]]
  60.         initForEntity:[fetchGroup entity]
  61.         fromDescription:"NEXTVAL"];
  62.     [aBinder addProperty:nextValProp];
  63.     [aBinder setDatabase:[[fetchGroup module] database]];    
  64.     [aBinder setRecordPrototype:[[_Seqno allocFromZone:[aBinder  
  65. scratchZone]] init]];
  66.     [aBinder associateRecordIvar:"seqno" withProperty:nextValProp];
  67.     
  68.         // -- use containerless binder
  69.         //
  70.     if ( [aBinder evaluateString:currStatement] ) {
  71.         [aBinder fetch];
  72.     }
  73.  
  74.         //    -- set value in recordlist
  75.         //
  76.     aValue = [[DBValue allocFromZone:[aBinder scratchZone]] init];
  77.     [aValue setIntValue:[[aBinder recordPrototype] seqno]];
  78.     [[fetchGroup recordList] setValue:aValue
  79.         forProperty:seqNoProp at:index];
  80.  
  81. > --
  82. > Mark Roder
  83. > NeXT Consultant, Mayo Foundation
  84. > NeXT Mail:     roder@mayo.edu
  85. > phone:        (507) 284-5306
  86. -- 
  87. Jon Buffington <internet: jonb@infoman.com uucp: uunet!infoman!jonb>
  88. NeXT VAD    Atlanta, GA            NeXTmail accepted
  89.