1
/************************************************************************************
2
TerraLib - a library for developing GIS applications.
3
Copyright � 2001-2004 INPE and Tecgraf/PUC-Rio.
5
This code is part of the TerraLib library.
6
This library is free software; you can redistribute it and/or
7
modify it under the terms of the GNU Lesser General Public
8
License as published by the Free Software Foundation; either
9
version 2.1 of the License, or (at your option) any later version.
11
You should have received a copy of the GNU Lesser General Public
12
License along with this library.
14
The authors reassure the license terms regarding the warranties.
15
They specifically disclaim any warranties, including, but not limited to,
16
the implied warranties of merchantability and fitness for a particular purpose.
17
The library provided hereunder is on an "as is" basis, and the authors have no
18
obligation to provide maintenance, support, updates, enhancements, or modifications.
19
In no event shall INPE and Tecgraf / PUC-Rio be held liable to any party for direct,
20
indirect, special, incidental, or consequential damages arising out of the use
21
of this library and its documentation.
22
*************************************************************************************/
25
This file shows an example of how to import a DBF table as
26
an attribute table in a TerraLib database. This attribute
27
table will be registered in the database as an external table.
32
#include <TeDatabase.h>
33
#include <TeImportExport.h>
38
// Database server parameters
39
string host = "localhost";
40
string dbname = "TerraTeste";
44
// Connect to the database
45
TeDatabase* db = new TeMySQL();
46
if (!db->connect(host, user, password, dbname))
48
cout << "Error: " << db->errorMessage() << endl << endl;
49
cout << "Press Enter\n";
53
// Import the dbf file
54
string filename = "../data/SOCEC.dbf";
55
if (db->tableExist("SOCEC"))
57
cout << "There is already a table named \"SOCEC\" in the TerraLib database!\n\n";
58
cout << "Press Enter\n";
63
if (TeImportDBFTable(filename,db))
64
cout << "The dbf file \"SOCEC.dbf\" was imported successfully as an external table in the TerraLib database!\n\n";
68
cout << "Fail to import the dbf file!\n";
69
cout << "Press Enter\n";
74
TeAttrTableVector tableVec;
75
if (db->getAttrTables(tableVec, TeAttrExternal))
77
cout << "External tables in the database: " << tableVec.size() << endl;
78
TeAttrTableVector::iterator it = tableVec.begin();
79
while (it != tableVec.end())
81
cout << (*it).name() << " primary key column: " << (*it).uniqueName() << endl << endl;
87
cout << "Press Enter\n";