#pragma interface #ifndef NSQL_H #define NSQL_H class SSTREAM; #include #include #ifndef _mysql_h class MYSQL_RES; #endif class PARAM_STRING; class NSQL_ARGS{ public: char *server; char *db; /*~PROTOBEG~ NSQL_ARGS */ public: NSQL_ARGS (const char *_server, const char *_db); NSQL_ARGS (void); int isok (void); void setdb (const char *s); void setserver (const char *s); ~NSQL_ARGS (void); /*~PROTOEND~ NSQL_ARGS */ }; class NSQL_INTERNAL; class NSQL{ NSQL_INTERNAL *internal; /*~PROTOBEG~ NSQL */ public: NSQL (NSQL_ARGS&args); NSQL (SSTREAM *sout); NSQL (const char *server, const char *db, const char *user, const char *passwd); NSQL (const char *server, const char *db); NSQL (const NSQL &n); bool showerrormode (bool mode); int a_query (const char *req); int a_queryf (const char *ctl, ...); int a_vqueryf (const char *ctl, va_list list); int connect (void); int disconnect (void); int forget_connection(); const char *error (void); int geterrno (); void free_result (MYSQL_RES *res); int getlastid (void); int query (const char *req); int queryf (const char *ctl, ...); void settcpport (const char *port); void settcpport (unsigned int port); void setunixpath (const char *path); void set_charset (PARAM_STRING cset); static void set_default_charset(PARAM_STRING cset); MYSQL_RES *store_result (void); int vqueryf (const char *ctl, va_list list); ~NSQL (void); /*~PROTOEND~ NSQL */ }; #include class NSQL_ENCODE{ class NSQL_STRINGS *tb; /*~PROTOBEG~ NSQL_ENCODE */ public: NSQL_ENCODE (void); const char *enc (const SSTRING *s); const char *enc (const SSTRING &s); const char *enc (const std::string &s); const char *enc (const char *s); ~NSQL_ENCODE (void); /*~PROTOEND~ NSQL_ENCODE */ }; class NSQL_FIELD_NAMES{ int nb; const char **fields; /*~PROTOBEG~ NSQL_FIELD_NAMES */ public: NSQL_FIELD_NAMES (int _nbf, const char *_fields[]); const char *getfieldname (int no)const; int getnb (void)const; /*~PROTOEND~ NSQL_FIELD_NAMES */ }; #define NSQL_IS_PASSWORD 1 // Must be encoded with the password() function class NSQL_FIELD: public SSTRING{ char *name; unsigned flags; /*~PROTOBEG~ NSQL_FIELD */ public: NSQL_FIELD (const char *_name); NSQL_FIELD (const char *_name, unsigned _flags); NSQL_FIELD (void); void clear (void); void clrflag (unsigned one_flag); const char *getsqlname (void)const; void setflag (unsigned one_flag); bool tstflag (unsigned one_flag); ~NSQL_FIELD (void); /*~PROTOEND~ NSQL_FIELD */ }; class NSQL_RECORD{ protected: NSQL_FIELD *tb[100]; int nbfield; int primkey; /*~PROTOBEG~ NSQL_RECORD */ protected: NSQL_RECORD (void); public: void clear (void); int insert_update (NSQL&ns, const char *table,bool on_duplicate); int insert (NSQL&ns, const char *table); int insert (const char *table); int insert_or_update (NSQL&ns, const char *table); int insert_or_update (const char *table); void rstmodified (void); void set (NSQL_FIELD_NAMES&fields, const char *row[]); void setempty (void); int update (NSQL&ns, const char *table, const char *where, ...); int update (const char *table, const char *where, ...); int updatev (NSQL&ns, const char *table, const char *where, va_list list); /*~PROTOEND~ NSQL_RECORD */ }; // Class used to assemble a query from multiple parts while providing proper escaping class NSQL_REQ{ std::string buf; public: NSQL_REQ(); void clear(); void append (PARAM_STRING s); void append (const char car); void append_arg (const unsigned val); void append_arg (const int val); void append_arg (PARAM_STRING s); __attribute__((format(printf, 2, 3))) void appendf (const char *ctl, ...); const char *c_str() const; size_t size() const; template void appendlist(const T &l){ append ('('); if (l.size() > 0){ auto it=begin(l); append_arg(*it); for (++it; it != end(l); ++it){ append (','); append_arg (*it); } } append (')'); } }; #endif