r1639: Initial revision
[clsql.git] / interfaces / mysql / clsql-mysql.c
1 /****************************************************************************
2  * FILE IDENTIFICATION
3  *
4  *   Name:          mysql-helper.cl
5  *   Purpose:       Helper functions for mysql.cl to handle 64-bit parts of API
6  *   Programmer:    Kevin M. Rosenberg
7  *   Date Started:  Mar 2002
8  *
9  * $Id: clsql-mysql.c,v 1.1 2002/03/23 14:04:52 kevin Exp $
10  *
11  * This file, part of CLSQL, is Copyright (c) 2002 by Kevin M. Rosenberg
12  *
13  * CLSQL users are granted the rights to distribute and use this software
14  * as governed by the terms of the Lisp Lesser GNU Public License
15  * (http://opensource.franz.com/preamble.html), also known as the LLGPL.
16  ***************************************************************************/
17
18 #ifdef WIN32
19 #include <windows.h>
20
21 BOOL WINAPI DllEntryPoint(HINSTANCE hinstdll, DWORD fdwReason,
22                           LPVOID lpvReserved)
23 {
24         return 1;
25 }
26        
27 #define DLLEXPORT __declspec(dllexport)
28
29 #else
30 #define DLLEXPORT 
31 #endif
32
33
34 #include <mysql.h>
35
36 /* Need to assemble a 64-bit integer to send to MySQL */
37 DLLEXPORT
38 void
39 clsql_mysql_data_seek (MYSQL_RES* res, unsigned int offset_high32,
40                        unsigned int offset_low32)
41 {
42   my_ulonglong offset;
43
44   offset = offset_high32;
45   offset = offset << 32;
46   offset += offset_low32;
47   
48   mysql_data_seek (res, offset);
49 }
50
51 /* The following functions are used to return 64-bit integers to Lisp.
52    They return the 32-bit low part and store in upper 32-bits in a 
53    located sent via a pointer */
54
55 const unsigned int bitmask_32bits = 0xFFFFFFFF;
56
57 #define lower_32bits(int64) ((unsigned int) int64 & bitmask_32bits)
58 #define upper_32bits(int64) ((unsigned int) (int64 >> 32))
59
60 DLLEXPORT
61 unsigned int
62 clsql_mysql_num_rows (MYSQL_RES* res, unsigned int* pHigh32)
63 {
64   my_ulonglong nRows = mysql_num_rows (res);
65   *pHigh32 = upper_32bits(nRows);
66   return lower_32bits(nRows);
67 }
68
69 DLLEXPORT
70 unsigned int
71 clsql_mysql_affected_rows (MYSQL* res, unsigned int* pHigh32)
72 {
73   my_ulonglong nAffected = mysql_affected_rows (res);
74   *pHigh32 = upper_32bits(nAffected);
75   return lower_32bits(nAffected);
76 }
77
78 DLLEXPORT
79 unsigned int
80 clsql_mysql_insert_id (MYSQL* mysql, unsigned int* pHigh32)
81 {
82   my_ulonglong insert_id = mysql_insert_id (mysql);
83   *pHigh32 = upper_32bits(insert_id);
84   return lower_32bits(insert_id);
85 }
86
87
88
89   
90