This file is indexed.

/usr/include/terralib/kernel/TeDatabase.h is in libterralib-dev 4.0.0-5ubuntu1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

   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
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
/************************************************************************************
TerraLib - a library for developing GIS applications.
Copyright � 2001-2007 INPE and Tecgraf/PUC-Rio.

This code is part of the TerraLib library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

You should have received a copy of the GNU Lesser General Public
License along with this library.

The authors reassure the license terms regarding the warranties.
They specifically disclaim any warranties, including, but not limited to,
the implied warranties of merchantability and fitness for a particular purpose.
The library provided hereunder is on an "as is" basis, and the authors have no
obligation to provide maintenance, support, updates, enhancements, or modifications.
In no event shall INPE and Tecgraf / PUC-Rio be held liable to any party for direct,
indirect, special, incidental, or consequential damages arising out of the use
of this library and its documentation.
*************************************************************************************/
/*! \file TeDatabase.h
    \brief This file contains structures and definitions about database support in TerraLib
*/
#ifndef  __TERRALIB_INTERNAL_DATABASE_H
#define  __TERRALIB_INTERNAL_DATABASE_H

#ifdef WIN32 
#pragma warning ( disable: 4786 ) 
#endif

#include "TeDefines.h"
#include "TeDataTypes.h"
#include "TeTable.h"
#include "TeGeometry.h"
#include "TeStatistics.h"
#include "TeProject.h"
#include "TeRaster.h"
#include "TeView.h"
#include "TeVisual.h"
#include "TeMetaModelCache.h"
#include "TeSharedPtr.h"
#include "TeDatabaseIndex.h"

class TeLayer;
class TeDatabaseFactoryParams;
class TeRasterParams;
class TeTheme;
class TeTime;
class TeTimeInterval;

#include <set>
using namespace std;

          
/*! \enum TeCursorLocation
	Location of a cursor on record set
 */
enum TeCursorLocation { TeCLIENTESIDE, TeSERVERSIDE };

/*! \enum TeCursorType
	Type of cursor on record set
 */
enum TeCursorType { TeUNIDIRECTIONAL, TeBIDIRECTIONAL, TeRANDOMACCESS };

/*! \enum TeCursorEditType
	Type of edition on record set cursor
 */
enum TeCursorEditType { TeREADONLY, TeREADWRITE };

/*! \enum TeCursorDataType
	Type of edition on record set cursor
 */
enum TeCursorDataType { TeBINARYCURSOR, TeTEXTCURSOR };


/*! \enum TeSpatialIndexType
	Type of spatial index
 */
enum TeSpatialIndexType {TeRTREE, TeQUADTREE};

//! A vector of objects identifications (object_id)
typedef vector<string>				TeKeys;

//! A Map of objects identifications (object_id) to a distance value
typedef map<string, double>			TeKeysToDist;

//! A Vector of pointers to TeGeometry 
typedef vector<TeGeometry*> TeGeometryVect;

//! A Map of the objects identifications to a set of statistical values
typedef map<string, TeStatisticsDimensionVect>  TeObjectStatistics;


class TeDatabasePortal;


//! An abstract database class
/*!
	Instances of this classes represent connections
	to a database server. It includes the host name, 
	user name and password parameters of the connection.
	It should be implemented by the drivers to specific
	database servers as: MySQL, Ado, PostgreSQL or any
	other server to be used in TerraLib applications.
	When possible, default implementations using ANSI SQL
	are provided. 
	Methods that rely on special features of the derived
	driver are left as purely virtual.

  \sa
  TeTheme, TeView, TeLayer, TeAttribute
*/
class TL_DLL TeDatabase 
{
public: 
	//! Empty constructor
	TeDatabase();

	//! Destructor
	virtual ~TeDatabase();

	//! Assignment operator
	virtual TeDatabase& operator=(const TeDatabase& other);

	//! Operator ==
	virtual bool operator== (const TeDatabase& other) const
	{	
		if (dbmsName_ != other.dbmsName_ ||
			database_ != other.database_ ||
			host_  != other.host_ ||
			user_ != other.user_ )
			return false;
		return true;
	}
	/** @name Members
	*  Methods to access class private members
	*/
	//@{		
	//! Returns the error message from the server
	virtual string errorMessage ()
	{ return errorMessage_; }

	//! Returns the error number from the server
	virtual int	errorNum ()
	{	return errorNumber_; }

	//! Return the user name of the connection opened
	string	user () 
	{ return user_; }

	//! Set the current user name to view
	void user(string value) { user_=value;}

	//! Returns the host name of the connection opened
	string	host () 
	{ return host_; }

	//! Returns the user's password of the connection opened
	string	password () 
	{ return password_; }

	//! Returns the database name of the connection opened
	string	databaseName () 
	{ return database_; }
	
	//! Returns the Database Management System name
	string	dbmsName () 
	{ return dbmsName_; }

	//! Returns the port number of the connection opened
	int	portNumber () 
	{ return portNumber_; }

	//! Returns the  map of layers in the database
	TeLayerMap&	layerMap () 
	{ return metaModel_->layerMap(); }

	//! Returns the  map of views in the database
	TeViewMap&	viewMap () 
	{ return metaModel_->viewMap(); }

	//! Returns the  map of themes in the database
	TeThemeMap&	themeMap () 
	{ return metaModel_->themeMap(); }

	//! Returns the map of invalid themes in the database
	TeThemeMap&	invalidThemeMap() 
	{ return metaModel_->invalidThemeMap(); }

	//! Returns the  map of projects in the database
	TeProjectMap&  projectMap ()
   { return metaModel_->projectMap(); }

	//! Returns the  map of legends in the database
	TeLegendEntryMap& legendMap () 
	{ return metaModel_->legendMap(); }

	//! Returns the set of relations between tables
	multiset<int>& relationMSet () 
	{ return metaModel_->relationMSet(); }

	//! Clears structures in memory (legendMap, layerMap, viewMap...) used to optimize database access
	virtual void clear();

	//@}

	/** @name Database
	*  Methods related to database and connection creation. 
	*  These methods return TRUE when the operation was successfull.
	*  Otherwise return FALSE and when possible an error message is captured.
	*/
	//@{	
	//! Creates a new database and open a connection to it
	virtual bool newDatabase(const string& database, const string& user, const string& password, const string& host, const int &port=-1, bool terralibModel=true, const std::string& characterSet = "") = 0;
	
	//! Opens a connection to a database server passing all parameters needed
	virtual bool connect (const string& host, const string& user, const string& password, const string& database, int port = -1) = 0;

	//! Show the server databases (only for MySQL, Oracle and PostgreSQL)
	virtual bool showDatabases (const string& /* host */, const string& /* user */, const string& /* password */, vector<string>& /* dbNames */ , int /* port */ = -1)
	{ return true; }

	//! Opens a connection without parameters. When possible, should be implemented by the derived classes 
	virtual bool connect (const string&  = "") { return false; };

	//! Check if there is an opened connection
	bool isConnected () 
	{ return isConnected_; }

	//! Closes the connection
	virtual void close() = 0;

	//! Returns a string that the describes the parameters of the database connected
	/*
		The expected return value is similar to: dbms_server;hostname;portnumber;databasename;user;password
	*/
	virtual string getDatabaseDescription();
	
  
  /**
   *  This is for TeFactory compatibility ( Invalid TeDatabaseFactory
   *  requests will try to create an default object using this function ).
   */
  static TeDatabase* DefaultObject( const TeDatabaseFactoryParams& )
  {
    std::cout << std::endl << "TeDatabase::DefaultObject - " <<
      " - Trying to create an invalid TeDatabase default object." <<
      std::endl;
    throw;
      
    return 0;
  };
  
	//@}

	/** @name Tables
	  Methods related to table manipulation.
		\note refer to data model documentation in order to understand the meanning of 
		each tables and its fields
	*/
	//@{	

	//! Returns a list of tables in a database
	virtual bool listTables(vector<string>& /* tableList */) { return false; }

	//! Verifies if a table exist in the database
	virtual bool tableExist(const string& table) = 0;
	
	//! Verifies if a table has a column
	virtual bool columnExist(const string& table, const string& column, TeAttribute& attr) = 0;

	//! Update a column
	virtual bool allowEmptyString(const string& /* tableName */, const string& /* column */) { return false; }

	//! Verifies and modifies the column names of the table. It returns if the table was modified  
	virtual bool validTable (TeTable& table);

	//! Return the name of an attribute table given its identifier
	string getTableName(int tableId);

	//! Return a valid name for a table from a initial one
	string getNewTableName(const string& n);

	//! Concatenate field values
	/*!
      \param fNamesVec vector containing the fields to be concatenated
	*/
	virtual string getConcatFieldsExpression(const vector<string>& fNamesVec);

	//! Creates a table
	/*!
      \param table table name
      \param attr table list of attributes
	 */
	virtual bool createTable(const string& table, TeAttributeList &attr) = 0;

