1 : /******************************************************************************
2 : * $Id: ogrsqliteselectlayer.cpp 19800 2010-06-04 21:38:03Z rouault $
3 : *
4 : * Project: OpenGIS Simple Features Reference Implementation
5 : * Purpose: Implements OGRSQLiteSelectLayer class, layer access to the results
6 : * of a SELECT statement executed via ExecuteSQL().
7 : * Author: Frank Warmerdam, warmerdam@pobox.com
8 : *
9 : ******************************************************************************
10 : * Copyright (c) 2004, Frank Warmerdam
11 : *
12 : * Permission is hereby granted, free of charge, to any person obtaining a
13 : * copy of this software and associated documentation files (the "Software"),
14 : * to deal in the Software without restriction, including without limitation
15 : * the rights to use, copy, modify, merge, publish, distribute, sublicense,
16 : * and/or sell copies of the Software, and to permit persons to whom the
17 : * Software is furnished to do so, subject to the following conditions:
18 : *
19 : * The above copyright notice and this permission notice shall be included
20 : * in all copies or substantial portions of the Software.
21 : *
22 : * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
23 : * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 : * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
25 : * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26 : * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
27 : * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
28 : * DEALINGS IN THE SOFTWARE.
29 : ****************************************************************************/
30 :
31 : #include "cpl_conv.h"
32 : #include "ogr_sqlite.h"
33 :
34 : CPL_CVSID("$Id: ogrsqliteselectlayer.cpp 19800 2010-06-04 21:38:03Z rouault $");
35 : /************************************************************************/
36 : /* OGRSQLiteSelectLayer() */
37 : /************************************************************************/
38 :
39 : OGRSQLiteSelectLayer::OGRSQLiteSelectLayer( OGRSQLiteDataSource *poDSIn,
40 : CPLString osSQL,
41 118 : sqlite3_stmt *hStmtIn )
42 :
43 : {
44 118 : poDS = poDSIn;
45 :
46 118 : iNextShapeId = 0;
47 118 : nSRSId = -1;
48 118 : poFeatureDefn = NULL;
49 :
50 118 : BuildFeatureDefn( "SELECT", hStmtIn );
51 :
52 118 : sqlite3_finalize( hStmtIn );
53 :
54 118 : this->osSQL = osSQL;
55 118 : }
56 :
57 : /************************************************************************/
58 : /* ~OGRSQLiteSelectLayer() */
59 : /************************************************************************/
60 :
61 118 : OGRSQLiteSelectLayer::~OGRSQLiteSelectLayer()
62 :
63 : {
64 118 : }
65 :
66 : /************************************************************************/
67 : /* ResetStatement() */
68 : /************************************************************************/
69 :
70 115 : OGRErr OGRSQLiteSelectLayer::ResetStatement()
71 :
72 : {
73 : int rc;
74 :
75 115 : ClearStatement();
76 :
77 115 : iNextShapeId = 0;
78 :
79 : rc = sqlite3_prepare( poDS->GetDB(), osSQL, osSQL.size(),
80 115 : &hStmt, NULL );
81 :
82 115 : if( rc == SQLITE_OK )
83 : {
84 115 : return OGRERR_NONE;
85 : }
86 : else
87 : {
88 : CPLError( CE_Failure, CPLE_AppDefined,
89 : "In ResetStatement(): sqlite3_prepare(%s):\n %s",
90 0 : osSQL.c_str(), sqlite3_errmsg(poDS->GetDB()) );
91 0 : hStmt = NULL;
92 0 : return OGRERR_FAILURE;
93 : }
94 : }
|