Annotation of libwww/Library/src/HTSQL.html, revision 2.1

2.1     ! frystyk     1: <HTML>
        !             2: <HEAD>
        !             3:   <TITLE>W3C Sample Code Library libwww SQL API</TITLE>
        !             4: </HEAD>
        !             5: <BODY>
        !             6: <H1>
        !             7:   Simple SQL API
        !             8: </H1>
        !             9: <PRE>
        !            10: /*
        !            11: **     (c) COPYRIGHT MIT 1995.
        !            12: **     Please first read the full copyright statement in the file COPYRIGH.
        !            13: */
        !            14: </PRE>
        !            15: <P>
        !            16: This module interacts with the MYSQL C client library to perform SQL operations.
        !            17: It is not intended as a complete SQL API but handles most of the typical
        !            18: error situations talking to an SQL server so that the caller doesn't have
        !            19: to think about it.
        !            20: <P>
        !            21: This requires that you have linked against a <A href="http://www.tcx.se/">MySQL
        !            22: library</A>. See the <A href="../../INSTALL.html">installation instructions</A>
        !            23: for details.
        !            24: <P>
        !            25: This module is implemented by <A HREF="HTSQL.c">HTSQL.c</A>, and it is a
        !            26: part of the <A HREF="http://www.w3.org/Library/"> W3C Sample Code Library</A>.
        !            27: <PRE>
        !            28: #ifndef HTSQL_H
        !            29: #define HTSQL_H
        !            30: 
        !            31: #include &lt;mysql/mysql.h&gt;
        !            32: </PRE>
        !            33: <H2>
        !            34:   The HTSQL Object
        !            35: </H2>
        !            36: <PRE>
        !            37: typedef struct _HTSQL HTSQL;
        !            38: 
        !            39: extern HTSQL * HTSQL_new (const char * host,
        !            40:                          const char * user, const char * pw,
        !            41:                          int flags);
        !            42: extern BOOL HTSQL_delete (HTSQL * me);
        !            43: </PRE>
        !            44: <H2>
        !            45:   Handling the link to the Server
        !            46: </H2>
        !            47: <H3>
        !            48:   Open a connection to the SQL server
        !            49: </H3>
        !            50: <PRE>
        !            51: extern BOOL HTSQL_connect (HTSQL * me);
        !            52: </PRE>
        !            53: <H3>
        !            54:   Close the link to the database
        !            55: </H3>
        !            56: <PRE>
        !            57: extern BOOL HTSQL_close (HTSQL * me);
        !            58: </PRE>
        !            59: <H3>
        !            60:   You can get information about whom we are talking to by calling this function:
        !            61: </H3>
        !            62: <PRE>
        !            63: extern BOOL HTSQL_version (HTSQL *             me,
        !            64:                           char **              server,
        !            65:                           unsigned int *       protocol_version,
        !            66:                           char **              server_version,
        !            67:                           char **              client_version);
        !            68: </PRE>
        !            69: <H3>
        !            70:   Selecting the current database
        !            71: </H3>
        !            72: <PRE>
        !            73: extern BOOL HTSQL_selectDB (HTSQL * me, const char * db);
        !            74: </PRE>
        !            75: <H3>
        !            76:   Getting the raw MYSQL object
        !            77: </H3>
        !            78: <P>
        !            79: After you have connected you can get the raw <CODE>MYSQL</CODE> object by
        !            80: calling this function
        !            81: <PRE>
        !            82: extern MYSQL * HTSQL_getMysql (HTSQL * me);
        !            83: </PRE>
        !            84: <H2>
        !            85:   SQL printf
        !            86: </H2>
        !            87: <P>
        !            88: When creating queries to send to the SQL server you need to generate a lot
        !            89: of SQL specific strings. This function knows most of the commonly used SQL
        !            90: ways of handling date and time string, escaping and quoting strings and how
        !            91: to write integers as strings. The function works pretty much as fprintf with
        !            92: the following possible format arguments:
        !            93: <DL COMPACT>
        !            94:   <DT>
        !            95:     <B>%s</B>
        !            96:   <DD>
        !            97:     Writes a string as is. No quotation or escaping is performed. NULL is written
        !            98:     as "<CODE>null</CODE>".
        !            99:   <DT>
        !           100:     <B>%S</B>
        !           101:   <DD>
        !           102:     Writes a string in quotes and escapes any special SQL characters. NULL is
        !           103:     written as "<CODE>null</CODE>".
        !           104:   <DT>
        !           105:     <B>%T</B>
        !           106:   <DD>
        !           107:     Creates an SQL datetime stamp from a <CODE>time_t</CODE> variable looking
        !           108:     like this <CODE>YYYY-MM-DD HH:MM:SS</CODE>. -1 is written as
        !           109:     "<CODE>null</CODE>"
        !           110:   <DT>
        !           111:     <B>%u</B>
        !           112:   <DD>
        !           113:     Unsigned integer
        !           114:   <DT>
        !           115:     <B>%l</B>
        !           116:   <DD>
        !           117:     Unsigned long integer
        !           118: </DL>
        !           119: <PRE>
        !           120: extern char * HTSQL_printf (char * buf, int length, char * fmt, ...);
        !           121: </PRE>
        !           122: <H2>
        !           123:   Issuing a Query
        !           124: </H2>
        !           125: <P>
        !           126: You can issue a query using this function. If the connection to the server
        !           127: was dropped then it automatically tries to reconnect
        !           128: <PRE>
        !           129: extern BOOL HTSQL_query (HTSQL * me, const char * query);
        !           130: </PRE>
        !           131: <P>
        !           132: Get information about the last inserted row's unique ID or how many rows
        !           133: were affected by the last query:
        !           134: <PRE>
        !           135: extern int HTSQL_getLastInsertId (HTSQL * me);
        !           136: extern int HTSQL_GetAffectedRows (HTSQL * me);
        !           137: </PRE>
        !           138: <H2>
        !           139:   Handle Query Results
        !           140: </H2>
        !           141: <P>
        !           142: Call this funciton to store the SQL query result
        !           143: <PRE>
        !           144: extern MYSQL_RES * HTSQL_storeResult (HTSQL * me);
        !           145: </PRE>
        !           146: <P>
        !           147: When you are done with a query result then call this to clean up
        !           148: <PRE>
        !           149: extern BOOL HTSQL_freeResult (MYSQL_RES * me);
        !           150: </PRE>
        !           151: <PRE>
        !           152: #endif
        !           153: </PRE>
        !           154: <P>
        !           155:   <HR>
        !           156: <ADDRESS>
        !           157:   @(#) $Id: HTSQLLog.html,v 2.3 1998/05/14 02:11:04 frystyk Exp $
        !           158: </ADDRESS>
        !           159: </BODY></HTML>

Webmaster