	//! Deletes a table. Do not allow the deletion of model tables
	 virtual bool deleteTable (const string& table);

	//! Adds a column to a table
	/*!
      \param table table name
      \param rep representation of the column being created
	*/
	virtual bool addColumn (const string& table, TeAttributeRep &rep) = 0;

	//! Deletes a column to a table
	/*!
      \param table table name
      \param colName name of the column being deleted
	*/
	virtual bool deleteColumn (const string& table, const string& colName);
	
	//! Creates a reationship between two tables
	/*!
      \param relName relationship name
      \param table table that will receive the foreign key
	  \param fieldName column that will be foreign key
	  \param relatedTable table that exports the foreign key
	  \param relatedField field that will the exported foreign key
	  \param cascadeDeletion flag that indicates if the deletion should be propagated
	*/
	virtual bool createRelation (const string& relName, const string& table, const string& fieldName, 
						const string& relatedTable, const string& relatedField, bool cascadeDeletion) = 0;

	//! Checks if a relation exist
	/*!
      \param tableName table where the relashionship exists
	  \param relName relationship name
	*/
	virtual TeDBRelationType existRelation(const string& tableName, const string& relName) = 0;

	//! Removes a relation exist
	/*!
	  \param name relationship name
      \param table table where the relashionship exists
	  \return TRUE if succeed and FALSE otherwise
	*/
	virtual bool deleteRelation(const string& name, const string& table);

	//@}
	
	/** @name Query
	*  Methods related to query the database
	*/
	//@{	
	//! Executes a SQL command that doesnt return a record set. Tipically a data definition comand
	virtual bool execute ( const string &sql) = 0;

	//! Returns a database portal.
	/*!
		A database portal is used to submit queries to the database and to navigate over the
		resulting record set
	*/
	virtual TeDatabasePortal* getPortal () = 0;

	//! Get the values that satisfy the query 
	virtual bool inClauseValues(const string& query , const string& attribute, vector<string>& inClauseVector);

	//@}

	/** @name  Data Model
		 Methods that create the database model suggested in TerraLib. 
		 Classes in TerraLib materialize the DataModel suggested.
	*/
	//@{
	//! Creates the entire TerraLib conceptual model.
	/*
      \param withIntegrity flag that indicates that the referencial integrity should be implemented.
	  \param createIndex flag that indicate that the indexes should be created
	*/
	virtual bool createConceptualModel(bool withIntegrity = true, bool newDatabase = true, bool createIndex = true);

	//! Creates the referencial integrity of the conceptual model
	virtual bool defineIntegrity(void);

	//! Create the indexes for the tables in the conceptual model
	virtual bool createIndex(const string& tableName, const string& indexName, const string& columnsName);

	//! Delete the index from tables in the conceptual model
	virtual bool deleteIndex(const string& tableName, const string& indexName);

	//! Return a TeDatabaseIndex vector from a table
	virtual bool getIndexesFromTable(const string& tableName, std::vector<TeDatabaseIndex>& vecIndexes);

	//! Creates a table to store version database information 
	virtual bool createDatabaseTable(); 
	
	//! Creates a table to store projectinon information
	virtual bool createProjectionTable();

	//! Creates a table to store Layers information
	virtual bool createLayerTable ();

	//! Creates a table to store Representations information
	virtual bool createRepresentationTable ();

	//! Creates a table to store Views information
	virtual bool createViewTable ();

	//! Creates a table to store Themes information
	virtual bool createThemeTable ();

	//! Creates a table to store the groupings associated with a theme
	virtual bool createGroupingTable();

	//! Creates a table to store information about the attribute tables used by a theme
	virtual bool createThemeTablesTable();

	//! Creates a table to store legends
	virtual bool createLegendTable ();

	//! Creates a table to store visual definitions
	virtual bool createVisualTable();

	//! Creates a table to store raster visual definitions
	virtual bool createVisualRasterTable();

	//! Creates a table to store information about the non-spatial tables associated to this layer
	virtual bool createLayerTableTable();

	//! Creates a table to store information about the external tables related to non-spatial tables of layers
	virtual bool createTablesRelationTable();

	//! Creates a table to store information about projects: an structure that groups views
	virtual bool createProjectTable();

	//! Creates a table to store the relation between project/views information
	virtual bool createProjectViewTable();
	//@}

	/** @name  Project
		 Methods related to the manipulation of projects
	*/
	//@{
	//! Load information about all projects stored in the database
	virtual bool loadProjectSet(); 

	//! Load information about a particular project
	virtual bool loadProject(TeProject* project); 
	
	//! Insert information about a project
	virtual bool insertProject(TeProject *project) = 0;
	
	//! Update information about a project
	virtual bool updateProject(TeProject *project);	

	//! Delete a project from the database
	virtual bool deleteProject(int projectId);	

	//! Insert a project/view relation
	virtual bool insertProjectViewRel(int projectId, int viewId);

	//! Deletes a project/view relation
	virtual bool deleteProjectViewRel(int projectId, int viewId);

	//! Check whether a given project already exists in the database (it is not case sensitive).
	virtual bool projectExist(const string& projectName);
	//@}

	/** @name  Geometries
		 Methods that create tables that store the spatial data
	*/
	//@{

	//! Creates a table for a polygon geometries
	virtual bool createPolygonGeometry (const string& tableName);

	//! Creates a table for line geometries
	virtual bool createLineGeometry (const string& tableName);

	//! Creates a table for point geometries
	virtual bool createPointGeometry (const string& tableName);

	//! Creates a table for cell geometries
	virtual bool createCellGeometry (const string& tableName);
 
	//! Creates a table for a text geometries
	virtual bool createTextGeometry (const string& tableName);

	//! Creates a table for a arc geometries
	virtual bool createArcGeometry (const string& tableName);

	//! Creates a table for a node geometries
	virtual bool createNodeGeometry (const string& tableName);

	//! Creates a table to store raster representations of objects
	virtual bool createRasterGeometry(const string& tableName);

	//! Creates a table to store information about raster representation
	virtual bool createRasterMetadataTable(const string& tableName);
	
    //! Creates a table for raster geometries
	virtual bool createRasterTable (const string& tableName);

	//! Creates a table to store information about objects in a theme
	virtual bool createCollectionTable(const string& tableName);
	//@}

	/** @name Non-spatial tables
	*  Retrieving/Inserting/Modifying generic tables in the database. 
	*/
	//@{
	//! Retrieves information about some tables
	/*
		\param atts returning vector of tables information 
		\param attType type of the tables that are being looked for (optional)
		\return TRUE if any table was found and FALSE otherwise
	*/
	virtual bool getAttrTables(TeAttrTableVector& atts, TeAttrTableType attType = TeAllAttrTypes);

	//! Inserts information about a link to an external table
	/*
		\param tableId table identification (from te_layer_table)
		\param tField link column name of the static table
		\param eTable name of the external table
		\param eField name of the link column of the related table
		\param relId returns the identification of the relation
	*/
	virtual bool insertRelationInfo(const int tableId, const string& tField,
									const string& rTable, const string& rField, int& relId) = 0;

	//! Inserts information about an attribute table
	virtual bool insertTableInfo (int layerId, TeTable &table, const string& user="") = 0;

	//! Updates information about an attribute table
	virtual bool updateTableInfo (int layerId, TeTable &table, const string user="");

	//! Retrieves the metainformation about an attribute table
	virtual bool loadTableInfo(TeTable& table);

	//! Saves a table and its contents in the database
	virtual bool insertTable(TeTable &table);

	//! Alter a property of a table 
	virtual bool alterTable(const string& tableName, TeAttributeRep& rep, const string& oldColName="");

	//! Alter the table name 
	virtual bool alterTable(const string& oldTableName, const string& newTablename);

	//! Saves a large binary objects (BLOB) in a row table 
	virtual bool insertBlob (const string& tableName, const string& columnBlob, TeAttributeRep& columnId, const string& valueId, unsigned char* data, int size);

	//! Saves a large binary objects (BLOB) in a row table 
	virtual bool insertBlob (const string& tableName, const string& columnBlob, TeAttributeRep& columnId, const string& valueId, const string& fileName);

	//! Saves a large binary objects (BLOB) in a row table 
	virtual bool insertBlob (const string& tableName, const string& columnBlob, const string& whereClause, unsigned char* data, int size) = 0;

	//! Saves a large binary objects (BLOB) in a row table 
	virtual bool insertBlob (const string& tableName, const string& columnBlob, const string& whereClause, const string& fileName);
	
	//! Updates a table and its contents in the database
	virtual bool updateTable	(TeTable &table);

	//! Retrieves a table and its contents from the database
	virtual bool loadTable		(const string& tableName, TeTable &table);

	//! Retrieves a table (or part of it) accordingly to a criteria written in SQL
	virtual bool selectTable	(const string& tableName, const string& criteria, TeTable &table);

