Home | History | Annotate | Download | only in sql
      1 /*
      2  * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved.
      3  *
      4  * Redistribution and use in source and binary forms, with or without
      5  * modification, are permitted provided that the following conditions
      6  * are met:
      7  * 1. Redistributions of source code must retain the above copyright
      8  *    notice, this list of conditions and the following disclaimer.
      9  * 2. Redistributions in binary form must reproduce the above copyright
     10  *    notice, this list of conditions and the following disclaimer in the
     11  *    documentation and/or other materials provided with the distribution.
     12  *
     13  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
     14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     16  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
     17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     18  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
     20  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
     21  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     24  */
     25 
     26 #ifndef SQLiteStatement_h
     27 #define SQLiteStatement_h
     28 
     29 #include "SQLiteDatabase.h"
     30 
     31 struct sqlite3_stmt;
     32 
     33 namespace WebCore {
     34 
     35 class SQLValue;
     36 
     37 class SQLiteStatement : public Noncopyable {
     38 public:
     39     SQLiteStatement(SQLiteDatabase&, const String&);
     40     ~SQLiteStatement();
     41 
     42     int prepare();
     43     int bindBlob(int index, const void* blob, int size);
     44     int bindText(int index, const String&);
     45     int bindInt64(int index, int64_t);
     46     int bindDouble(int index, double);
     47     int bindNull(int index);
     48     int bindValue(int index, const SQLValue&);
     49     unsigned bindParameterCount() const;
     50 
     51     int step();
     52     int finalize();
     53     int reset();
     54 
     55     int prepareAndStep() { if (int error = prepare()) return error; return step(); }
     56 
     57     // prepares, steps, and finalizes the query.
     58     // returns true if all 3 steps succeed with step() returning SQLITE_DONE
     59     // returns false otherwise
     60     bool executeCommand();
     61 
     62     // prepares, steps, and finalizes.
     63     // returns true is step() returns SQLITE_ROW
     64     // returns false otherwise
     65     bool returnsAtLeastOneResult();
     66 
     67     bool isExpired();
     68 
     69     // Returns -1 on last-step failing.  Otherwise, returns number of rows
     70     // returned in the last step()
     71     int columnCount();
     72 
     73     String getColumnName(int col);
     74     SQLValue getColumnValue(int col);
     75     String getColumnText(int col);
     76     double getColumnDouble(int col);
     77     int getColumnInt(int col);
     78     int64_t getColumnInt64(int col);
     79     const void* getColumnBlob(int col, int& size);
     80     void getColumnBlobAsVector(int col, Vector<char>&);
     81 
     82     bool returnTextResults(int col, Vector<String>&);
     83     bool returnIntResults(int col, Vector<int>&);
     84     bool returnInt64Results(int col, Vector<int64_t>&);
     85     bool returnDoubleResults(int col, Vector<double>&);
     86 
     87     SQLiteDatabase* database() { return &m_database; }
     88 
     89     const String& query() const { return m_query; }
     90 
     91 private:
     92     SQLiteDatabase& m_database;
     93     String m_query;
     94     sqlite3_stmt* m_statement;
     95 #ifndef NDEBUG
     96     bool m_isPrepared;
     97 #endif
     98 };
     99 
    100 } // namespace WebCore
    101 
    102 #endif // SQLiteStatement_h
    103