зеркало из https://github.com/mozilla/pjs.git
Bug 388048 - mozIStorageStatement::getParameterIndexes is useless. r=sspitzer
This commit is contained in:
Родитель
ee9773eb3e
Коммит
a829849d4f
|
@ -45,7 +45,7 @@ interface nsISimpleEnumerator;
|
|||
|
||||
[ptr] native sqlite3stmtptr(struct sqlite3_stmt);
|
||||
|
||||
[scriptable, uuid(1f39bc95-090d-40a5-9dee-6d5a591e48bf)]
|
||||
[scriptable, uuid(76b1b70e-5740-488d-b910-3f0f02ab2fd1)]
|
||||
interface mozIStorageStatement : mozIStorageValueArray {
|
||||
/**
|
||||
* Initialize this query with the given SQL statement.
|
||||
|
@ -74,12 +74,12 @@ interface mozIStorageStatement : mozIStorageValueArray {
|
|||
AUTF8String getParameterName(in unsigned long aParamIndex);
|
||||
|
||||
/**
|
||||
* All indexes of a named parameter, if it's specified more than once
|
||||
* Returns the index of the named parameter.
|
||||
*
|
||||
* @param aName The name of the parameter you want the index for.
|
||||
* @return The index of the named parameter.
|
||||
*/
|
||||
void getParameterIndexes
|
||||
(in AUTF8String aParameterName,
|
||||
out unsigned long aCount,
|
||||
[array,size_is(aCount),retval] out unsigned long aIndexes);
|
||||
unsigned long getParameterIndex(in AUTF8String aName);
|
||||
|
||||
/**
|
||||
* Number of columns returned
|
||||
|
|
|
@ -213,48 +213,19 @@ mozStorageStatement::GetParameterName(PRUint32 aParamIndex, nsACString & _retval
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
/* void getParameterIndexes(in AUTF8String aParameterName, out unsigned long aCount, [array,size_is(aCount),retval] out unsigned long aIndexes); */
|
||||
/* unsigned long getParameterIndex(in AUTF8String aParameterName); */
|
||||
NS_IMETHODIMP
|
||||
mozStorageStatement::GetParameterIndexes(const nsACString &aParameterName, PRUint32 *aCount, PRUint32 **aIndexes)
|
||||
mozStorageStatement::GetParameterIndex(const nsACString &aName,
|
||||
PRUint32 *_retval)
|
||||
{
|
||||
NS_ASSERTION (mDBConnection && mDBStatement, "statement not initialized");
|
||||
NS_ENSURE_ARG_POINTER(aCount);
|
||||
NS_ENSURE_ARG_POINTER(aIndexes);
|
||||
|
||||
nsCAutoString name(":");
|
||||
name.Append(aParameterName);
|
||||
|
||||
if (sqlite3_bind_parameter_index(mDBStatement, name.get()) == 0) {
|
||||
// Named parameter not found
|
||||
*aCount = 0;
|
||||
*aIndexes = nsnull;
|
||||
return NS_OK;
|
||||
}
|
||||
int ind = sqlite3_bind_parameter_index(mDBStatement,
|
||||
nsPromiseFlatCString(aName).get());
|
||||
if (ind == 0) // Named parameter not found
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
|
||||
int count = sqlite3_bind_parameter_count(mDBStatement);
|
||||
int *idxs = new int[count];
|
||||
if (!idxs)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
int size = 0;
|
||||
for (int i = 0; i < count; i++) {
|
||||
// sqlite indices start at 1
|
||||
const char *pName = sqlite3_bind_parameter_name(mDBStatement, i + 1);
|
||||
if (name.Equals(pName))
|
||||
idxs[size++] = i;
|
||||
}
|
||||
|
||||
*aCount = size;
|
||||
*aIndexes = (PRUint32*) NS_Alloc(sizeof(PRUint32) * size);
|
||||
if (!aIndexes) {
|
||||
delete[] idxs;
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
for (int i = 0; i < size; i++)
|
||||
(*aIndexes)[i] = idxs[i];
|
||||
|
||||
delete[] idxs;
|
||||
*_retval = ind - 1; // SQLite indexes are 1-based, we are 0-based
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
|
@ -60,31 +60,17 @@ function test_getParameterName()
|
|||
do_check_eq(":id", stmt.getParameterName(0));
|
||||
}
|
||||
|
||||
function test_getParameterIndexes_different()
|
||||
function test_getParameterIndex_different()
|
||||
{
|
||||
var stmt = createStatement("SELECT * FROM test WHERE id = :id OR name = :name");
|
||||
var count = { value: 0 };
|
||||
var result = stmt.getParameterIndexes("id", count);
|
||||
do_check_eq(1, count.value);
|
||||
do_check_eq(1, result.length);
|
||||
do_check_eq(0, result[0]);
|
||||
|
||||
result = stmt.getParameterIndexes("name", count);
|
||||
do_check_eq(1, count.value);
|
||||
do_check_eq(1, result.length);
|
||||
do_check_eq(1, result[0]);
|
||||
do_check_eq(0, stmt.getParameterIndex(":id"));
|
||||
do_check_eq(1, stmt.getParameterIndex(":name"));
|
||||
}
|
||||
|
||||
function test_getParameterIndexes_same()
|
||||
function test_getParameterIndex_same()
|
||||
{
|
||||
// XXX this looks like a bug in sqlite
|
||||
var stmt = createStatement("SELECT * FROM test WHERE id = :test OR name = :test");
|
||||
|
||||
var count = { value: 0 };
|
||||
var result = stmt.getParameterIndexes("test", count);
|
||||
do_check_eq(1, count.value);
|
||||
do_check_eq(1, result.length);
|
||||
do_check_eq(0, result[0]);
|
||||
var stmt = createStatement("SELECT * FROM test WHERE id = @test OR name = @test");
|
||||
do_check_eq(0, stmt.getParameterIndex("@test"));
|
||||
}
|
||||
|
||||
function test_columnCount()
|
||||
|
@ -124,8 +110,8 @@ function test_state_executing()
|
|||
}
|
||||
|
||||
var tests = [test_parameterCount_none, test_parameterCount_one,
|
||||
test_getParameterName, test_getParameterIndexes_different,
|
||||
test_getParameterIndexes_same, test_columnCount,
|
||||
test_getParameterName, test_getParameterIndex_different,
|
||||
test_getParameterIndex_same, test_columnCount,
|
||||
test_getColumnName, test_state_ready, test_state_executing];
|
||||
|
||||
function run_test()
|
||||
|
|
Загрузка…
Ссылка в новой задаче