	//!	Deletes all tables, of a particular type, associated to a layer
	virtual bool deleteLayerTable	(int layerId, TeAttrTableType ttype = TeAttrStatic);
	//@}

	/** @name Projection
	*  Accessing/Inserting/Modifying projection information into the database. 
	*/
	//@{ 	

	//! Insert information about a geographical projection
	virtual bool insertProjection (TeProjection *proj) = 0;	

	//! Updates information about a geographical projection
	virtual bool updateProjection (TeProjection *proj);	

	//! Retrieves information about a geographical projection identified by its database id
	virtual TeProjection* loadProjection (int id);
	//@}

	/** @name Layers
	*  Retrieving/Inserting/Modifying/Deleting layers in the database. 
	*/
	//@{ 
	//! Insert information about a layer
	virtual bool insertLayer	(TeLayer *layer) = 0;
	
	//! Update information about a layer
	virtual bool updateLayer	(TeLayer *layer);	

	//! Load information about all layers stored in the database
	/*
		\param loadAttrList  indicates if the attribute list of each attribute table should be loaded
	*/
	virtual bool loadLayerSet	(const bool& loadAttrList = true);

	//! Load information about a particular layer 
	/*
		\param layer		a pointer to a layer that will be loaded from database
		\param loadAttrList indicates if the attribute list of each attribute table should be loaded
	*/
	virtual bool loadLayer		(TeLayer* layer, const bool& loadAttrList = true);

	//! Load layer tables 
	/*
		\param layer		a pointer to a layer whose attribute table will be loaded from database
		\param loadAttrList indicates if the attribute list of each attribute table should be loaded
	*/
	virtual bool loadLayerTable (TeLayer* layer, const bool& loadAttrList = true);

	//! Delete a particular layer passing its id
	virtual bool deleteLayer	(int layerId);

	//! Check if a particular layer exists (passing its id)
	virtual bool layerExist		(int id);

	//! Check if a particular layer exists (passing its name)
	virtual bool layerExist		(string layerName);

	//! Checks whether a given layer name is valid or already exists in the database
	/*!
		\param n		layer name to be checked
		\return the modified valid layer name
	*/	
	virtual string getNewLayerName(const string& n);
	//@}

	/** @name Representation
	*  Retrieving/Inserting/Modifying/Deleting representations in the database. 
	*/
	//@{ 
	//! Inserts information about a geometrical representation
	virtual bool insertRepresentation (int layerId, TeRepresentation& rep) = 0;	

	//! Updates information about a geometrical representation
	virtual bool updateRepresentation (int layerId, TeRepresentation& rep);	

	//! Updates the box information of a layer in the corresponding metadata table
	virtual bool updateLayerBox(TeLayer* layer);

	//@}

	/** @name Raster Tables
	*  Retrieving/Inserting/Modifying/Deleting raster representations in the database. 
	*/
	//@{ 
	//! Inserts information about a raster geometry associated to an object
	/*!
		\param tableName name of the table that stores the raster representation
		\param par raster parameters 
		\param objectId identification of the object associated to the raster geometry
	*/
	virtual bool insertRasterGeometry(const string& tableName, TeRasterParams& par, const string& objectId = "");

	//! Updates the information about the raster geometry associated to an object of a layer
	/*!
		\param layerId layer unique database identification
		\param par raster parameters 
		\param objectId identification of the object associated to the raster geometry
	*/
	virtual bool updateRasterRepresentation(int layerId, TeRasterParams& par, const string& objectId="");

	//! Returns the name of the table where the raster geometry associated to an object of a leyr
	/*!
		\param layerId layer unique database identification
		\param objectId identification of the object associated to the raster geometry
	*/
	virtual string getRasterTable(int layerId, const string& objectId);
	
	//! Inserts metadata information about a particular raster geometry
	/*!
		\param tableName name of the table that stores the metadata
		\param geomId  geometry unique database identification
		\param par raster parameters 
	*/
	virtual bool insertRasterMetadata (const string& tableName, int geomId, TeRasterParams& par);

	//! Updates metadata information about a particular raster geometry
	/*!
		\param tableName name of the table that stores the metadata
		\param geomId  geometry unique database identification
		\param par raster parameters 

	*/	
	virtual bool updateRasterMetadata (const string& tableName, int geomId, TeRasterParams& par);
	//@}
	/** @name Views
	*  Retrieving/Inserting/Modifying/Deleting views in the database. 
	*/
	//@{ 
	//! Inserts a view
	virtual bool insertView (TeView *view) = 0;	

	//! Updates a view
	virtual bool updateView (TeView *view);	

	//! Loads a set of views belonging to a user
	/*
		\param user			 the user name 
		\param loadAttrList  indicates if the attribute list of each attribute table should be loaded
		\param visualClass  identifies which concrete class od visual should be instantiated.
		The default is TerraLib basic visual.
	*/
	virtual bool loadViewSet (const string& user, const bool& loadAttrList = true, const string& visualClass="tevisual");

	//! Load a view
	/*
		\param view			a pointer to a view that will be loaded from database
		\param loadAttrList indicates if the attribute list of each attribute table should be loaded
		\param visualClass  identifies which concrete class od visual should be instantiated.
		The default is TerraLib basic visual.
	*/
	virtual bool loadView (TeView* view, const bool& loadAttrList = true, const string& visualClass="tevisual");

	//! Delete a view
	virtual bool deleteView (int viewId);

	//! Recursive inserting of a view tree.
	virtual bool insertViewTree (TeViewTree *tree) = 0;	

	//! Recursive load view tree.
	/*
		\param view			a pointer to a view that will be loaded from database
		\param id			a specific theme or viewtree id of this view that will be loaded from database
		\param loadAttrList indicates if the attribute list of each attribute table should be loaded
		\param visualClass  identifies which concrete class od visual should be instantiated.
		The default is TerraLib basic visual.
	*/
	virtual TeViewTree* loadViewTree(TeView* view, int id, const bool& loadAttrList = true, const string& visualClass = "tevisual");

	//! Recusive updating of a view tree.
	virtual bool updateViewTree (TeViewTree *tree);
	
	//! Check whether a given view already exists in the database
	virtual bool viewExist(string viewName);

	//@}

	/** @name Themes
	*  Retrieving/Inserting/Modifying/Deleting themes and group of themes in the database. 
	*/
	//@{ 
	//! Inserts a group of themes in the database
	virtual bool insertThemeGroup	(TeViewTree* tree) = 0;

	//! Inserts an abstract theme in the database.
	virtual bool insertTheme		(TeAbstractTheme *theme) = 0; 	

	//! Updates an asbtract theme in the database
	virtual bool updateTheme		(TeAbstractTheme *theme);

	//! Loads a theme from the database
	virtual bool loadTheme			(TeAbstractTheme *theme, const bool& loadAttrList = true, const string& visualClass = "tevisual");
	
	//! Loads several themes from the database. Created for otimization.
	virtual bool loadThemes			(std::vector<TeAbstractTheme*>& vecThemes, const bool& loadAttrList, const std::string& userName, const bool& loadMetadata = true, const string& visualType = "tevisual");

	//! Loads several external themes from the database. Created for otimization.
	virtual bool loadExternalThemes	(std::vector<TeAbstractTheme*>& vecExternalThemes);

	//! Loads all attribute tables of a theme
	virtual bool loadThemeTable		(TeTheme* theme, const bool& loadAttrList = true);

	//! Erases the theme group identified by themeId
	virtual bool deleteThemeGroup	(int themeId);

	//! Erases the theme identified by themeId
	virtual bool deleteTheme		(int themeId);

	//! Erases the legends of a theme identified by themeId
	virtual bool deleteLegend		(int themeId);
	
	//! Inserts information about a table used by a theme 
	bool insertThemeTable(TeTheme *theme, TeTable& inputTable);

	//! Inserts information about a table used by a theme 
	virtual bool insertThemeTable	(int themeId, int tableId, int relationId, int tableOrder) = 0; 

	//! Updates  information about the tables used by a theme 
	virtual bool updateThemeTable	(TeTheme *theme);
	
	//! Removes a table from the theme
	bool removeThemeTable(TeTheme *theme, int tableOrder);

	//! Inserts information about a grouping used in a theme
	virtual bool insertGrouping (int themeId, const TeGrouping& grouping);

	//! Updates information about a grouping used in a theme
	virtual bool updateGrouping (int themeId, const TeGrouping& grouping);

	//! Generates the label position (x,y) to each object of a theme or of a particular object
	virtual bool generateLabelPositions(TeTheme *theme, const std::string& objectId = "");

	//! Check whether a given theme already exists in the database
	virtual bool themeExist(string themeName);
	
	//! Check whether a given theme from a specific view already exists in the database
	virtual bool themeExist(const std::string &viewName, const std::string &userName, const std::string &themeName);

