18e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project/*
28e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved.
38e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project *
48e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * Redistribution and use in source and binary forms, with or without
58e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * modification, are permitted provided that the following conditions
68e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * are met:
78e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * 1. Redistributions of source code must retain the above copyright
88e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project *    notice, this list of conditions and the following disclaimer.
98e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * 2. Redistributions in binary form must reproduce the above copyright
108e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project *    notice, this list of conditions and the following disclaimer in the
118e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project *    documentation and/or other materials provided with the distribution.
128e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project *
138e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
148e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
158e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
168e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
178e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
188e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
198e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
208e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
218e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
228e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
238e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
248e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project */
258e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
268e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#ifndef SQLiteStatement_h
278e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#define SQLiteStatement_h
288e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
298e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#include "SQLiteDatabase.h"
308e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
318e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectstruct sqlite3_stmt;
328e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
338e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectnamespace WebCore {
348e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
358e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectclass SQLValue;
368e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
37ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdochclass SQLiteStatement {
38ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddbBen Murdoch    WTF_MAKE_NONCOPYABLE(SQLiteStatement); WTF_MAKE_FAST_ALLOCATED;
398e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectpublic:
408e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    SQLiteStatement(SQLiteDatabase&, const String&);
418e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    ~SQLiteStatement();
428e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
438e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    int prepare();
448e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    int bindBlob(int index, const void* blob, int size);
452fc2651226baac27029e38c9d6ef883fa32084dbSteve Block    int bindBlob(int index, const String&);
468e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    int bindText(int index, const String&);
47e8b154fd68f9b33be40a3590e58347f353835f5cSteve Block    int bindInt(int index, int);
488e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    int bindInt64(int index, int64_t);
498e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    int bindDouble(int index, double);
508e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    int bindNull(int index);
518e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    int bindValue(int index, const SQLValue&);
528e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    unsigned bindParameterCount() const;
538e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
548e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    int step();
558e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    int finalize();
568e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    int reset();
578e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
588e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    int prepareAndStep() { if (int error = prepare()) return error; return step(); }
598e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
608e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    // prepares, steps, and finalizes the query.
618e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    // returns true if all 3 steps succeed with step() returning SQLITE_DONE
628e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    // returns false otherwise
638e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    bool executeCommand();
648e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
658e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    // prepares, steps, and finalizes.
668e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    // returns true is step() returns SQLITE_ROW
678e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    // returns false otherwise
688e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    bool returnsAtLeastOneResult();
698e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
708e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    bool isExpired();
718e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
728e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    // Returns -1 on last-step failing.  Otherwise, returns number of rows
738e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    // returned in the last step()
748e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    int columnCount();
758e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
76e8b154fd68f9b33be40a3590e58347f353835f5cSteve Block    bool isColumnNull(int col);
778e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    String getColumnName(int col);
788e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    SQLValue getColumnValue(int col);
798e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    String getColumnText(int col);
808e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    double getColumnDouble(int col);
818e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    int getColumnInt(int col);
828e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    int64_t getColumnInt64(int col);
838e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    const void* getColumnBlob(int col, int& size);
842fc2651226baac27029e38c9d6ef883fa32084dbSteve Block    String getColumnBlobAsString(int col);
858e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    void getColumnBlobAsVector(int col, Vector<char>&);
868e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
878e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    bool returnTextResults(int col, Vector<String>&);
888e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    bool returnIntResults(int col, Vector<int>&);
898e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    bool returnInt64Results(int col, Vector<int64_t>&);
908e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    bool returnDoubleResults(int col, Vector<double>&);
918e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
928e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    SQLiteDatabase* database() { return &m_database; }
938e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
948e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    const String& query() const { return m_query; }
958e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
968e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectprivate:
978e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    SQLiteDatabase& m_database;
988e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    String m_query;
998e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    sqlite3_stmt* m_statement;
1008e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#ifndef NDEBUG
1018e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    bool m_isPrepared;
1028e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#endif
1038e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project};
1048e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
1058e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project} // namespace WebCore
1068e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
1078e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#endif // SQLiteStatement_h
108