home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.sys.next.programmer
- Path: sparky!uunet!infoman!jonb
- From: jonb@infoman (Jon C. Buffington)
- Subject: Re: DBKit- Trying to get a SQL function in a query
- Message-ID: <1992Sep10.131204.5022@infoman.com>
- Sender: jonb@infoman.com
- Reply-To: jonb@infoman.com
- Organization: Information Management Inc.
- References: <1992Sep9.194037.14018@bmw.mayo.edu>
- Date: Thu, 10 Sep 1992 13:12:04 GMT
- Lines: 83
-
- In article <1992Sep9.194037.14018@bmw.mayo.edu> roder@mayo.edu (Mark N.
- Roder) writes:
- >
- >
- > I am trying to find a easy answer to the following problem. I am
- > doing a phone-book type application and want to use the SQL function
- > soundex to do fuzzy type of searchs on last name.
- >
- > I (will) have a trigger to create a soundex value in the table
- > whenever a insert/update is done. We will call that field sl, with the
- > name field being name. The type of query I want to do is like this:
- > SELECT name FROM entries
- > WHERE sl LIKE SOUNDEX('looking_for_this_name')
- >
- > How can I do this with DBKit?.
- >
- > The way I look at it, there is 2 different ways to approach this.
- >
- > 1) try to get a value back from a SQL function. I can then use
- > that in the building of the qualifier. In looking at the docs, the
- > evaluateString: method would do the trick, but I don't know how to get
- the
- > value back from that. I can do the following from withn isql:
- > > 1> SELECT SOUNDEX('Anderson')
- > > 2> go
- > >
- > > -----
- > > A536
- > >
- > > (1 row affected)
- > > 1>
- > Now, If I send it that string using evaluateString, how do I get
- > the value back? This would also be nice in finding things like MAX,
- MIN,
- > AVG,etc
-
- You must tell DBKit about the properties you expect back even though you
- are bypassing the sql composition component of DBKit. DBkit needs to know
- where to copy the results into the client program. Here is a containerless
- binder I use to assign sequence numbers from an oracle server to new rows
- in a recordlist:
-
- aBinder = [[DBBinder allocFromZone:[self zone]] init];
- [aBinder setFlushEnabled:NO];
- ...
- const char *currStatement = "SELECT PURCHASE_GEN.NEXTVAL FROM
- USER_TABLES";
-
- seqNoProp = [[fetchGroup entity] propertyNamed:"IDNO"];
-
- // -- show binder were to store returned values
- //
- nextValProp = [[DBExpression allocFromZone:[self zone]]
- initForEntity:[fetchGroup entity]
- fromDescription:"NEXTVAL"];
- [aBinder addProperty:nextValProp];
- [aBinder setDatabase:[[fetchGroup module] database]];
- [aBinder setRecordPrototype:[[_Seqno allocFromZone:[aBinder
- scratchZone]] init]];
- [aBinder associateRecordIvar:"seqno" withProperty:nextValProp];
-
- // -- use containerless binder
- //
- if ( [aBinder evaluateString:currStatement] ) {
- [aBinder fetch];
- }
-
- // -- set value in recordlist
- //
- aValue = [[DBValue allocFromZone:[aBinder scratchZone]] init];
- [aValue setIntValue:[[aBinder recordPrototype] seqno]];
- [[fetchGroup recordList] setValue:aValue
- forProperty:seqNoProp at:index];
-
- >
- > --
- > Mark Roder
- > NeXT Consultant, Mayo Foundation
- > NeXT Mail: roder@mayo.edu
- > phone: (507) 284-5306
- --
- Jon Buffington <internet: jonb@infoman.com uucp: uunet!infoman!jonb>
- NeXT VAD Atlanta, GA NeXTmail accepted
-