	//! Checks whether a given theme name is valid or already exists in the database
	/*!
		\param n		theme name to be checked
		\return the modified valid theme name
	*/	
	virtual string getNewThemeName(const string& n);

	//@}

	/** @name Legend
	*  Retrieving/Inserting/Modifying/Deleting legends in the database. 
	*/
	//@{ 
	//! Inserts legend in the database
	virtual bool insertLegend	(TeLegendEntry *legend) = 0;	
	//! Updates legend entries in the database
	virtual bool updateLegend	(TeLegendEntry *legend);	

	virtual bool updateLegend   (vector<TeLegendEntry>& legVec);
	virtual bool loadLegend		(TeAbstractTheme *theme, const string& visualClass = "tevisual");
	virtual bool updateVisual	(TeLegendEntry *legend);
	virtual bool updateVisual   (vector<TeLegendEntry>& legVec);
	//@}

	/** @name Polygon
	// Accessing/Inserting/Modifying polygon geometries into the database
	*/
	//@{ 
	//! Inserts a polygon set in a geometry table
	virtual bool insertPolygonSet (const string& table, TePolygonSet &ps);	

	//! Updates a polygon set in a geometry table
	virtual bool updatePolygonSet (const string& table, TePolygonSet &ps);	

	//! Returns all polygons in a table given a criteria expressed as an SQL where statement
	virtual bool selectPolygonSet (const string& table, const string& criteria, TePolygonSet &ps);

	//! Returns all polygons that represents objects of a particular theme
	virtual bool loadPolygonSet	(TeTheme* theme, TePolygonSet &ps);

	//! Returns all polygons  that represents objects of a particular geoid
	virtual bool loadPolygonSet	(const string& table, const string& geoid, TePolygonSet &ps);

	//! Returns all polygons inside a given box
	virtual bool loadPolygonSet	(const string& table, TeBox &box, TePolygonSet &ps);

	//! Returns a database portal to iterate over the polygons that are inside a given box
	/*
		\return A database portal pointer if there is any polygons inside the box
		\return A null pointer if there isn't polygons to iterate
		\note The database portal pointer should be deleted by the application
	*/
	virtual TeDatabasePortal* loadPolygonSet(const string& table, TeBox &box);

	//! Returns the first polygon that contais a given coordinate
	virtual bool locatePolygon		(const string& table, TeCoord2D &pt, TePolygon &polygon, const double& tol = 0.0);

	//! Returns the polygons that contains a give coordinate
	virtual bool locatePolygonSet   (const string& table, TeCoord2D &pt, double tol, TePolygonSet &polygons);

	//! Inserts a polygon in a geometry table
	virtual bool insertPolygon		(const string& table, TePolygon &p) = 0;	

	//! Updates a polygon in a geometry table
	virtual bool updatePolygon		(const string& table, TePolygon &p) = 0;
	//@}

	/** @name Line
	*  Accessing/Inserting/Modifying Line geometries into the database. 
	*/
	//@{ 	
	// Accessing/Inserting line geometries into the database
	virtual bool insertLineSet	(const string& table, TeLineSet &ls);	
	virtual bool updateLineSet	(const string& table,TeLineSet &ls);
	virtual bool loadLineSet	(const string& table, const string& geoid, TeLineSet &ls);
    virtual bool loadLineSet	(TeTheme* theme, TeLineSet &ls);
	virtual bool loadLineSet	(const string& table, TeBox &box, TeLineSet &linSet);
	virtual TeDatabasePortal*    loadLineSet (const string& table, TeBox &box);
	virtual bool selectLineSet	(const string& table, const string& criteria, TeLineSet &ls);

    virtual bool insertLine		(const string& table, TeLine2D &l) = 0;		
	virtual bool updateLine		(const string& table, TeLine2D &l) = 0;
	virtual bool locateLine		(const string& table, TeCoord2D &pt, TeLine2D &line, const double& tol = 0.0);
	virtual bool locateLineSet	(const string& table, TeCoord2D &pt, TeLineSet & ls, const double& tol = 0.0);

	//@}

	/** @name Point
	*  Accessing/Inserting/Modifying Point geometries into the database. 
	*/
	//@{ 	
	// Accessing/Inserting point geometries into the database
	virtual bool insertPointSet	(const string& table, TePointSet &ps);	
    virtual bool updatePointSet (const string& table, TePointSet &ps);
	virtual bool loadPointSet	(const string& table, TeBox &box, TePointSet &ps);
	virtual TeDatabasePortal* loadPointSet	(const string& table, TeBox &box);
	virtual bool loadPointSet	(const string& table, const string& geoid, TePointSet &ps);
	virtual bool loadPointSet	(TeTheme* theme, TePointSet &ps);
	virtual bool selectPointSet (const string& table, const string& criteria, TePointSet &ps);

    virtual bool insertPoint	(const string& table, TePoint &p) = 0;	
	virtual bool updatePoint	(const string& table, TePoint &p);
	virtual bool locatePoint	(const string& table, TeCoord2D &pt, TePoint &point, const double& tol = 0.0);
	virtual bool locatePointSet (const string& table, TeCoord2D &pt, TePointSet &pointSet, const double& tol=0.0);
	//@}

	/** @name Text
	*  Accessing/Inserting/Modifying Text geometries into the database. 
	*/
	//@{ 	
	// Accessing/Inserting text geometries into the database
	virtual bool insertTextSet	(const string& table, TeTextSet &ts);	
	virtual bool updateTextSet	(const string& table, TeTextSet &ts);	
	virtual bool loadTextSet	(const string& table, const string& geoid, TeTextSet &ts);
	virtual bool selectTextSet	(const string& table, const string& criteria, TeTextSet &ts);

	virtual bool insertText		(const string& table, TeText &t) = 0;	
	virtual bool updateText		(const string& table, TeText &t);
	virtual bool locateText		(const string& table, TeCoord2D &pt, TeText &text, const double& tol = 0.0);
	virtual bool locateTextSet	(const string& table, TeCoord2D &pt, TeTextSet &textSet, const double& tol = 0.0);
	//@}

	/** @name Arc
	*  Accessing/Inserting/Modifying Arc geometries  into the database. 
	*/
	//@{ 	
	//! Inserts an arc set geometry in the database.
	virtual bool insertArcSet	(const string& table, TeArcSet &as);	

	//! Updates arc set geometry in the database.
	virtual bool updateArcSet	(const string& table, TeArcSet &as);	

	//! Loads an arc geometry from the database that has the specified object id (geoid).
	virtual bool loadArcSet		(const string& table, const string& geoid, TeArcSet &as);

	//! Inserts an arc geometry in the database.
	virtual bool insertArc		(const string& table,TeArc &arc) = 0;

	//! Updates an arc geometry in the database.
	virtual bool updateArc		(const string& table,TeArc &arc);
	//@}

	/** @name Node
	*  Accessing/Inserting/Modifying Node geometries into the database. 
	*/
	//@{ 	
	// Accessing/Inserting node geometries into the database
	virtual bool insertNodeSet	(const string& table, TeNodeSet &ns);	
	virtual bool updateNodeSet	(const string& table, TeNodeSet &ns);	
	virtual bool loadNodeSet	(const string& table, const string& geoid, TeNodeSet &ps);

	virtual bool insertNode		(const string& table, TeNode &node) = 0;	
	virtual bool updateNode		(const string& table, TeNode &node);	
	//@}

	/** @name Cell
	*  Accessing/Inserting/Modifying Cell geometries  into the database. 
	*/
	//@{ 	
	// Accessing/Inserting cell geometries into the database
	virtual bool insertCellSet	(const string& table, TeCellSet &cs);	
	virtual bool updateCellSet	(const string& table, TeCellSet &cs);	
	virtual bool loadCellSet	(const int& layerId, const string& table, const string& geoid, TeCellSet &cs);
	virtual bool selectCellSet	(const int& layerId, const string& table, const string& criteria, TeCellSet &cs);

	virtual bool insertCell		(const string& table, TeCell &c) = 0;
	virtual bool updateCell		(const string& table, TeCell &c);
	virtual bool locateCell		(const string& table, TeCoord2D &pt, TeCell &c, const double& tol = 0.0);
	//@}

	//! Removes a geometry from the given tableName
	virtual bool removeGeometry(const string& tableName, const TeGeomRep& rep, const int& geomId);
	
	//! Insert a raster block into the database
	/*!
      \param table table name
	  \param blockId block unique identifier
	  \param ll  block lower left coordinate
	  \param ur  block upper right coordinate
	  \param buf block binary data
	  \param size block size
	  \param band block band
	  \param res block resolution factor
	  \param subband sub band definitiion
	*/
	virtual	bool insertRasterBlock(const string& table, const string& blockId, const TeCoord2D& ll, const TeCoord2D& ur, unsigned char *buf,unsigned long size, int band=0, unsigned int res=1, unsigned int subband=0) = 0;

