summaryrefslogtreecommitdiff
path: root/src/db.h
blob: e8d391601793a675871e19fb7d35b69c1843cf99 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/***************************************************************************
 *            db.h
 *
 *  Copyright  2005  Ian McIntosh
 *  ian_mcintosh@linuxadvocate.org
 ****************************************************************************/

/*
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Library General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

#ifndef _DB_H_
#define _DB_H_

#include <mysql.h>

typedef struct db_connection {
	MYSQL *m_pMySQLConnection;
	gchar* m_pzHost;
	gchar* m_pzUserName;
	gchar* m_pzPassword;
	gchar* m_pzDatabase;
} db_connection_t;

typedef MYSQL_RES db_resultset_t;
typedef MYSQL_ROW db_row_t;

#define DB_ROADS_TABLENAME 		("Road")
#define DB_FEATURES_TABLENAME	("Feature")

#include "map.h"
#include "layers.h"
#include "pointstring.h"

void db_create_tables(void);

void db_init(void);
void db_deinit(void);

// connect
gboolean db_connect(const gchar* pzHost, const gchar* pzUserName, const gchar* pzPassword, const gchar* pzDatabase);
const gchar* db_get_connection_info(void);

// utility
gboolean db_is_empty(void);

gboolean db_insert_roadname(const gchar* pszName, gint nSuffixID, gint* pnReturnID);

//~ gboolean db_create_points_db(const gchar* name);

//~ // insert
//~ gboolean db_road_insert(db_connection_t* pConnection, gint nLayerType, GPtrArray* pPoints, gint* pReturnID);
//~ gboolean db_point_insert(db_connection_t* pConnection, gint nPointSetID, mappoint_t* pPoint, gint* pReturnID);

//~ // load
//~ gboolean db_load_geometry(db_connection_t* pConnection, maprect_t* pRect, layer_t* pLayer, gint nNumLayers); //, geometryset_t* pGeometrySet);
//~ gboolean db_pointset_get_list(db_connection_t* pConnection, GPtrArray* pPointSet);

gboolean db_query(const gchar* pszSQL, db_resultset_t** ppResultSet);
db_row_t db_fetch_row(db_resultset_t* pResultSet);
void db_free_result(db_resultset_t* pResultSet);
gint db_get_last_insert_id(void);

void db_begin_thread(void);
void db_end_thread(void);

gchar* db_make_escaped_string(const gchar* pszString);
void db_free_escaped_string(gchar* pszString);

void db_parse_wkb_linestring(const gint8* data, GPtrArray* pPointsArray, gboolean (*callback_alloc_point)(mappoint_t**));

void db_enable_keys(void);
void db_disable_keys(void);

gboolean db_insert_city(const gchar* pszName, gint nStateID, gint* pnReturnCityID);
gboolean db_insert_road(gint nRoadNameID, gint nLayerType,
							gint nAddressLeftStart, gint nAddressLeftEnd,
							gint nAddressRightStart, gint nAddressRightEnd,
							gint nCityLeftID, gint nCityRightID,
							const gchar* pszZIPCodeLeft, const gchar* pszZIPCodeRight,
							GPtrArray* pPointsArray, gint* pReturnID);

gboolean db_city_get_id(const gchar* pszName, gint nStateID, gint* pnReturnID);
gboolean db_state_get_id(const gchar* pszName, gint* pnReturnID);

void db_lock(void);
void db_unlock(void);

#endif