diff --git a/uppdev/Freetds/Freetds.cpp b/uppdev/Freetds/Freetds.cpp new file mode 100644 index 000000000..a2604f69f --- /dev/null +++ b/uppdev/Freetds/Freetds.cpp @@ -0,0 +1,69 @@ +#include + +#include +#include +#include +#include +#include +#include +#include + +#include /* sqlfront.h always comes first */ +#include /* sybdb.h is the only other file you need */ + +int err_handler(DBPROCESS*, int, int, int, char*, char*) {} +int msg_handler(DBPROCESS*, DBINT, int, int, char*, char*, char*, int) {} + +using namespace Upp; + +extern char *optarg; +extern int optind; + +const static char syntax[] = + "syntax: example -S server -D db -U user -P passwd\n"; + +struct Options { + char *appname, *servername, *dbname, *username, *password; +} options = {0,0,0,0,0}; + + +CONSOLE_APP_MAIN +{ + int i, ch; + LOGINREC *login; + DBPROCESS *dbproc; + RETCODE erc; + + options.appname = "Holly"; + + options.servername = strdup("mssql"); + options.dbname = strdup("Holly"); + + if (dbinit() == FAIL) { + LOG("dbinit failed"); + return; + } + + dberrhandle(err_handler); + dbmsghandle(msg_handler); + + if ((login = dblogin()) == NULL) { + LOG("dblogin failed"); + return; + } + + DBSETLUSER(login, options.username); + DBSETLPWD(login, options.password); + + if ((dbproc = dbopen(login, options.servername)) == NULL) { + LOG("unable to connect"); + return; + } + + if (options.dbname && (erc = dbuse(dbproc, options.dbname)) == FAIL) { + LOG("unable to use db"); + return; + } + + LOG("Success!"); +} diff --git a/uppdev/Freetds/Freetds.upp b/uppdev/Freetds/Freetds.upp new file mode 100644 index 000000000..ad8071922 --- /dev/null +++ b/uppdev/Freetds/Freetds.upp @@ -0,0 +1,12 @@ +uses + Core; + +library + sybdb; + +file + Freetds.cpp; + +mainconfig + "" = ""; + diff --git a/uppdev/Freetds/init b/uppdev/Freetds/init new file mode 100644 index 000000000..d34fe5678 --- /dev/null +++ b/uppdev/Freetds/init @@ -0,0 +1,4 @@ +#ifndef _Freetds_icpp_init_stub +#define _Freetds_icpp_init_stub +#include "Core/init" +#endif