	//! Inserts the entire visual of a Legend
	virtual	bool insertVisual (TeLegendEntry *legend);

	//! Insert raster visual
	virtual bool insertRasterVisual (int themeId , TeRasterVisual* rasterVisual);

	//! Returns the raster associated to a layer
	virtual TeRaster* loadLayerRaster(int layerId, const string& objectId="", const char& mode = 'r');

	//! Creates a lookup table (used for pallete raster representations)
	virtual bool createLUTTable(const string& name);

	//! Loads a look up table associated to a raster and fills its parameters
	virtual bool loadRasterLUT(TeRasterParams* par);

	//! Creates a spatial index for a spatial table. In order to get correct column names to index, see getSpatialIdxColumn method.
	virtual bool createSpatialIndex(const string& table, const string& columns, TeSpatialIndexType /*type*/ = TeRTREE,short /* level */ =0,short /* tile */ =0);

	//! Creates a spatial metadata for a spatial table. It is implemented only in spatial databases.
	virtual bool insertMetadata(const string& /* table */, const string& /* column */, double /* tolx */, double /* toly */,TeBox &/* box */,short /* srid */ =0) { return true; };

	//! Returns the name of the column that wiil be the spatially indexed, for a given type of geometry table 
	virtual string getSpatialIdxColumn(TeGeomRep rep);

	//! Update box information in a table that has a set of columns to store a box value
	/*
		This method gives to the drivers the ability to update box columns, considering precision issues
		that are particular to the driver. The box should be stored in 4 columns (lower_x, lower_y, upper_x, upper_y)
		\param tableName table name
		\param keyColumnName name of the column that is primary key
		\param idValue key value of the row that should be updated
		\param box new box value
	*/
   virtual bool updateBBox(const string& tableName, const string& keyColumnName, int keyValue, const TeBox& box);  


	/** @name Spatial Operations with vector data
	*  spatial operations over geometries into the database. 
	*/
	//@{ 	

	/** @name topologic relation query
	*  topologic relation query over geometries into the database. 
	*/
	//@{
	/*!
	  \brief Returns the geometries of a geometric table (actGeomTable) that have a specific spatial relation (relate) with a subset of geometries of this table (actGeomTable)   
	  \param actGeomTable	geometric table name
	  \param actRep			geometric representation of the geometric table
	  \param actIdsIn		identifiers of a geometry subset of the actGeomTable table 
	  \param portal			a pointer to a database portal that will contain the resulted geometries
	  \param relate			spatial relation
	  \param actCollTable	collection table name
	 */
	virtual bool spatialRelation(const string& actGeomTable, TeGeomRep actRep, TeKeys& actIdsIn, 
		TeDatabasePortal *portal, int relate, const string& actCollTable="");
	
	/*!
	  \brief Returns the geometries of a geometric table (visGeomTable) that have a specific spatial relation (relate) with a subset of geometries of other geometric table (actGeomTable)   
	  \param actGeomTable	geometric table name
	  \param actRep			geometric representation of the actGeomTable table
	  \param actIdsIn		identifiers of a geometry subset of the actGeomTable table 
	  \param visGeomTable	geometric table name
	  \param visRep			geometric representation of the visGeomTable table
	  \param portal			a pointer to a database portal that will contain the resulted geometries
	  \param relate		 	spatial relation
	  \param visCollTable	collection table name associated with the visGeomTable table
	 */
	virtual bool spatialRelation(const string& actGeomTable, TeGeomRep actRep, TeKeys& actIdsIn, 
		const string& visGeomTable, TeGeomRep visRep, TeDatabasePortal *portal, 
		int relate, const string& visCollTable=""); 

	/*!
	  \brief Returns the geometries of a geometric table (actGeomTable) that have a specific spatial relation (relate) with a geometry in memory (geom)
	  \param actGeomTable	geometric table name
	  \param actRep			geometric representation of the actGeomTable table
	  \param geom			a pointer to a geometry in memory
	  \param portal			a pointer to a database portal that will contain the resulted geometries
	  \param relate			spatial relation
	  \param actCollTable	collection table name associated with the actGeomTable table
	 */
	virtual bool spatialRelation(const string& actGeomTable, TeGeomRep actRep, TeGeometry* geom, 
		TeDatabasePortal *portal, int relate, const string& actCollTable=""); 
		
	/*!
	  \brief Returns the geometries of a geometric table (actGeomTable) that have a specific spatial relation (relate) with a subset of geometries of this table (actGeomTable)   
	  \param actGeomTable	geometric table name
	  \param actRep			geometric representation of the geometric table
	  \param actIdsIn		identifiers of a geometry subset of the actGeomTable table 
	  \param actIdsOut		structure that will contain the identifiers of the resulted geometries
	  \param relate			spatial relation
	  \param actCollTable	collection table name
	 */
	virtual bool spatialRelation(const string& actGeomTable, TeGeomRep actRep, TeKeys& actIdsIn, 
		TeKeys& actIdsOut, int relate, const string& actCollTable="");

	/*!
	  \brief Returns the geometries of a geometric table (visGeomTable) that have a specific spatial relation (relate) with a subset of geometries of other geometric table (actGeomTable)   
	  \param actGeomTable	geometric table name
	  \param actRep			geometric representation of the actGeomTable table
	  \param actIdsIn		identifiers of a geometry subset of the actGeomTable table 
	  \param visGeomTable	geometric table name
	  \param visRep			geometric representation of the visGeomTable table
	  \param visIdsOut		structure that will contain the identifiers of the resulted geometries
	  \param relate			spatial relation
	  \param visCollTable	collection table name associated with the visGeomTable table
	 */
	virtual bool spatialRelation(const string& actGeomTable, TeGeomRep actRep, TeKeys& actIdsIn, 
		const string& visGeomTable, TeGeomRep visRep, TeKeys& visIdsOut, int relate, 
		const string& visCollTable="", TeDatabase* = 0); 

	/*!
	  \brief Returns the geometries of a geometric table (actGeomTable) that have a specific spatial relation (relate) with a geometry in memory (geom)
	  \param actGeomTable	geometric table name
	  \param actRep			geometric representation of the actGeomTable table
	  \param geom			a pointer to a geometry in memory
	  \param actIdsOut		structure that will contain the identifiers of the resulted geometries
	  \param relate			spatial relation
	  \param actCollTable	collection table name associated with the actGeomTable table
	*/
	virtual bool spatialRelation(const string& actGeomTable, TeGeomRep actRep, TeGeometry* geom, 
		TeKeys& actIdsOut, int relate, const string& actCollTable=""); 
	//@}
	
	/** @name metric functions
	*  metric functions over geometries into the database. 
	*/
	//@{
	/*!
		\brief Calculates the area of a geometry set of the geometric table (actGeomTable) 
		\param actGeomTable	geometric table name
		\param actRep		geometric representation of the geometric table
		\param actIdsIn		identifiers of the geometry set of the actGeomTable table 
		\param area			the returned area value 
	 */
	virtual bool calculateArea(const string& actGeomTable, TeGeomRep actRep, TeKeys& actIdsIn, double &area);

	/*!
		\brief Calculates the length of a geometry set of the actGeomTable table 
		\param actGeomTable	geometric table name
		\param actRep		geometric representation of the geometric table
		\param actIdsIn		identifiers of the geometry set of the actGeomTable table 
		\param length		the returned length value 
	 */
	virtual bool calculateLength(const string& actGeomTable, TeGeomRep actRep, TeKeys& actIdsIn, double &length);
	
	/*!
		\brief Calculates the distance between two geometries of the actGeomTable table 
		\param actGeomTable	geometric table name
		\param actRep		geometric representation of the geometric table
		\param Ids			identifiers of the two geometries of the actGeomTable table 
		\param distance		the returned distance value 
	 */
	virtual bool calculateDistance(const string& actGeomTable, TeGeomRep actRep, TeKeys& Ids, double& distance);

	/*!
		\brief Calculates the distance between a geometry of a geometric table (actGeomTable) and a geometry of other geometric table (visGeomTable)
		\param actGeomTable		geometric table name
		\param actRep			geometric representation of the actGeomTable table
		\param objId1			identifier of the geometry of the actGeomTable table
		\param visGeomTable		geometric table name
		\param visRep			geometric representation of the visGeomTable table
		\param objId2			identifier of the geometry of the visGeomTable table
		\param distance			the returned distance value 
	 */
	virtual bool calculateDistance(const string& actGeomTable, TeGeomRep actRep, const string& objId1, 
		const string& visGeomTable, TeGeomRep visRep, const string& objId2, double& distance);

