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 378e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectclass SQLiteStatement : public Noncopyable { 388e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectpublic: 398e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project SQLiteStatement(SQLiteDatabase&, const String&); 408e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project ~SQLiteStatement(); 418e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 428e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project int prepare(); 438e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project int bindBlob(int index, const void* blob, int size); 448e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project int bindText(int index, const String&); 458e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project int bindInt64(int index, int64_t); 468e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project int bindDouble(int index, double); 478e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project int bindNull(int index); 488e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project int bindValue(int index, const SQLValue&); 498e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project unsigned bindParameterCount() const; 508e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 518e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project int step(); 528e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project int finalize(); 538e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project int reset(); 548e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 558e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project int prepareAndStep() { if (int error = prepare()) return error; return step(); } 568e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 578e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project // prepares, steps, and finalizes the query. 588e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project // returns true if all 3 steps succeed with step() returning SQLITE_DONE 598e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project // returns false otherwise 608e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project bool executeCommand(); 618e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 628e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project // prepares, steps, and finalizes. 638e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project // returns true is step() returns SQLITE_ROW 648e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project // returns false otherwise 658e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project bool returnsAtLeastOneResult(); 668e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 678e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project bool isExpired(); 688e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 698e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project // Returns -1 on last-step failing. Otherwise, returns number of rows 708e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project // returned in the last step() 718e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project int columnCount(); 728e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 738e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project String getColumnName(int col); 748e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project SQLValue getColumnValue(int col); 758e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project String getColumnText(int col); 768e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project double getColumnDouble(int col); 778e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project int getColumnInt(int col); 788e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project int64_t getColumnInt64(int col); 798e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project const void* getColumnBlob(int col, int& size); 808e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project void getColumnBlobAsVector(int col, Vector<char>&); 818e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 828e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project bool returnTextResults(int col, Vector<String>&); 838e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project bool returnIntResults(int col, Vector<int>&); 848e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project bool returnInt64Results(int col, Vector<int64_t>&); 858e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project bool returnDoubleResults(int col, Vector<double>&); 868e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 878e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project SQLiteDatabase* database() { return &m_database; } 888e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 898e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project const String& query() const { return m_query; } 908e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 918e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectprivate: 928e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project SQLiteDatabase& m_database; 938e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project String m_query; 948e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project sqlite3_stmt* m_statement; 958e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#ifndef NDEBUG 968e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project bool m_isPrepared; 978e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#endif 988e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project}; 998e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 1008e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project} // namespace WebCore 1018e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project 1028e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#endif // SQLiteStatement_h 103