From cadaee395e4161b559ab345d175c8b32c4950d19 Mon Sep 17 00:00:00 2001 From: Wilrik de Loose Date: Tue, 6 May 2008 12:35:55 +0000 Subject: db_demo files --- db_demo/Debug/BuildLog.htm | Bin 0 -> 4516 bytes db_demo/Debug/db_demo.exe.embed.manifest | 1 + db_demo/Debug/db_demo.exe.embed.manifest.res | Bin 0 -> 2112 bytes db_demo/Debug/getopt.obj | Bin 0 -> 1359 bytes db_demo/Debug/reset.obj | Bin 0 -> 8898 bytes db_demo/Debug/vc80.idb | Bin 0 -> 35840 bytes db_demo/Debug/vc80.pdb | Bin 0 -> 61440 bytes db_demo/db_demo.ncb | Bin 0 -> 232448 bytes db_demo/db_demo.sln | 20 ++ db_demo/db_demo.suo | Bin 0 -> 12288 bytes db_demo/db_demo.vcproj | 202 +++++++++++ db_demo/db_demo.vcproj.TUE.s052058.user | 65 ++++ db_demo/getopt.c | 169 +++++++++ db_demo/libpq-fe.h | 510 +++++++++++++++++++++++++++ db_demo/libpq.dll | Bin 0 -> 158780 bytes db_demo/reset.c | 70 ++++ db_demo/reset.h | 25 ++ 17 files changed, 1062 insertions(+) create mode 100644 db_demo/Debug/BuildLog.htm create mode 100644 db_demo/Debug/db_demo.exe.embed.manifest create mode 100644 db_demo/Debug/db_demo.exe.embed.manifest.res create mode 100644 db_demo/Debug/getopt.obj create mode 100644 db_demo/Debug/reset.obj create mode 100644 db_demo/Debug/vc80.idb create mode 100644 db_demo/Debug/vc80.pdb create mode 100644 db_demo/db_demo.ncb create mode 100644 db_demo/db_demo.sln create mode 100644 db_demo/db_demo.suo create mode 100644 db_demo/db_demo.vcproj create mode 100644 db_demo/db_demo.vcproj.TUE.s052058.user create mode 100644 db_demo/getopt.c create mode 100644 db_demo/libpq-fe.h create mode 100644 db_demo/libpq.dll create mode 100644 db_demo/reset.c create mode 100644 db_demo/reset.h diff --git a/db_demo/Debug/BuildLog.htm b/db_demo/Debug/BuildLog.htm new file mode 100644 index 0000000..e0d4f6f Binary files /dev/null and b/db_demo/Debug/BuildLog.htm differ diff --git a/db_demo/Debug/db_demo.exe.embed.manifest b/db_demo/Debug/db_demo.exe.embed.manifest new file mode 100644 index 0000000..d2d2076 --- /dev/null +++ b/db_demo/Debug/db_demo.exe.embed.manifest @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/db_demo/Debug/db_demo.exe.embed.manifest.res b/db_demo/Debug/db_demo.exe.embed.manifest.res new file mode 100644 index 0000000..3a6eb75 Binary files /dev/null and b/db_demo/Debug/db_demo.exe.embed.manifest.res differ diff --git a/db_demo/Debug/getopt.obj b/db_demo/Debug/getopt.obj new file mode 100644 index 0000000..9467e62 Binary files /dev/null and b/db_demo/Debug/getopt.obj differ diff --git a/db_demo/Debug/reset.obj b/db_demo/Debug/reset.obj new file mode 100644 index 0000000..df39ac1 Binary files /dev/null and b/db_demo/Debug/reset.obj differ diff --git a/db_demo/Debug/vc80.idb b/db_demo/Debug/vc80.idb new file mode 100644 index 0000000..084f6b5 Binary files /dev/null and b/db_demo/Debug/vc80.idb differ diff --git a/db_demo/Debug/vc80.pdb b/db_demo/Debug/vc80.pdb new file mode 100644 index 0000000..c105627 Binary files /dev/null and b/db_demo/Debug/vc80.pdb differ diff --git a/db_demo/db_demo.ncb b/db_demo/db_demo.ncb new file mode 100644 index 0000000..f165350 Binary files /dev/null and b/db_demo/db_demo.ncb differ diff --git a/db_demo/db_demo.sln b/db_demo/db_demo.sln new file mode 100644 index 0000000..59bffa6 --- /dev/null +++ b/db_demo/db_demo.sln @@ -0,0 +1,20 @@ + +Microsoft Visual Studio Solution File, Format Version 9.00 +# Visual Studio 2005 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "db_demo", "db_demo.vcproj", "{9D6F3903-9D46-4F8D-BF55-76C3800005BC}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {9D6F3903-9D46-4F8D-BF55-76C3800005BC}.Debug|Win32.ActiveCfg = Debug|Win32 + {9D6F3903-9D46-4F8D-BF55-76C3800005BC}.Debug|Win32.Build.0 = Debug|Win32 + {9D6F3903-9D46-4F8D-BF55-76C3800005BC}.Release|Win32.ActiveCfg = Release|Win32 + {9D6F3903-9D46-4F8D-BF55-76C3800005BC}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/db_demo/db_demo.suo b/db_demo/db_demo.suo new file mode 100644 index 0000000..1405612 Binary files /dev/null and b/db_demo/db_demo.suo differ diff --git a/db_demo/db_demo.vcproj b/db_demo/db_demo.vcproj new file mode 100644 index 0000000..8fae3cd --- /dev/null +++ b/db_demo/db_demo.vcproj @@ -0,0 +1,202 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/db_demo/db_demo.vcproj.TUE.s052058.user b/db_demo/db_demo.vcproj.TUE.s052058.user new file mode 100644 index 0000000..5ea8aa5 --- /dev/null +++ b/db_demo/db_demo.vcproj.TUE.s052058.user @@ -0,0 +1,65 @@ + + + + + + + + + + + diff --git a/db_demo/getopt.c b/db_demo/getopt.c new file mode 100644 index 0000000..2c65f00 --- /dev/null +++ b/db_demo/getopt.c @@ -0,0 +1,169 @@ + + +/* +* Disktest +* Copyright (c) International Business Machines Corp., 2001 +* +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +* +* Please send e-mail to yardleyb@us.ibm.com if you have +* questions or comments. +* +* Project Website: TBD +* +* +* $Id: Getopt.c,v 1.4 2005/05/04 17:54:00 mridge Exp $ +* $Log: Getopt.c,v $ +* Revision 1.4 2005/05/04 17:54:00 mridge +* Update to version 1.2.8 +* +* Revision 1.4 2002/03/30 01:32:14 yardleyb +* Major Changes: +* +* Added Dumping routines for +* data miscompares, +* +* Updated performance output +* based on command line. Gave +* one decimal in MB/s output. +* +* Rewrote -pL IO routine to show +* correct stats. Now show pass count +* when using -C. +* +* Minor Changes: +* +* Code cleanup to remove the plethera +* if #ifdef for windows/unix functional +* differences. +* +* Revision 1.3 2002/02/21 21:32:19 yardleyb +* Added more unix compatability +* ifdef'd function out when +* compiling for unix env. that +* have getopt +* +* Revision 1.2 2002/02/04 20:35:38 yardleyb +* Changed max. number of threads to 64k. +* Check for max threads in parsing. +* Fixed windows getopt to return correctly +* when a bad option is given. +* Update time output to be in the format: +* YEAR/MONTH/DAY-HOUR:MIN:SEC +* instead of epoch time. +* +* Revision 1.1 2001/12/04 18:57:36 yardleyb +* This source add for windows compatability only. +* +*/ + +#ifdef WINDOWS + +#include +#include +#include +#include +#include "getopt.h" + +/* + * + * FUNCTION: getopt() + * + * Get next command line option and parameter + * source gathered from MS examples and modified + * to conform with unix like getopt. + * + */ + +/* Global Exportable */ +int optind; +char *optarg; + +int getopt (int argc, char** argv, char* pszValidOpts) { + char chOpt; + char* psz = NULL; + char* pszParam = NULL; + static int iArg = 1; + + if (iArg < argc) { + psz = &(argv[iArg][0]); + if (*psz == '-' || *psz == '/') { + /* we have an option specifier */ + chOpt = argv[iArg][1]; + if (isalnum(chOpt) || ispunct(chOpt)) { + /* we have an option character */ + psz = strchr(pszValidOpts, chOpt); + if (psz != NULL) { + /* option is valid, we want to return chOpt */ + if (psz[1] == ':') { + /* option can have a parameter */ + psz = &(argv[iArg][2]); + if (*psz == '\0') { + /* must look at next argv for param */ + if (iArg+1 < argc) { + psz = &(argv[iArg+1][0]); + if (*psz == '-' || *psz == '/') { + /* next argv is a new option, so param + * not given for current option + */ + fprintf(stderr, "-%c option requires an argument.\n", chOpt); + chOpt = '?'; + pszParam = NULL; + } else { + /* next argv is the param */ + iArg++; + pszParam = psz; + } + } else { + /* reached end of args looking for param */ + } + } else { + /* param is attached to option */ + pszParam = psz; + } + } else { + /* option is alone, has no parameter */ + } + } else { + /* option specified is not in list of valid options */ + fprintf(stderr, "Invalid option -- %c\n", chOpt); + chOpt = '?'; + pszParam = NULL; + } + } else { + /* though option specifier was given, option character + * is not alpha or was was not specified + */ + chOpt = 0; + pszParam = &(argv[iArg][0]); + } + } else { + /* standalone arg given with no option specifier */ + chOpt = -1; + pszParam = &(argv[iArg][0]); + } + } else { + /* end of argument list */ + chOpt = -1; + } + + optind = iArg++; + optarg = pszParam; + return (chOpt); +} + +#endif /* defined WINDOWS */ + diff --git a/db_demo/libpq-fe.h b/db_demo/libpq-fe.h new file mode 100644 index 0000000..a675335 --- /dev/null +++ b/db_demo/libpq-fe.h @@ -0,0 +1,510 @@ +/*------------------------------------------------------------------------- + * + * libpq-fe.h + * This file contains definitions for structures and + * externs for functions used by frontend postgres applications. + * + * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group + * Portions Copyright (c) 1994, Regents of the University of California + * + * $PostgreSQL: pgsql/src/interfaces/libpq/libpq-fe.h,v 1.116.4.1 2006/05/21 20:20:05 tgl Exp $ + * + *------------------------------------------------------------------------- + */ + +#ifndef LIBPQ_FE_H +#define LIBPQ_FE_H + +#ifdef __cplusplus +extern "C" +{ +#endif + +#include + +/* + * postgres_ext.h defines the backend's externally visible types, + * such as Oid. + */ +#include "postgres_ext.h" + +/* SSL type is needed here only to declare PQgetssl() */ +#ifdef USE_SSL +#include +#endif + +/* Application-visible enum types */ + +typedef enum +{ + /* + * Although it is okay to add to this list, values which become unused + * should never be removed, nor should constants be redefined - that + * would break compatibility with existing code. + */ + CONNECTION_OK, + CONNECTION_BAD, + /* Non-blocking mode only below here */ + + /* + * The existence of these should never be relied upon - they should + * only be used for user feedback or similar purposes. + */ + CONNECTION_STARTED, /* Waiting for connection to be made. */ + CONNECTION_MADE, /* Connection OK; waiting to send. */ + CONNECTION_AWAITING_RESPONSE, /* Waiting for a response from the + * postmaster. */ + CONNECTION_AUTH_OK, /* Received authentication; waiting for + * backend startup. */ + CONNECTION_SETENV, /* Negotiating environment. */ + CONNECTION_SSL_STARTUP, /* Negotiating SSL. */ + CONNECTION_NEEDED /* Internal state: connect() needed */ +} ConnStatusType; + +typedef enum +{ + PGRES_POLLING_FAILED = 0, + PGRES_POLLING_READING, /* These two indicate that one may */ + PGRES_POLLING_WRITING, /* use select before polling again. */ + PGRES_POLLING_OK, + PGRES_POLLING_ACTIVE /* unused; keep for awhile for backwards + * compatibility */ +} PostgresPollingStatusType; + +typedef enum +{ + PGRES_EMPTY_QUERY = 0, /* empty query string was executed */ + PGRES_COMMAND_OK, /* a query command that doesn't return + * anything was executed properly by the + * backend */ + PGRES_TUPLES_OK, /* a query command that returns tuples was + * executed properly by the backend, + * PGresult contains the result tuples */ + PGRES_COPY_OUT, /* Copy Out data transfer in progress */ + PGRES_COPY_IN, /* Copy In data transfer in progress */ + PGRES_BAD_RESPONSE, /* an unexpected response was recv'd from + * the backend */ + PGRES_NONFATAL_ERROR, /* notice or warning message */ + PGRES_FATAL_ERROR /* query failed */ +} ExecStatusType; + +typedef enum +{ + PQTRANS_IDLE, /* connection idle */ + PQTRANS_ACTIVE, /* command in progress */ + PQTRANS_INTRANS, /* idle, within transaction block */ + PQTRANS_INERROR, /* idle, within failed transaction */ + PQTRANS_UNKNOWN /* cannot determine status */ +} PGTransactionStatusType; + +typedef enum +{ + PQERRORS_TERSE, /* single-line error messages */ + PQERRORS_DEFAULT, /* recommended style */ + PQERRORS_VERBOSE /* all the facts, ma'am */ +} PGVerbosity; + +/* PGconn encapsulates a connection to the backend. + * The contents of this struct are not supposed to be known to applications. + */ +typedef struct pg_conn PGconn; + +/* PGresult encapsulates the result of a query (or more precisely, of a single + * SQL command --- a query string given to PQsendQuery can contain multiple + * commands and thus return multiple PGresult objects). + * The contents of this struct are not supposed to be known to applications. + */ +typedef struct pg_result PGresult; + +/* PGcancel encapsulates the information needed to cancel a running + * query on an existing connection. + * The contents of this struct are not supposed to be known to applications. + */ +typedef struct pg_cancel PGcancel; + +/* PGnotify represents the occurrence of a NOTIFY message. + * Ideally this would be an opaque typedef, but it's so simple that it's + * unlikely to change. + * NOTE: in Postgres 6.4 and later, the be_pid is the notifying backend's, + * whereas in earlier versions it was always your own backend's PID. + */ +typedef struct pgNotify +{ + char *relname; /* notification condition name */ + int be_pid; /* process ID of server process */ + char *extra; /* notification parameter */ + /* Fields below here are private to libpq; apps should not use 'em */ + struct pgNotify *next; /* list link */ +} PGnotify; + +/* Function types for notice-handling callbacks */ +typedef void (*PQnoticeReceiver) (void *arg, const PGresult *res); +typedef void (*PQnoticeProcessor) (void *arg, const char *message); + +/* Print options for PQprint() */ +typedef char pqbool; + +typedef struct _PQprintOpt +{ + pqbool header; /* print output field headings and row + * count */ + pqbool align; /* fill align the fields */ + pqbool standard; /* old brain dead format */ + pqbool html3; /* output html tables */ + pqbool expanded; /* expand tables */ + pqbool pager; /* use pager for output if needed */ + char *fieldSep; /* field separator */ + char *tableOpt; /* insert to HTML */ + char *caption; /* HTML
*/ + char **fieldName; /* null terminated array of repalcement + * field names */ +} PQprintOpt; + +/* ---------------- + * Structure for the conninfo parameter definitions returned by PQconndefaults + * + * All fields except "val" point at static strings which must not be altered. + * "val" is either NULL or a malloc'd current-value string. PQconninfoFree() + * will release both the val strings and the PQconninfoOption array itself. + * ---------------- + */ +typedef struct _PQconninfoOption +{ + char *keyword; /* The keyword of the option */ + char *envvar; /* Fallback environment variable name */ + char *compiled; /* Fallback compiled in default value */ + char *val; /* Option's current value, or NULL */ + char *label; /* Label for field in connect dialog */ + char *dispchar; /* Character to display for this field in + * a connect dialog. Values are: "" + * Display entered value as is "*" + * Password field - hide value "D" Debug + * option - don't show by default */ + int dispsize; /* Field size in characters for dialog */ +} PQconninfoOption; + +/* ---------------- + * PQArgBlock -- structure for PQfn() arguments + * ---------------- + */ +typedef struct +{ + int len; + int isint; + union + { + int *ptr; /* can't use void (dec compiler barfs) */ + int integer; + } u; +} PQArgBlock; + +/* ---------------- + * Exported functions of libpq + * ---------------- + */ + +/* === in fe-connect.c === */ + +/* make a new client connection to the backend */ +/* Asynchronous (non-blocking) */ +extern PGconn *PQconnectStart(const char *conninfo); +extern PostgresPollingStatusType PQconnectPoll(PGconn *conn); + +/* Synchronous (blocking) */ +extern PGconn *PQconnectdb(const char *conninfo); +extern PGconn *PQsetdbLogin(const char *pghost, const char *pgport, + const char *pgoptions, const char *pgtty, + const char *dbName, + const char *login, const char *pwd); + +#define PQsetdb(M_PGHOST,M_PGPORT,M_PGOPT,M_PGTTY,M_DBNAME) \ + PQsetdbLogin(M_PGHOST, M_PGPORT, M_PGOPT, M_PGTTY, M_DBNAME, NULL, NULL) + +/* close the current connection and free the PGconn data structure */ +extern void PQfinish(PGconn *conn); + +/* get info about connection options known to PQconnectdb */ +extern PQconninfoOption *PQconndefaults(void); + +/* free the data structure returned by PQconndefaults() */ +extern void PQconninfoFree(PQconninfoOption *connOptions); + +/* + * close the current connection and restablish a new one with the same + * parameters + */ +/* Asynchronous (non-blocking) */ +extern int PQresetStart(PGconn *conn); +extern PostgresPollingStatusType PQresetPoll(PGconn *conn); + +/* Synchronous (blocking) */ +extern void PQreset(PGconn *conn); + +/* request a cancel structure */ +extern PGcancel *PQgetCancel(PGconn *conn); + +/* free a cancel structure */ +extern void PQfreeCancel(PGcancel *cancel); + +/* issue a cancel request */ +extern int PQcancel(PGcancel *cancel, char *errbuf, int errbufsize); + +/* backwards compatible version of PQcancel; not thread-safe */ +extern int PQrequestCancel(PGconn *conn); + +/* Accessor functions for PGconn objects */ +extern char *PQdb(const PGconn *conn); +extern char *PQuser(const PGconn *conn); +extern char *PQpass(const PGconn *conn); +extern char *PQhost(const PGconn *conn); +extern char *PQport(const PGconn *conn); +extern char *PQtty(const PGconn *conn); +extern char *PQoptions(const PGconn *conn); +extern ConnStatusType PQstatus(const PGconn *conn); +extern PGTransactionStatusType PQtransactionStatus(const PGconn *conn); +extern const char *PQparameterStatus(const PGconn *conn, + const char *paramName); +extern int PQprotocolVersion(const PGconn *conn); +extern int PQserverVersion(const PGconn *conn); +extern char *PQerrorMessage(const PGconn *conn); +extern int PQsocket(const PGconn *conn); +extern int PQbackendPID(const PGconn *conn); +extern int PQclientEncoding(const PGconn *conn); +extern int PQsetClientEncoding(PGconn *conn, const char *encoding); + +#ifdef USE_SSL +/* Get the SSL structure associated with a connection */ +extern SSL *PQgetssl(PGconn *conn); +#else +extern void *PQgetssl(PGconn *conn); +#endif + +/* Tell libpq whether it needs to initialize OpenSSL */ +extern void PQinitSSL(int do_init); + +/* Set verbosity for PQerrorMessage and PQresultErrorMessage */ +extern PGVerbosity PQsetErrorVerbosity(PGconn *conn, PGVerbosity verbosity); + +/* Enable/disable tracing */ +extern void PQtrace(PGconn *conn, FILE *debug_port); +extern void PQuntrace(PGconn *conn); + +/* Override default notice handling routines */ +extern PQnoticeReceiver PQsetNoticeReceiver(PGconn *conn, + PQnoticeReceiver proc, + void *arg); +extern PQnoticeProcessor PQsetNoticeProcessor(PGconn *conn, + PQnoticeProcessor proc, + void *arg); + +/* + * Used to set callback that prevents concurrent access to + * non-thread safe functions that libpq needs. + * The default implementation uses a libpq internal mutex. + * Only required for multithreaded apps that use kerberos + * both within their app and for postgresql connections. + */ +typedef void (*pgthreadlock_t) (int acquire); + +extern pgthreadlock_t PQregisterThreadLock(pgthreadlock_t newhandler); + +/* === in fe-exec.c === */ + +/* Simple synchronous query */ +extern PGresult *PQexec(PGconn *conn, const char *query); +extern PGresult *PQexecParams(PGconn *conn, + const char *command, + int nParams, + const Oid *paramTypes, + const char *const * paramValues, + const int *paramLengths, + const int *paramFormats, + int resultFormat); +extern PGresult *PQprepare(PGconn *conn, const char *stmtName, + const char *query, int nParams, + const Oid *paramTypes); +extern PGresult *PQexecPrepared(PGconn *conn, + const char *stmtName, + int nParams, + const char *const * paramValues, + const int *paramLengths, + const int *paramFormats, + int resultFormat); + +/* Interface for multiple-result or asynchronous queries */ +extern int PQsendQuery(PGconn *conn, const char *query); +extern int PQsendQueryParams(PGconn *conn, + const char *command, + int nParams, + const Oid *paramTypes, + const char *const * paramValues, + const int *paramLengths, + const int *paramFormats, + int resultFormat); +extern int PQsendPrepare(PGconn *conn, const char *stmtName, + const char *query, int nParams, + const Oid *paramTypes); +extern int PQsendQueryPrepared(PGconn *conn, + const char *stmtName, + int nParams, + const char *const * paramValues, + const int *paramLengths, + const int *paramFormats, + int resultFormat); +extern PGresult *PQgetResult(PGconn *conn); + +/* Routines for managing an asynchronous query */ +extern int PQisBusy(PGconn *conn); +extern int PQconsumeInput(PGconn *conn); + +/* LISTEN/NOTIFY support */ +extern PGnotify *PQnotifies(PGconn *conn); + +/* Routines for copy in/out */ +extern int PQputCopyData(PGconn *conn, const char *buffer, int nbytes); +extern int PQputCopyEnd(PGconn *conn, const char *errormsg); +extern int PQgetCopyData(PGconn *conn, char **buffer, int async); + +/* Deprecated routines for copy in/out */ +extern int PQgetline(PGconn *conn, char *string, int length); +extern int PQputline(PGconn *conn, const char *string); +extern int PQgetlineAsync(PGconn *conn, char *buffer, int bufsize); +extern int PQputnbytes(PGconn *conn, const char *buffer, int nbytes); +extern int PQendcopy(PGconn *conn); + +/* Set blocking/nonblocking connection to the backend */ +extern int PQsetnonblocking(PGconn *conn, int arg); +extern int PQisnonblocking(const PGconn *conn); + +/* Force the write buffer to be written (or at least try) */ +extern int PQflush(PGconn *conn); + +/* + * "Fast path" interface --- not really recommended for application + * use + */ +extern PGresult *PQfn(PGconn *conn, + int fnid, + int *result_buf, + int *result_len, + int result_is_int, + const PQArgBlock *args, + int nargs); + +/* Accessor functions for PGresult objects */ +extern ExecStatusType PQresultStatus(const PGresult *res); +extern char *PQresStatus(ExecStatusType status); +extern char *PQresultErrorMessage(const PGresult *res); +extern char *PQresultErrorField(const PGresult *res, int fieldcode); +extern int PQntuples(const PGresult *res); +extern int PQnfields(const PGresult *res); +extern int PQbinaryTuples(const PGresult *res); +extern char *PQfname(const PGresult *res, int field_num); +extern int PQfnumber(const PGresult *res, const char *field_name); +extern Oid PQftable(const PGresult *res, int field_num); +extern int PQftablecol(const PGresult *res, int field_num); +extern int PQfformat(const PGresult *res, int field_num); +extern Oid PQftype(const PGresult *res, int field_num); +extern int PQfsize(const PGresult *res, int field_num); +extern int PQfmod(const PGresult *res, int field_num); +extern char *PQcmdStatus(PGresult *res); +extern char *PQoidStatus(const PGresult *res); /* old and ugly */ +extern Oid PQoidValue(const PGresult *res); /* new and improved */ +extern char *PQcmdTuples(PGresult *res); +extern char *PQgetvalue(const PGresult *res, int tup_num, int field_num); +extern int PQgetlength(const PGresult *res, int tup_num, int field_num); +extern int PQgetisnull(const PGresult *res, int tup_num, int field_num); + +/* Delete a PGresult */ +extern void PQclear(PGresult *res); + +/* For freeing other alloc'd results, such as PGnotify structs */ +extern void PQfreemem(void *ptr); + +/* Exists for backward compatibility. bjm 2003-03-24 */ +#define PQfreeNotify(ptr) PQfreemem(ptr) + +/* Define the string so all uses are consistent. */ +#define PQnoPasswordSupplied "fe_sendauth: no password supplied\n" + +/* + * Make an empty PGresult with given status (some apps find this + * useful). If conn is not NULL and status indicates an error, the + * conn's errorMessage is copied. + */ +extern PGresult *PQmakeEmptyPGresult(PGconn *conn, ExecStatusType status); + + +/* Quoting strings before inclusion in queries. */ +extern size_t PQescapeStringConn(PGconn *conn, + char *to, const char *from, size_t length, + int *error); +extern unsigned char *PQescapeByteaConn(PGconn *conn, + const unsigned char *from, size_t from_length, + size_t *to_length); +extern unsigned char *PQunescapeBytea(const unsigned char *strtext, + size_t *retbuflen); +/* These forms are deprecated! */ +extern size_t PQescapeString(char *to, const char *from, size_t length); +extern unsigned char *PQescapeBytea(const unsigned char *from, size_t from_length, + size_t *to_length); + + + +/* === in fe-print.c === */ + +extern void +PQprint(FILE *fout, /* output stream */ + const PGresult *res, + const PQprintOpt *ps); /* option structure */ + +/* + * really old printing routines + */ +extern void +PQdisplayTuples(const PGresult *res, + FILE *fp, /* where to send the output */ + int fillAlign, /* pad the fields with spaces */ + const char *fieldSep, /* field separator */ + int printHeader, /* display headers? */ + int quiet); + +extern void +PQprintTuples(const PGresult *res, + FILE *fout, /* output stream */ + int printAttName, /* print attribute names */ + int terseOutput, /* delimiter bars */ + int width); /* width of column, if 0, use variable + * width */ + + +/* === in fe-lobj.c === */ + +/* Large-object access routines */ +extern int lo_open(PGconn *conn, Oid lobjId, int mode); +extern int lo_close(PGconn *conn, int fd); +extern int lo_read(PGconn *conn, int fd, char *buf, size_t len); +extern int lo_write(PGconn *conn, int fd, char *buf, size_t len); +extern int lo_lseek(PGconn *conn, int fd, int offset, int whence); +extern Oid lo_creat(PGconn *conn, int mode); +extern int lo_tell(PGconn *conn, int fd); +extern int lo_unlink(PGconn *conn, Oid lobjId); +extern Oid lo_import(PGconn *conn, const char *filename); +extern int lo_export(PGconn *conn, Oid lobjId, const char *filename); + +/* === in fe-misc.c === */ + +/* Determine length of multibyte encoded char at *s */ +extern int PQmblen(const unsigned char *s, int encoding); + +/* Determine display length of multibyte encoded char at *s */ +extern int PQdsplen(const unsigned char *s, int encoding); + +/* Get encoding id from environment variable PGCLIENTENCODING */ +extern int PQenv2encoding(void); + +#ifdef __cplusplus +} +#endif + +#endif /* LIBPQ_FE_H */ diff --git a/db_demo/libpq.dll b/db_demo/libpq.dll new file mode 100644 index 0000000..7d9d2a2 Binary files /dev/null and b/db_demo/libpq.dll differ diff --git a/db_demo/reset.c b/db_demo/reset.c new file mode 100644 index 0000000..6fd92f7 --- /dev/null +++ b/db_demo/reset.c @@ -0,0 +1,70 @@ +#include +#include + +#include "libpq-fe.h" +#include "reset.h" + +int main(int argc, char *argv[]) { + int i; + int options; + int day; + int month; + int year; + PGconn *conn; + char SQL_query[512]; + PGresult *res; + + day = month = year = 0; + + conn = PQsetdbLogin(PGHOST, PGPORT, PGOPTIONS, PGTTY, DBNAME, LOGIN, PWD); + + if(CONNECTION_BAD == PQstatus(conn)) { + fprintf(stderr, "Connection to database '%s' failed.\n %s", DBNAME, PQerrorMessage(conn)); + PQfinish(conn); + return 1; + } + + if(0 < day) { + for(i = 0; i <= day; i++) { + sprintf(SQL_query, "UPDATE counter_day SET \"%0.2d\" = 0;", i); + res = PQexec(conn, SQL_query); + + if((NULL == res) || (PGRES_COMMAND_OK != PQresultStatus(res))) { + printf("Unable to execute query: %s\n %s\n", SQL_query, PQerrorMessage(conn)); + PQclear(res); + PQfinish(conn); + return 1; + } + PQclear(res); + } + } + if(0 < month) { + for(i = 1; i <= month; i++) { + sprintf(SQL_query, "UPDATE counter_month SET \"%0.2d\" = 0;", i); + res = PQexec(conn, SQL_query); + + if((NULL == res) || (PGRES_COMMAND_OK != PQresultStatus(res))) { + printf("Unable to execute query: %s\n %s\n", SQL_query, PQerrorMessage(conn)); + PQclear(res); + PQfinish(conn); + return 1; + } + PQclear(res); + } + } + if(1 == year) { + sprintf(SQL_query, "INSERT INTO counter_year VALUES (counter_year.year +1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);"); + res = PQexec(conn, SQL_query); + + if((NULL == res) || (PGRES_COMMAND_OK != PQresultStatus(res))) { + printf("Unable to execute query: %s\n %s\n", SQL_query, PQerrorMessage(conn)); + PQclear(res); + PQfinish(conn); + return 1; + } + PQclear(res); + } + PQfinish(conn); + + return 0; +} diff --git a/db_demo/reset.h b/db_demo/reset.h new file mode 100644 index 0000000..51dd0e0 --- /dev/null +++ b/db_demo/reset.h @@ -0,0 +1,25 @@ +/* + * reset.h + * House of Mozart statistic database reset app (c) 2003 oliver + * + * GNU public license *FIXME* + */ + +#define VERSION 0.0.1 + +#define PGHOST "matchblox.schinagl.nl" +#define PGPORT "5432" +#define PGOPTIONS "\0" +#define PGTTY "\0" +#define DBNAME "2iv55" +#define LOGIN "2iv55" +#define PWD "uhtfiwwp" + +#define SHORTHELP \ +"Not enough or incorrect arguments try -h for help\n" + +#define LONGHELP \ +" -h\tprint this help message\n \ + -d\tReset daily stats\n \ + -m\tReset monthly stats\n \ + -a\tReset All stats (month day)\n" -- cgit v0.12