	/*!
	  \brief Returns the geometries of a geometric table (actGeomTable) that are within a specific distance from a point in memory 
	  \param actGeomTable	geometric table name
	  \param actRep			geometric representation of the actGeomTable table
	  \param point			a point in memory
	  \param IdsDistOut		structure that will contain the identifiers of the resulted geometries and their distances
	  \param max_distance	maximum distance 
	  \param actCollTable	collection table name associated with the actGeomTable table
	*/
	virtual bool withinDistance(const string& actGeomTable, TeGeomRep actRep, const TeCoord2D& point, 
		TeKeysToDist& IdsDistOut, const double& max_distance, const string& actCollTable="");
	//@}


	/** @name functions that generate new geometries 
	*  functions that generate new geometries over geometries into the database. 
	*/
	//@{
	/*!
		\brief Returns the buffers with a specific distance of a geometry set of a geometric table (actGeomTable)
		\param actGeomTable	geometric table name
		\param actRep		geometric representation of the geometric table
		\param actIds		identifiers of the geometry set of the actGeomTable table 
		\param bufferSet	the returned buffers 
		\param dist			the distance of the buffers
	 */
	virtual bool buffer(const string& actGeomTable, TeGeomRep actRep, TeKeys& actIds, TePolygonSet& bufferSet, double dist);

	/*!
		\brief Returns the centroids of a geometry set of a geometric table (actGeomTable)
		\param actGeomTable	geometric table name
		\param actRep		geometric representation of the geometric table
		\param centroidSet	the returned centroids 
		\param actIds		identifiers of the geometry set of the actGeomTable table 
		\param actCollTable collection table name associated with the actGeomTable table 
	*/
	virtual bool centroid(const string& actGeomTable, TeGeomRep actRep, TePointSet& centroidSet, TeKeys actIds = vector<string>(), const string& actCollTable = "");

	/*!
		\brief Returns the convex geometries of a geometries set of a geometric table (actGeomTable)
		\param actGeomTable		geometric table name
		\param actRep			geometric representation of the geometric table
		\param actIds			identifiers of the geometry set of the actGeomTable table 
		\param convexHullSet	the returned convex geometries 
	*/
	virtual bool convexHull(const string& actGeomTable, TeGeomRep actRep, TeKeys& actIds, TePolygonSet& convexHullSet);
	//@}

	/*!
		\brief Returns the nearest neighbors of a specific geometry of a geometric table (actGeomTable)
		\param actGeomTable		geometric table name
		\param actCollTable		collection table name associated with the actGeomTable table
		\param actRep			geometric representation of the geometric table
		\param objId1			identifier of the geometry of the actGeomTable table
	    \param actIdsOut		structure that will contain the identifiers of the nearest neighbors 
		\param numRes			the number of nearest neighbors that will be returned
	*/
	virtual bool nearestNeighbors(const string& actGeomTable, const string& actCollTable,
		TeGeomRep actRep, const string& objId1, TeKeys& actIdsOut, int numRes=1);
	
	/*!
		\brief Returns the nearest neighbors of a geometric table (visGeomTable) of a specific geometry of other geometric table (actGeomTable)
		\param actGeomTable		geometric table name
		\param actRep			geometric representation of the actGeomTable table
		\param objId1			identifier of the geometry of the actGeomTable table
		\param visGeomTable		geometric table name
		\param visCollTable		collection table name associated with the visGeomTable table
		\param visRep			geometric representation of the visGeomTable table
	    \param visIdsOut		structure that will contain the identifiers of the nearest neighbors 
		\param numRes			the number of nearest neighbors that will be returned
	*/
	virtual bool nearestNeighbors(const string& actGeomTable, TeGeomRep actRep, const string& objId1, 
		const string& visGeomTable, const string& visCollTable, 
		TeGeomRep visRep, TeKeys& visIdsOut, int numRes=1); 

	/*!
		\brief Returns the nearest neighbors of a specific geometry of a geometric table (actGeomTable)
		\param actGeomTable		geometric table name
		\param actCollTable		collection table name associated with the actGeomTable table
		\param actRep			geometric representation of the geometric table
		\param objId1			identifier of the geometry of the actGeomTable table
	    \param portal			a pointer to a database portal that will contain the identifiers of the nearest neighbors 
		\param numRes			the number of nearest neighbors that will be returned
	*/
	virtual bool nearestNeighbors(const string& actGeomTable, const string& actCollTable, 
		TeGeomRep actRep, const string& objId1, TeDatabasePortal* portal, int numRes=1);

	/*!
		\brief Returns the nearest neighbors of a geometric table (visGeomTable) of a specific geometry of other geometric table (actGeomTable)
		\param actGeomTable		geometric table name
		\param actRep			geometric representation of the actGeomTable table
		\param objId1			identifier of the geometry of the actGeomTable table
		\param visGeomTable		geometric table name
		\param visCollTable		collection table name associated with the visGeomTable table
		\param visRep			geometric representation of the visGeomTable table
	    \param portal			a pointer to a database portal that will contain the identifiers of the nearest neighbors 
		\param numRes			the number of nearest neighbors that will be returned
	*/
	virtual bool nearestNeighbors(const string& actGeomTable, TeGeomRep actRep, 
		const string& objId1, const string& visGeomTable, const string& visCollTable, 
		TeGeomRep visRep, TeDatabasePortal* portal, int numRes=1); 

	/** @name set functions
	*  functions of set: union, intersection, difference and symmetrical difference. 
	*/
	//@{

	/*!
		\brief Returns the intersection between two geometries of a geometric table (actGeomTable) 
		\param actGeomTable		geometric table name
		\param actRep			geometric representation of the actGeomTable table
		\param actIds		identifiers of the geometry set of the actGeomTable table 
		\param geomVect			the returned intersection 
	 */
	virtual bool geomIntersection(const string& actGeomTable, TeGeomRep actRep, TeKeys& actIds, TeGeometryVect& geomVect);

	/*!
		\brief Returns the intersection between a geometry of a geometric table (actGeomTable) and a geometry of other geometric table (visGeomTable)
		\param actGeomTable		geometric table name
		\param actRep			geometric representation of the actGeomTable table
		\param objId1			identifier of a geometry of the actGeomTable table
		\param visGeomTable		geometric table name
		\param visRep			geometric representation of the visGeomTable table
		\param objId2			identifier of other geometry of the visGeomTable table
		\param geomVect			the returned intersection 
	 */
	virtual bool geomIntersection(const string& actGeomTable, TeGeomRep actRep, const string& objId1,
		const string& visGeomTable, TeGeomRep visRep, const string& objId2, TeGeometryVect& geomVect);

	/*!
		\brief Returns the difference between two geometries of a geometric table (actGeomTable) 
		\param actGeomTable		geometric table name
		\param actRep			geometric representation of the actGeomTable table
		\param objId1			identifier of a geometry of the actGeomTable table
		\param objId2			identifier of other geometry of the actGeomTable table
		\param geomVect			the returned difference 
	 */
	virtual bool geomDifference(const string& actGeomTable, TeGeomRep actRep, const string& objId1, 
		const string& objId2, TeGeometryVect& geomVect);

	/*!
		\brief Returns the difference between a geometry of a geometric table (actGeomTable) and a geometry of other geometric table (visGeomTable)
		\param actGeomTable		geometric table name
		\param actRep			geometric representation of the actGeomTable table
		\param objId1			identifier of a geometry of the actGeomTable table
		\param visGeomTable		geometric table name
		\param visRep			geometric representation of the visGeomTable table
		\param objId2			identifier of other geometry of the visGeomTable table
		\param geomVect			the returned difference 
	 */
	virtual bool geomDifference(const string& actGeomTable, TeGeomRep actRep, const string& objId1, 
		const string& visGeomTable, TeGeomRep visRep, const string& objId2, TeGeometryVect& geomVect);

	/*!
		\brief Returns the union between geometries of a geometric table (actGeomTable) 
		\param actGeomTable		geometric table name
		\param actRep			geometric representation of the actGeomTable table
		\param actIds			identifiers of the geometry set of the actGeomTable table 
		\param geomVect			the returned union 
	 */
	virtual bool geomUnion(const string& actGeomTable, TeGeomRep actRep, TeKeys& actIds, TeGeometryVect& geomVect);

	/*!
		\brief Returns the union between a geometry of a geometric table (actGeomTable) and a geometry of other geometric table (visGeomTable)
		\param actGeomTable		geometric table name
		\param actRep			geometric representation of the actGeomTable table
		\param objId1			identifier of a geometry of the actGeomTable table
		\param visGeomTable		geometric table name
		\param visRep			geometric representation of the visGeomTable table
		\param objId2			identifier of other geometry of the visGeomTable table
		\param geomVect			the returned union 
	 */
	virtual bool geomUnion(const string& actGeomTable, TeGeomRep actRep, const string& objId1, 
		const string& visGeomTable, TeGeomRep visRep, const string& objId2, TeGeometryVect& geomVect);

