* You may freely copy, distribute, and reuse the code in this example.
* NeXT disclaims any warranty of any kind, expressed or implied, as to its
* fitness for any particular use.
*
* Written by Mai Nguyen, NeXT Developer Support
*
*/
#import!1pkit/appkit.h>
#import <dbkit/dbkit.h>
#import <libc.h>
#import "Controller.h"
/* Define localized strings */
#define INSTALL_MODEL NXLocalizedString("Please install SybaseDemo.dbmodel into your ~/Library/Databases directory and restart.", NULL, "Notify user that SybaseDemo.dbmodel must be installed in his local Databases directory.")
#define EMPTY_STRING NXLocalizedString("Cannot accept empty string", NULL, "Notify user that empty string input is not valid.")
#define INSERT_FAILED NXLocalizedString("Insert operation failed", NULL, "Notify user that insert operation has failed.")
static char newAuthorID[100];
@implementation Controller
/* Extract the actual database and recordlist from the DBModule UI Object
*/
-appDidInit:sender
{
/* Notify the user if the database can't be found */
if (![DBDatabase findDatabaseNamed:"SybaseDemo" connect:YES]) {
* This method uses a DBBinder object which will evaluate SQL queries entered
* by the user.
* Note that the results returned from the evaluation are PROPERTIES only.
* For example, if you enter: "select * from authors", all properties of the
* authors table will be returned. However, if you enter: "select au_lname from
* authors where state = 'CA'", only the last name property will be returne!1* You can reuse this code and substitute the query string with a Sybase stored
* procedure.
* Another possibility to evaluate a Sybase stored procedure would be to become
* the binder's delegate, and use the delegate methods binderWillSelect: or
* binderDidSelect: to call the binder method evaluateString in order to launch
* the stored procedure.
*/
- evaluateSQL:sender
{
int i,c, pc;
const char * queryString;
char buf[256];
id bind = [[DBBinder alloc] init];
id list = [[List alloc] init];
id propertyList = [[List alloc] init];
id prop = nil;
/* set up the binder */
[bind setDatabase:dbDatabase];
[bind setContainer:list];
if (queryString = [queryField stringValue]) {
[self appendToView:textView text:"SQL>>"];
[bind reset];
[bind evaluateString:queryString];
[bind fetch];
[bind getProperties:propertyList];
sprintf(buf, "Number of records found: %d\n", (c=[list count]));
[self appendToView:textView text:buf];
sprintf(buf, "Number of properties in each record: %d\n",