Bug 543710 - Logging for XUL template based on storage; The patch to commit.

r=enndeakin sr=neil.
This commit is contained in:
Laurent Jouanneau 2010-03-09 01:02:27 +01:00
Родитель 36786bb6d6
Коммит 93ad3ca6ed
8 изменённых файлов: 233 добавлений и 7 удалений

Просмотреть файл

@ -106,6 +106,18 @@ class nsICollation;
"XPath expression in <assign> could not be parsed"
#define ERROR_TEMPLATE_BAD_BINDING_XPATH \
"XPath expression in <binding> could not be parsed"
#define ERROR_TEMPLATE_STORAGE_BAD_URI \
"only profile: or file URI are allowed"
#define ERROR_TEMPLATE_STORAGE_CANNOT_OPEN_DATABASE \
"cannot open given database"
#define ERROR_TEMPLATE_STORAGE_BAD_QUERY \
"syntax error in the SQL query"
#define ERROR_TEMPLATE_STORAGE_UNKNOWN_QUERY_PARAMETER \
"the given named parameter is unknown in the SQL query"
#define ERROR_TEMPLATE_STORAGE_WRONG_TYPE_QUERY_PARAMETER \
"the type of a query parameter is wrong"
#define ERROR_TEMPLATE_STORAGE_QUERY_PARAMETER_NOT_BOUND \
"a query parameter cannot be bound to the SQL query"
class nsXULContentUtils
{

Просмотреть файл

@ -53,6 +53,7 @@
#include "nsXULTemplateBuilder.h"
#include "nsXULTemplateResultStorage.h"
#include "nsXULContentUtils.h"
#include "mozIStorageService.h"
@ -248,7 +249,10 @@ nsXULTemplateQueryProcessorStorage::GetDatasource(nsIArray* aDataSources,
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIFileChannel> fileChannel = do_QueryInterface(channel, &rv);
NS_ENSURE_SUCCESS(rv, rv); // if it fails, not a file url
if (NS_FAILED(rv)) { // if it fails, not a file url
nsXULContentUtils::LogTemplateError(ERROR_TEMPLATE_STORAGE_BAD_URI);
return rv;
}
nsCOMPtr<nsIFile> file;
rv = fileChannel->GetFile(getter_AddRefs(databaseFile));
@ -258,7 +262,10 @@ nsXULTemplateQueryProcessorStorage::GetDatasource(nsIArray* aDataSources,
// ok now we have an URI of a sqlite file
nsCOMPtr<mozIStorageConnection> connection;
rv = storage->OpenDatabase(databaseFile, getter_AddRefs(connection));
NS_ENSURE_SUCCESS(rv, rv);
if (NS_FAILED(rv)) {
nsXULContentUtils::LogTemplateError(ERROR_TEMPLATE_STORAGE_CANNOT_OPEN_DATABASE);
return rv;
}
NS_ADDREF(*aReturn = connection);
return NS_OK;
@ -314,7 +321,10 @@ nsXULTemplateQueryProcessorStorage::CompileQuery(nsIXULTemplateBuilder* aBuilder
nsresult rv = mStorageConnection->CreateStatement(NS_ConvertUTF16toUTF8(sqlQuery),
getter_AddRefs(statement));
NS_ENSURE_SUCCESS(rv, rv);
if (NS_FAILED(rv)) {
nsXULContentUtils::LogTemplateError(ERROR_TEMPLATE_STORAGE_BAD_QUERY);
return rv;
}
PRUint32 parameterCount = 0;
PRUint32 count = queryContent->GetChildCount();
@ -332,7 +342,10 @@ nsXULTemplateQueryProcessorStorage::CompileQuery(nsIXULTemplateBuilder* aBuilder
if (child->GetAttr(kNameSpaceID_None, nsGkAtoms::name, name)) {
rv = statement->GetParameterIndex(NS_ConvertUTF16toUTF8(name),
&index);
NS_ENSURE_SUCCESS(rv, rv);
if (NS_FAILED(rv)) {
nsXULContentUtils::LogTemplateError(ERROR_TEMPLATE_STORAGE_UNKNOWN_QUERY_PARAMETER);
return rv;
}
parameterCount++;
}
else if (child->GetAttr(kNameSpaceID_None, nsGkAtoms::index, indexValue)) {
@ -348,7 +361,8 @@ nsXULTemplateQueryProcessorStorage::CompileQuery(nsIXULTemplateBuilder* aBuilder
{ &nsGkAtoms::int32, &nsGkAtoms::integer, &nsGkAtoms::int64,
&nsGkAtoms::null, &nsGkAtoms::double_, &nsGkAtoms::string, nsnull };
PRInt32 typeError, typeValue = child->FindAttrValueIn(kNameSpaceID_None, nsGkAtoms::type,
PRInt32 typeError = 1;
PRInt32 typeValue = child->FindAttrValueIn(kNameSpaceID_None, nsGkAtoms::type,
sTypeValues, eCaseMatters);
rv = NS_ERROR_ILLEGAL_VALUE;
PRInt32 valInt32 = 0;
@ -379,8 +393,19 @@ nsXULTemplateQueryProcessorStorage::CompileQuery(nsIXULTemplateBuilder* aBuilder
case nsIContent::ATTR_MISSING:
rv = statement->BindStringParameter(index, value);
break;
default:
typeError = 0;
}
if (typeError <= 0) {
nsXULContentUtils::LogTemplateError(ERROR_TEMPLATE_STORAGE_WRONG_TYPE_QUERY_PARAMETER);
return rv;
}
if (NS_FAILED(rv)) {
nsXULContentUtils::LogTemplateError(ERROR_TEMPLATE_STORAGE_QUERY_PARAMETER_NOT_BOUND);
return rv;
}
NS_ENSURE_SUCCESS(rv, rv);
}
}

Просмотреть файл

@ -159,6 +159,9 @@ _TEST_FILES = \
test_tmpl_sortquerymemberandtwotriples.xul \
test_tmpl_storage_baddatasource.xul \
test_tmpl_storage_badquery.xul \
test_tmpl_storage_bad_parameters.xul \
test_tmpl_storage_bad_parameters_2.xul \
test_tmpl_storage_bad_parameters_3.xul \
test_tmpl_storage_dynamicparameters.xul \
test_tmpl_storage_listbox.xul \
test_tmpl_storage_multiqueries.xul \

Просмотреть файл

@ -0,0 +1,57 @@
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?>
<!--
storage listbox with bad query parameters
-->
<window title="XUL Template Tests" width="500" height="600"
onload="test_template();"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript"
src="chrome://mochikit/content/MochiKit/packed.js"></script>
<script type="application/javascript"
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<body xmlns="http://www.w3.org/1999/xhtml" style="height: 300px; overflow: auto;"/>
<script src="templates_shared.js"/>
<script>
<![CDATA[
SimpleTest.waitForExplicitFinish();
var testid ="storage listbox with bad query parameters";
var queryType = "storage";
var isTreeBuilder = false;
var needsOpen = false;
var notWorkingYet = false;
var notWorkingYetDynamic = false;
var expectedOutput = <output></output>;
Components.classes["@mozilla.org/consoleservice;1"]
.getService(Components.interfaces.nsIConsoleService)
.reset();
expectedConsoleMessages.push("Error parsing template: the given named parameter is unknown in the SQL query");
var changes = [];
]]>
</script>
<listbox xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" id="root"
flex="1" datasources="animals.sqlite" ref="." querytype="storage">
<template>
<query>
SELECT * FROM animals WHERE species_id = ? ORDER BY name
<param name="bar">2</param>
</query>
<action>
<listitem uri="?" label="?name"/>
</action>
</template>
</listbox>
</window>

Просмотреть файл

@ -0,0 +1,57 @@
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?>
<!--
storage listbox with bad query parameters
-->
<window title="XUL Template Tests" width="500" height="600"
onload="test_template();"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript"
src="chrome://mochikit/content/MochiKit/packed.js"></script>
<script type="application/javascript"
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<body xmlns="http://www.w3.org/1999/xhtml" style="height: 300px; overflow: auto;"/>
<script src="templates_shared.js"/>
<script>
<![CDATA[
SimpleTest.waitForExplicitFinish();
var testid ="storage listbox with bad query parameters";
var queryType = "storage";
var isTreeBuilder = false;
var needsOpen = false;
var notWorkingYet = false;
var notWorkingYetDynamic = false;
var expectedOutput = <output></output>;
Components.classes["@mozilla.org/consoleservice;1"]
.getService(Components.interfaces.nsIConsoleService)
.reset();
expectedConsoleMessages.push("Error parsing template: the type of a query parameter is wrong");
var changes = [];
]]>
</script>
<listbox xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" id="root"
flex="1" datasources="animals.sqlite" ref="." querytype="storage">
<template>
<query>
SELECT * FROM animals WHERE species_id = ? ORDER BY name
<param type="mysupertype">2</param>
</query>
<action>
<listitem uri="?" label="?name"/>
</action>
</template>
</listbox>
</window>

Просмотреть файл

@ -0,0 +1,58 @@
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?>
<!--
storage listbox with bad query parameters
-->
<window title="XUL Template Tests" width="500" height="600"
onload="test_template();"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript"
src="chrome://mochikit/content/MochiKit/packed.js"></script>
<script type="application/javascript"
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<body xmlns="http://www.w3.org/1999/xhtml" style="height: 300px; overflow: auto;"/>
<script src="templates_shared.js"/>
<script>
<![CDATA[
SimpleTest.waitForExplicitFinish();
var testid ="storage listbox with bad query parameters";
var queryType = "storage";
var isTreeBuilder = false;
var needsOpen = false;
var notWorkingYet = false;
var notWorkingYetDynamic = false;
var expectedOutput = <output></output>;
Components.classes["@mozilla.org/consoleservice;1"]
.getService(Components.interfaces.nsIConsoleService)
.reset();
expectedConsoleMessages.push("Error parsing template: a query parameter cannot be bound to the SQL query");
var changes = [];
]]>
</script>
<listbox xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" id="root"
flex="1" datasources="animals.sqlite" ref="." querytype="storage">
<template>
<query>
SELECT * FROM animals WHERE species_id = :spec ORDER BY name
<param name="spec" type="int32">5</param>
<param>L%</param>
</query>
<action>
<listitem uri="?" label="?name"/>
</action>
</template>
</listbox>
</window>

Просмотреть файл

@ -30,13 +30,20 @@ var notWorkingYet = false;
var notWorkingYetDynamic = false;
var expectedOutput =<output></output>;
Components.classes["@mozilla.org/consoleservice;1"]
.getService(Components.interfaces.nsIConsoleService)
.reset();
expectedConsoleMessages.push("Error parsing template: only profile: or file URI are allowed");
var changes = [];
]]>
</script>
<listbox xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" id="root"
flex="1" rows="8"
datasources="animalsqsdqsdqsdq.sqlite" ref="." querytype="storage">
datasources="http://foo.local/animals.sqlite" ref="." querytype="storage">
<template>
<query>
SELECT * FROM animals WHERE species_id = 2 ORDER BY name

Просмотреть файл

@ -30,6 +30,13 @@ var notWorkingYet = false;
var notWorkingYetDynamic = false;
var expectedOutput =<output></output>;
Components.classes["@mozilla.org/consoleservice;1"]
.getService(Components.interfaces.nsIConsoleService)
.reset();
expectedConsoleMessages.push("Error parsing template: syntax error in the SQL query");
var changes = [];
]]>
</script>