1 /* $NetBSD: pgfs_db.h,v 1.2 2012/04/11 14:26:44 yamt Exp $ */ 2 3 /*- 4 * Copyright (c)2010,2011 YAMAMOTO Takashi, 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 */ 28 29 #include <libpq-fe.h> /* Oid */ 30 31 int pgfs_connectdb(struct puffs_usermount *, const char *, const char *, bool, 32 bool, unsigned int); 33 34 #define CREATECMD(c, cmd, ...) \ 35 if ((c) == NULL) (c) = createcmd((cmd), 0, __VA_ARGS__) 36 #define CREATECMD_NOPARAM(c, cmd) \ 37 if ((c) == NULL) (c) = createcmd((cmd), 0) 38 39 struct cmd *createcmd(const char *, unsigned int, ...); 40 41 #define FETCHNEXT(s, t, ...) \ 42 fetchnext((s), __arraycount(t), (t), __VA_ARGS__) 43 44 struct Xconn; 45 46 int sendcmd(struct Xconn *, struct cmd *, ...); 47 int sendcmdx(struct Xconn *, int, struct cmd *, ...); 48 int simplecmd(struct Xconn *, struct cmd *, ...); 49 int simplefetch(struct Xconn *, Oid, ...); 50 51 struct fetchstatus { 52 struct Xconn *xc; 53 PGresult *res; 54 unsigned int cur; 55 unsigned int nrows; 56 bool done; 57 }; 58 59 void fetchinit(struct fetchstatus *, struct Xconn *); 60 int fetchnext(struct fetchstatus *, unsigned int, const Oid *, ...); 61 void fetchdone(struct fetchstatus *); 62 63 struct Xconn *begin(struct puffs_usermount *, const char *); 64 struct Xconn *begin_readonly(struct puffs_usermount *, const char *); 65 void rollback(struct Xconn *); 66 int commit(struct Xconn *); 67 int commit_sync(struct Xconn *); 68 int flush_xacts(struct puffs_usermount *); 69 70 /* 71 * PostgreSQL stuff 72 * 73 * XXX these definitions should not be here. 74 * probably type OIDs should be obtained from pg_type at runtime? 75 */ 76 77 #define LOBLKSIZE (8 * 1024 / 4) 78 79 #define BYTEA 17 80 #define INT8OID 20 81 #define INT4OID 23 82 #define TEXTOID 25 83 #define OIDOID 26 84 #define TIMESTAMPTZOID 1184 85 86 int timespec_to_pgtimestamp(const struct timespec *, char **); 87