	/*!
		\brief Returns the symmetrical difference between two geometries of a geometric table (actGeomTable) 
		\param actGeomTable		geometric table name
		\param actRep			geometric representation of the actGeomTable table
		\param objId1			identifier of a geometry of the actGeomTable table
		\param objId2			identifier of other geometry of the actGeomTable table
		\param geomVect			the returned symmetrical difference 
	 */
	virtual bool geomXOr(const string& actGeomTable, TeGeomRep actRep, const string& objId1, 
		const string& objId2, TeGeometryVect& geomVect);

	/*!
		\brief Returns the symmetrical difference between a geometry of a geometric table (actGeomTable) and a geometry of other geometric table (visGeomTable)
		\param actGeomTable		geometric table name
		\param actRep			geometric representation of the actGeomTable table
		\param objId1			identifier of a geometry of the actGeomTable table
		\param visGeomTable		geometric table name
		\param visRep			geometric representation of the visGeomTable table
		\param objId2			identifier of other geometry of the visGeomTable table
		\param geomVect			the returned symmetrical difference 
	 */
	virtual bool geomXOr(const string& actGeomTable, TeGeomRep actRep, const string& objId1, 
		const string& visGeomTable, TeGeomRep visRep, const string& objId2, TeGeometryVect& geomVect);	
	//@}

	/** @name Spatial Operations with raster data
	*  spatial operations over raster data into the database. 
	*/
	//@{ 	
	/*!
		\brief Returns the statistics of raster data regions inside a geometry set of a geometric table (actGeomTable)
		\param rasterTable		raster table name
		\param actGeomTable		geometric table name that contains polygons
		\param Ids				identifiers of the geometries of the actGeomTable table that define the regions in the raster data  
		\param result			structure that will contain the resulted statistics 
	*/
	virtual bool zonal(const string& rasterTable, const string& actGeomTable, TeKeys& Ids, TeObjectStatistics& result, const bool &useDummy=true);
	
	/*!
		\brief Returns the statistics of raster data regions inside a geometry set of a geometric table (actGeomTable)
		\param rasterTable		raster table name
		\param actGeomTable		geometric table name that contains polygons
		\param actCollTable		collection table that contains the identifiers of the geometries of the actGeomTable table that define the regions in the raster data  
		\param result			structure that will contain the resulted statistics 
	*/
	virtual bool zonal(const string& rasterTable, const string& actGeomTable, const string& actCollTable, TeObjectStatistics& result, const bool &useDummy=true);
	
	/*!
		\brief Returns the statistics of a raster data region inside a geometry in memory 
		\param rasterTable		raster table name
		\param poly				the geometry in memory that define a region in the raster data 
		\param result			structure that will contain the resulted statistics 
	*/
	virtual bool zonal(const string& rasterTable, TePolygon& poly, TeStatisticsDimensionVect& result,const bool &useDummy=true);

	/*!
		\brief Clips a raster data from a geometry of a geometric table (actGeomTable)
		\param rasterTable		raster table name
		\param actGeomTable		geometric table name that contains polygons
		\param objId			identifier of the geometry of the actGeomTable table 
		\param nameLayerOut		the layer name that will contain the result 
		\param st				the strategy used in the clipping of the raster data
	*/
	virtual bool mask(const string& rasterTable, const string& actGeomTable, const string& objId, const string& nameLayerOut, TeStrategicIterator st);
	
	/*!
		\brief Clips a raster data from a geometry in memory (poly)
		\param rasterTable		raster table name
		\param poly				a geometry in memory 
		\param nameLayerOut		the layer name that will contain the result 
		\param st				the strategy used in the clipping of the raster data
	*/
	virtual bool mask(const string& rasterTable, TePolygon& poly, const string& nameLayerOut, TeStrategicIterator st);
	//@}
	
	/** @name specifics SQLs
	*  return SQL strings 
	*/
	//@{ 	
	//! Return a string that describes a where clause in SQL to return the geometries inside the box
	virtual string getSQLBoxWhere (const TeBox& box, const TeGeomRep rep, const std::string& tableName);

	//! Return a string that describes a where clause in SQL to return the geometries of the table2 that are 
	//! inside the geometries box of the table1 (table1 must have lower_x, lower_y...) 
	virtual string getSQLBoxWhere (const string& table1, const string& table2, TeGeomRep rep2, TeGeomRep rep1 = TePOLYGONS);

	//! Return a string SQL to be used in the clause SELECT to select the box (lower_x, lower_y, upper_x, upper_y)
	virtual string getSQLBoxSelect (const string& tableName, TeGeomRep rep);

	//!< Returns a string SQL to be used in the ORDER BY clause when querying geometries.
	virtual std::string getSQLOrderBy(const TeGeomRep& rep) const;

	//! Return a string SQL to calculate the statistics of some attributes
	virtual string getSQLStatistics (TeGroupingAttr& attrs);
	
	//! Return the database function in SQL to generate autonumber values
	virtual string getSQLAutoNumber(const string& table);

	//! Return a string SQL to temporal where
	virtual string getSQLTemporalWhere (TeTimeInterval& /* timeInterval */, TeTemporalRelation /* timeOperator */, const string& /* initialTime */, const string& /* finalTime */ );

	//! Return a string SQL to temporal where 
	virtual string getSQLTemporalWhere (const string& temporalRest);
		
	//! Return a string SQL to temporal where
	virtual string getSQLTemporalWhere(int /* time1 */, int /* time2 */, TeChronon /* chr */, TeTemporalRelation /* rel */, const string& /* initialTime */, const string& /* finalTime */);

	//! Returns a valid SQL time string
	virtual string getSQLTime(const TeTime& /* time */) const { return ""; };

	//! Returns a SQL temporal expression applied to a column
	virtual string getSQLTemporalFunction (TeChronon chr, const string& colName);
	//@}

	//! Return the box of a specific geometry (object_id)  
	virtual bool getMBRGeom(string tableGeom, string object_id, TeBox& box, string colGeom);

	//! Return the box of a select objects set 
	virtual bool getMBRSelectedObjects(string geomTable,string colGeom, string fromClause, 
		string whereClause, string afterWhereClause, TeGeomRep repType,TeBox &bout, const double& tol = 0.0);

	//! Gets the list of attributes of a table
	virtual bool getAttributeList(const string& tableName,TeAttributeList& attList);

	//! Escape special characters in a string to be used in a SQL statement
	virtual string  escapeSequence(const string& from) = 0;

	//! Returns theme box
	virtual TeBox getThemeBox(TeTheme* theme);

	//! Returns the container of legend title alias
	map<int, map<string, string> >& mapThemeAlias() {return metaModel_->mapThemeAlias();}

	//! Concat values in a vector using unionString as the join between each value
	virtual string concatValues(vector<string>& values, const string& unionString) = 0;

	//! Returns the SQL function for upper case
	virtual string toUpper(const string& value) = 0;

	//! Returns the SQL function for substring that starts from left to right with informed length.
	virtual string leftString(const string& /*name*/, const int& /*length*/){return "";}

	//! Write the given version as the terralib version in the database
	virtual	bool updateVersionStamp(const string& version ); 

	//! Read and returns the terralib version from the database
	virtual	bool loadVersionStamp( string& version ); 

   /** @name Transaction control methods 
	\Note should be implemented by the drivers that has it. Default implementation
	is DO NOTHING.
   */
   //@{ 
   //! Begins a transaction
   virtual bool beginTransaction(); 

   //! Commits a transaction
   virtual bool commitTransaction();

   //! Rollbacks a transaction
   virtual bool rollbackTransaction();
   //@}

   //! Drops a database view
   virtual bool dropDBView(const string& dbViewName);
   
	//! Gets the client encoding
   virtual std::string getClientEncoding()
   { return ""; }

	//! Sets the client encoding
   virtual bool setClientEncoding(const std::string& /*characterSet*/)
   { return true; }

	//! Retrives the list of available character sets
   virtual bool getEncodingList(std::vector<std::string>& /*vecEncodingList*/)
   { return true; }

   //! Retrives the list of available character sets
   virtual bool getEncodingList(const std::string& /*host*/, const std::string& /*user*/, const std::string& /*password*/, const int& /*port*/, std::vector<std::string>& /*vecEncodingList*/)
   { return true; }


protected :

	bool				isConnected_;			//!< indicates if the connection is open
	string				host_;					//!< host name of the database server
	string				user_;					//!< user name 
	string				password_;				//!< user password
	string				database_;				//!< database name
	int					portNumber_;			//!< port number
	int					errorNumber_;			//!< error number
	string				errorMessage_;			//!< error message
	string				dbmsName_;				//!< DBMS name (Ado, MySQL, Postgres, OracleSpatial)
	TeSharedPtr<TeMetaModelCache> metaModel_;	//!< Meta model: Layers, Themes, Views...

	//! Update metadata about an attribute table that had its name or columns changed
	void alterTableInfoInMemory(const string& updatedTableName, string oldTableName="");

	int               transactionCounter_;//!< counts how many nested transactions have been opened

private:

