| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2007 Apple Inc. All rights reserved. | 2 * Copyright (C) 2007 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2010 Google Inc. All rights reserved. | 3 * Copyright (C) 2010 Google Inc. All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * | 8 * |
| 9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 namespace WebCore { | 43 namespace WebCore { |
| 44 | 44 |
| 45 SQLStatementSync::SQLStatementSync(const String& statement, const Vector<SQLValu
e>& arguments, int permissions) | 45 SQLStatementSync::SQLStatementSync(const String& statement, const Vector<SQLValu
e>& arguments, int permissions) |
| 46 : m_statement(statement) | 46 : m_statement(statement) |
| 47 , m_arguments(arguments) | 47 , m_arguments(arguments) |
| 48 , m_permissions(permissions) | 48 , m_permissions(permissions) |
| 49 { | 49 { |
| 50 ASSERT(!m_statement.isEmpty()); | 50 ASSERT(!m_statement.isEmpty()); |
| 51 } | 51 } |
| 52 | 52 |
| 53 PassRefPtr<SQLResultSet> SQLStatementSync::execute(DatabaseSync* db, ExceptionSt
ate& es) | 53 PassRefPtr<SQLResultSet> SQLStatementSync::execute(DatabaseSync* db, ExceptionSt
ate& exceptionState) |
| 54 { | 54 { |
| 55 db->setAuthorizerPermissions(m_permissions); | 55 db->setAuthorizerPermissions(m_permissions); |
| 56 | 56 |
| 57 SQLiteDatabase* database = &db->sqliteDatabase(); | 57 SQLiteDatabase* database = &db->sqliteDatabase(); |
| 58 | 58 |
| 59 SQLiteStatement statement(*database, m_statement); | 59 SQLiteStatement statement(*database, m_statement); |
| 60 int result = statement.prepare(); | 60 int result = statement.prepare(); |
| 61 if (result != SQLResultOk) { | 61 if (result != SQLResultOk) { |
| 62 if (result == SQLResultInterrupt) | 62 if (result == SQLResultInterrupt) |
| 63 es.throwUninformativeAndGenericDOMException(SQLDatabaseError); | 63 exceptionState.throwUninformativeAndGenericDOMException(SQLDatabaseE
rror); |
| 64 else | 64 else |
| 65 es.throwDOMException(SyntaxError, SQLError::syntaxErrorMessage); | 65 exceptionState.throwDOMException(SyntaxError, SQLError::syntaxErrorM
essage); |
| 66 db->setLastErrorMessage("could not prepare statement", result, database-
>lastErrorMsg()); | 66 db->setLastErrorMessage("could not prepare statement", result, database-
>lastErrorMsg()); |
| 67 return 0; | 67 return 0; |
| 68 } | 68 } |
| 69 | 69 |
| 70 if (statement.bindParameterCount() != m_arguments.size()) { | 70 if (statement.bindParameterCount() != m_arguments.size()) { |
| 71 if (db->isInterrupted()) | 71 if (db->isInterrupted()) |
| 72 es.throwUninformativeAndGenericDOMException(SQLDatabaseError); | 72 exceptionState.throwUninformativeAndGenericDOMException(SQLDatabaseE
rror); |
| 73 else | 73 else |
| 74 es.throwDOMException(SyntaxError, SQLError::syntaxErrorMessage); | 74 exceptionState.throwDOMException(SyntaxError, SQLError::syntaxErrorM
essage); |
| 75 db->setLastErrorMessage("number of '?'s in statement string does not mat
ch argument count"); | 75 db->setLastErrorMessage("number of '?'s in statement string does not mat
ch argument count"); |
| 76 return 0; | 76 return 0; |
| 77 } | 77 } |
| 78 | 78 |
| 79 for (unsigned i = 0; i < m_arguments.size(); ++i) { | 79 for (unsigned i = 0; i < m_arguments.size(); ++i) { |
| 80 result = statement.bindValue(i + 1, m_arguments[i]); | 80 result = statement.bindValue(i + 1, m_arguments[i]); |
| 81 if (result == SQLResultFull) { | 81 if (result == SQLResultFull) { |
| 82 es.throwDOMException(QuotaExceededError, SQLError::quotaExceededErro
rMessage); | 82 exceptionState.throwDOMException(QuotaExceededError, SQLError::quota
ExceededErrorMessage); |
| 83 db->setLastErrorMessage("there was not enough remaining storage spac
e"); | 83 db->setLastErrorMessage("there was not enough remaining storage spac
e"); |
| 84 return 0; | 84 return 0; |
| 85 } | 85 } |
| 86 | 86 |
| 87 if (result != SQLResultOk) { | 87 if (result != SQLResultOk) { |
| 88 es.throwUninformativeAndGenericDOMException(SQLDatabaseError); | 88 exceptionState.throwUninformativeAndGenericDOMException(SQLDatabaseE
rror); |
| 89 db->setLastErrorMessage("could not bind value", result, database->la
stErrorMsg()); | 89 db->setLastErrorMessage("could not bind value", result, database->la
stErrorMsg()); |
| 90 return 0; | 90 return 0; |
| 91 } | 91 } |
| 92 } | 92 } |
| 93 | 93 |
| 94 RefPtr<SQLResultSet> resultSet = SQLResultSet::create(); | 94 RefPtr<SQLResultSet> resultSet = SQLResultSet::create(); |
| 95 | 95 |
| 96 // Step so we can fetch the column names. | 96 // Step so we can fetch the column names. |
| 97 result = statement.step(); | 97 result = statement.step(); |
| 98 if (result == SQLResultRow) { | 98 if (result == SQLResultRow) { |
| 99 int columnCount = statement.columnCount(); | 99 int columnCount = statement.columnCount(); |
| 100 SQLResultSetRowList* rows = resultSet->rows(); | 100 SQLResultSetRowList* rows = resultSet->rows(); |
| 101 | 101 |
| 102 for (int i = 0; i < columnCount; i++) | 102 for (int i = 0; i < columnCount; i++) |
| 103 rows->addColumn(statement.getColumnName(i)); | 103 rows->addColumn(statement.getColumnName(i)); |
| 104 | 104 |
| 105 do { | 105 do { |
| 106 for (int i = 0; i < columnCount; i++) | 106 for (int i = 0; i < columnCount; i++) |
| 107 rows->addResult(statement.getColumnValue(i)); | 107 rows->addResult(statement.getColumnValue(i)); |
| 108 | 108 |
| 109 result = statement.step(); | 109 result = statement.step(); |
| 110 } while (result == SQLResultRow); | 110 } while (result == SQLResultRow); |
| 111 | 111 |
| 112 if (result != SQLResultDone) { | 112 if (result != SQLResultDone) { |
| 113 es.throwUninformativeAndGenericDOMException(SQLDatabaseError); | 113 exceptionState.throwUninformativeAndGenericDOMException(SQLDatabaseE
rror); |
| 114 db->setLastErrorMessage("could not iterate results", result, databas
e->lastErrorMsg()); | 114 db->setLastErrorMessage("could not iterate results", result, databas
e->lastErrorMsg()); |
| 115 return 0; | 115 return 0; |
| 116 } | 116 } |
| 117 } else if (result == SQLResultDone) { | 117 } else if (result == SQLResultDone) { |
| 118 // Didn't find anything, or was an insert. | 118 // Didn't find anything, or was an insert. |
| 119 if (db->lastActionWasInsert()) | 119 if (db->lastActionWasInsert()) |
| 120 resultSet->setInsertId(database->lastInsertRowID()); | 120 resultSet->setInsertId(database->lastInsertRowID()); |
| 121 } else if (result == SQLResultFull) { | 121 } else if (result == SQLResultFull) { |
| 122 // Quota error, the delegate will be asked for more space and this state
ment might be re-run. | 122 // Quota error, the delegate will be asked for more space and this state
ment might be re-run. |
| 123 es.throwDOMException(QuotaExceededError, SQLError::quotaExceededErrorMes
sage); | 123 exceptionState.throwDOMException(QuotaExceededError, SQLError::quotaExce
ededErrorMessage); |
| 124 db->setLastErrorMessage("there was not enough remaining storage space"); | 124 db->setLastErrorMessage("there was not enough remaining storage space"); |
| 125 return 0; | 125 return 0; |
| 126 } else if (result == SQLResultConstraint) { | 126 } else if (result == SQLResultConstraint) { |
| 127 es.throwDOMException(ConstraintError, "A constraint was violated."); | 127 exceptionState.throwDOMException(ConstraintError, "A constraint was viol
ated."); |
| 128 db->setLastErrorMessage("statement failed due to a constraint failure"); | 128 db->setLastErrorMessage("statement failed due to a constraint failure"); |
| 129 return 0; | 129 return 0; |
| 130 } else { | 130 } else { |
| 131 es.throwUninformativeAndGenericDOMException(SQLDatabaseError); | 131 exceptionState.throwUninformativeAndGenericDOMException(SQLDatabaseError
); |
| 132 db->setLastErrorMessage("could not execute statement", result, database-
>lastErrorMsg()); | 132 db->setLastErrorMessage("could not execute statement", result, database-
>lastErrorMsg()); |
| 133 return 0; | 133 return 0; |
| 134 } | 134 } |
| 135 | 135 |
| 136 resultSet->setRowsAffected(database->lastChanges()); | 136 resultSet->setRowsAffected(database->lastChanges()); |
| 137 return resultSet.release(); | 137 return resultSet.release(); |
| 138 } | 138 } |
| 139 | 139 |
| 140 } // namespace WebCore | 140 } // namespace WebCore |
| OLD | NEW |