User Guide
cc -o my_app my_app.c -L/usr/local/Hughes/lib
-lmsql
cc -o my_app my_app.c -L/usr/local/Hughes/lib
-lmsql -lsocket -lnsl
The API has changed slightly from the original mSQL API.
Please ensure that you check the semantics and syntax of the functions
before you use them.
char * host ;
If the connection is made to the server, an integer identifier is returned to the calling function. This value is used as a handle for all other calls to the mSQL API. The value returned is in fact the socket descriptor for the connection. By calling msqlConnect() more than once and assigning the returned values to separate variables, connections to multiple database servers can be maintained simultaneously.
In previous versions
of mSQL, the MSQL_HOST environment variable could be used to specify a
target machine if the host parameter was NULL. This is no longer the case.
It should also be noted that communicating with the server via UNIX sockets
rather than TCP/IP sockets increases performance greatly. If you are communicating
with a server on the same machine as the client software you should always
specify NULL as the hostname. Using "localhost" or the name of the local
machine will force the use of TCP/IP and degrade performance.
msqlSelectDB()
int sock ;
char * dbName ;
msqlQuery()
int sock ;
char * query ;
Queries are sent to the engine over the connection associated with sock as plain text strings using msqlQuery(). As with previous releases of mSQL, a returned value of -1 indicates an error and msqlErrMsg will be updated to contain a valid error message. If the query generates output from the engine, such as a SELECT statement, the data is buffered in the API waiting for the application to retrieve it. If the application submits another query before it retrieves the data using msqlStoreResult(), the buffer will be overwritten by any data generated by the new query.
In previous versions
of mSQL, the return value of msqlQuery() was either -1 (indicating an error)
or 0 (indicating success). mSQL 2 adds to these semantics by providing
more information back to the client application via the return code. If
the return code is greater than 0, not only does it imply success, it also
indicates the number of rows "touched" by the query (i.e. the number of
rows returned by a SELECT, the number of rows modified by an update, or
the number of rows removed by a delete).
msqlStoreResult()
msqlFreeResult()
m_result * result ;
msqlFetchRow()
m_result * result ;
msqlDataSeek()
m_result * result ;
int pos ;
msqlNumRows()
m_result * result ;
If no data is
matched by a select query, msqlNumRows() will indicate that the
result table has 0 rows. Note: earlier versions of mSQL returned a NULL
result handle if no data was found. This has been simplified and made more
intuitive by returning a result handle with 0 rows of result data.
msqlFetchField()
m_result * result ;
char * name ; /* name of field */
char * table ; /* name of table */
int type ; /* data type of field */
int length , /* length in bytes of field */
int flags ; /* attribute flags */
} m_field;
msqlFieldSeek()
m_result * result ;
int pos ;
msqlNumFields()
m_result * result ;
msqlClose()
int sock ;
int sock ;
msqlListTables()
int sock ;
msqlListFields()
int sock ;
char * tableName;
msqlListIndex()
int sock ;
char * tableName;
char * index;
An example of the data returned by msqlListIndex is shown
below. The example shows the result of calling msqlListIndex on a compound
index. The index is defined as an AVL Tree index and is based on the values
of the fields first_name and last_name. Currently the only valid index
type is ?avl? signifying a memory mapped AVL tree index. Further index
schemes will be added to mSQL in the future.
avl
first_name
last_name
char * msqltime;
msqlUnixTimeToTime()
time_t clock;
msqlDateToUnixTime()
char * msqldate;
msqlUnixTimeToDate()
time_t clock;
date = msqlUnixTimeToDate(
clock );
char * time1,
msqlDateOffset()
char * date;
int dOff,
mOff,
yOff
today = msqlUnixTimeToDate( clock );
tomorrow = msqlDateOffset(
today , 1 , 0 , 0 );
char * time1,
msqlDiffDates()
char * date1,
char * file;
Inst_Dir/new.conf
new