	TeDatabase(const TeDatabase& other);
};

//! An abstract access portal to a database
/*! A portal has a concept of a record set, that is generated by a selection (query) on
	the data accessible through a connection to a database server.
  \sa TeDatabase, TeGeometry, TeTable, TeTheme, TeView, TeLayer

  */
class TL_DLL TeDatabasePortal {
protected:
	

	TeDatabase*		db_;			//!< the database associated to this portal
	TeAttributeList	attList_;		//!< the list of attributes associated to this portal
	int				numRows_;		//!< the number of rows in this portal
	int				numFields_;		//!< the number of fields in this portal
	string          errorMessage_;	//!< error message
	int				errorNumber_;	//!< error number

public :

	//!Constructor 
	TeDatabasePortal ();

	//! Destructor
	virtual ~TeDatabasePortal ();
	
	//! Returns the database associated to this portal 
	TeDatabase* getDatabase()
	{ return db_; }

	//! Executes a SQL query that opens a record set
	virtual bool query ( const string &qry, TeCursorLocation l = TeSERVERSIDE, TeCursorType t = TeUNIDIRECTIONAL, TeCursorEditType e = TeREADONLY, TeCursorDataType dt = TeTEXTCURSOR ) = 0;

	//! Fetchs the next row in a record set that shouldve been previously opened
	virtual bool fetchRow () = 0;

	//! Fetchs a particular row
	virtual bool fetchRow (int i) = 0;

	//! Frees the current record set
	virtual void freeResult () = 0;

	//! Gets the last error message
	virtual string	errorMessage ()
	{ return errorMessage_; }

	//! Gets the number of the last error message
	virtual int errorNum ()
	{ return errorNumber_; }
	
//	virtual bool loadNetwork (TeLayer *layer) = 0;

// specific SQL SELECT command methods

	/*! \brief Retrieves the number of rows in a portal. Some drivers
	           (like PostgreSQL and PostGIS) brings to the client only
			   a part of the row, and then this number can be less than
			   the number of rows returned by query.
    */
	int numRows () 
	{ return numRows_;}

	//! Retrieves the number of fields in this portal
	int numFields () 
	{ return numFields_; }

	//! Retrieves attribute list in this portal
	TeAttributeList& getAttributeList()	
	{ return attList_; }

	//! Retrieves the i-th attribute in this portal
	TeAttribute getAttribute (int i);

	//! Retrieves an attribute by name
	TeAttribute getAttribute (const string& s);

	//! Gets the value of the i-th attribute as a literal
	virtual char* getData (int i) = 0;

	//! Gets the value of a named attribute as a literal
	virtual char* getData (const string& s) = 0;

	//! Gets the value of the i-th attribute as a double
	virtual double getDouble (int i);

	//! Gets the value of a named attribute as a double
	virtual double getDouble (const string& s);

	//! Gets the value of the i-th attribute as an integer
	virtual int getInt (int i);

	//! Gets the value of a named attribute as an integer
	virtual int getInt (const string& s);

	//! Gets the value of a named attribute as a boolean
	virtual bool getBool (const string& s) = 0;

	//! Gets the value of the i-th attribute as a boolean
	virtual bool getBool (int i) = 0;

	//! Gets the value of the i-th attribute as a date 
	virtual TeTime getDate (int i) = 0;

	//! Gets the value of a named attribute as a date 
	virtual TeTime getDate (const string& s) = 0;

	//! Gets the of a date/time attribute as a string formatted as accepted in further SQL statements
	virtual string getDateAsString(int i) = 0;

	//! Gets the of a date/time attribute as a string formatted as accepted in further SQL statements
	virtual string getDateAsString(const string& s) = 0;

	//! Gets the value of a named BLOB attribute 
	virtual bool getBlob(const string& s, unsigned char* &data, long& size) = 0;

	//! Gets the index of a named attribute
	int getColumnIndex (const string& s);

	//! Gets the name of the i-th attribute
	string getColumnName (int i);

	/** @name Data Model
	  The following methods decodify structures as stored 
	  in the database according to the data model proposed in TerraLib. 
	*/
	//@{ 	
	virtual TeViewTree*		getViewTree ();
	virtual TeLegendEntry	getLegend();
	virtual void			getVisual(TeVisual*);
	virtual bool			getVisual(TeVisual* vis, TeGeomRep& rep, const unsigned int& initIndex);
	virtual bool			getRasterVisual(TeRasterVisual& vis, const unsigned int& initIndex=0);
	virtual TeColor			getColor(); 
	virtual bool	getRasterBlock(unsigned long& size, unsigned char* ptData)=0;
	virtual bool	getView(TeView& view, const unsigned int& initIndex=0);
	virtual bool	getProjection(TeProjection** proj, const unsigned int& initIndex=0);
	virtual void	getViewNodeParams (TeViewNodeParams& params, const unsigned int& initIndex=0);
	virtual bool	getTheme(TeAbstractTheme& theme, const unsigned int& initIndex=0);
	virtual bool	getGrouping(TeGrouping& group, const unsigned int& initIndex=0);
	virtual bool	getLegend(TeLegendEntry& leg, const unsigned int& initIndex=0);
	virtual bool	getAttrTable(TeTable& table, const unsigned int& initIndex=0);
	virtual bool	getLayer(TeLayer& layer, const unsigned int& initIndex=0);
	virtual bool	getRepresentation(TeRepresentation& rep, const unsigned int& initIndex=0);

	//@}

	/** @name Fetch Geometry
	  The following methods decodify geometries as stored 
	  in the database according to the data model proposed in TerraLib.
	  \param geom		the geometry that will be filled from portal
	  \param initIndex  the position index in the portal where begins the geometry information 
	  \return The fetchGeometry methods advance the portal to the next record and 
	  they return TRUE if there are more records to be read and FALSE otherwise.
	*/
	//@{ 	
	virtual	bool fetchGeometry (TePolygon& geom) = 0;
	virtual	bool fetchGeometry (TePolygon& geom, const unsigned int& initIndex); 
	virtual	bool fetchGeometry (TeLine2D& geom) = 0;
	virtual	bool fetchGeometry (TeLine2D& geom, const unsigned int& initIndex); 
	virtual	bool fetchGeometry (TeNode& geom) = 0;
	virtual	bool fetchGeometry (TeNode& geom, const unsigned int& initIndex);
	virtual	bool fetchGeometry (TePoint& geom) = 0;
	virtual	bool fetchGeometry (TePoint& geom, const unsigned int& initIndex);
	virtual	bool fetchGeometry (TeCell& geom);
	virtual	bool fetchGeometry (TeCell& geom, const unsigned int& initIndex);
	virtual	bool fetchGeometry (TeArc& geom);
	virtual	bool fetchGeometry (TeArc& geom, const unsigned int& initIndex);
	virtual	bool fetchGeometry (TeText& geom);
	virtual	bool fetchGeometry (TeText& geom, const unsigned int& initIndex);
	//@}
};


//! Breaks a collection of strings into a series of IN clauses to be used in query expressions
/*
	\params begin Iterator that p oints to the beginning of the collection
	\params end Iterator that points to the end of the collection
	\param db pointer to the database where the query expression will be applied
	\param addPlicae flat to indicate that the character ' should enclose each string
*/
template <typename Iterator>
vector<string>
generateInClauses(Iterator& begin, Iterator& end, TeDatabase* db, bool addPlicae=true)
{
	int i, chunkSize = 200;
	string inClause;
	vector<string> inClauseVector;

	Iterator temp = begin;
	i = 0;
	while (temp != end)
	{
		if (i%chunkSize == 0)
		{
			if (!inClause.empty())
			{
				inClause[inClause.size() - 1] = ')';
				inClauseVector.push_back(inClause);
				inClause.clear();
			}
			inClause = "(";
		}

		if (addPlicae)
			inClause += "'" + db->escapeSequence(*temp) + "',";
		else
			inClause += db->escapeSequence(*temp) + ",";
		i++;
		++temp;
	}
	if (!inClause.empty())
	{
		inClause[inClause.size() - 1] = ')';
		inClauseVector.push_back(inClause);
	}
	return inClauseVector;
}


/*! \example createDatabase.cpp
	Shows how to create a TerraLib database.
 */

/*! \example databaseQuery.cpp
	Shows how to retrieve an existing layer from a TerraLib database, 
	and execute some queries on its polygon geometry table.
 */

/*! \example databaseSQLQuery.cpp
	Shows how retrieve geometries (polygons) using an SQL query.
 */
 
/*! \example spatialQuery.cpp
	Shows how  to use the database interface to do some	spatial queries 
	involving objects with points, lines and polygon geometries.
 */

/*! \example spatialQueryAndBuffer.cpp
	Shows to use the database interface to do some  spatial queries involving 
	objects with points, lines and polygon geometries, and to generate a buffer operation.
 */
#endif