Skip to content

Commit

Permalink
add basic support for providing a better error to the user in the cas…
Browse files Browse the repository at this point in the history
…e that a key_field is provided but it is not being used in a custom sql subquery - refs tilemill-project#1509
  • Loading branch information
Dane Springmeyer committed Jun 6, 2012
1 parent 92b3219 commit 53ceff5
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions models/Datasource.server.bones
Expand Up @@ -38,6 +38,17 @@ models.Datasource.prototype.sync = function(method, model, success, error) {
mml.Layer[0].Datasource = _(mml.Layer[0].Datasource).defaults({
row_limit: row_limit
});

// simplistic validation that subselects have the key_field string present
// not a proper parser, but this is not the right place to be parsing SQL
// https://github.com/mapbox/tilemill/issues/1509
if (mml.Layer[0].Datasource.table !== undefined
&& mml.Layer[0].Datasource.key_field !== undefined
&& mml.Layer[0].Datasource.table.match(/select /i)
&& mml.Layer[0].Datasource.table.search(mml.Layer[0].Datasource.key_field) == -1) {
return error(new Error("Your SQL subquery needs to contain the custom key_field supplied: '" + mml.Layer[0].Datasource.key_field + "'"));
}

var source = new mapnik.Datasource(mml.Layer[0].Datasource);

var features = [];
Expand Down

0 comments on commit 53ceff5

Please sign in to comment.