Пример #1
0
  _fetch: function (opts) {
    var MAX_GET_LENGTH = 1024;
    this.trigger('loading', opts);

    var sql = this.getSQL();
    // if the query changes the database just send it
    if (cartoMetadataStatic.alterTableData(sql)) {
      TableDataCollection.prototype.fetch.call(this, opts);
      return;
    }

    // use get to fetch the schema, probably cached
    this._sqlQuery(_.template('select * from (<%= sql %>) __wrapped limit 0')({ sql: sql }), (data) => {
      // get schema
      this.query_schema = this._schemaFromQueryFields(data.fields);
      if (!this.table.isInSQLView()) {
        if ('the_geom' in this.query_schema) {
          delete this.query_schema['the_geom_webmercator'];
        }
      }
      TableDataCollection.prototype.fetch.call(this, opts);
    }, (err) => {
      this.trigger('error', this, err);
    }, sql.length > MAX_GET_LENGTH ? 'POST' : 'GET');
  },
Пример #2
0
  sync: function (method, model, options) {
    if (!options) { options = {}; }
    options.data = this._createUrlOptions(function (d) {
      return d !== 'sql';
    });

    if (cartoMetadataStatic.alterTableData(this.options.get('sql') || '')) {
      options.data += '&q=' + encodeURIComponent(this.options.get('sql'));
      options.type = 'POST';
    } else {
      // when a geometry can be lazy fetched, don't fetch it
      var fetchGeometry = 'cartodb_id' in this.query_schema;
      options.data += '&q=' + encodeURIComponent(this.wrappedSQL(this.query_schema, [], !fetchGeometry));

      if (options.data.length > 2048) {
        options.type = 'POST';
      }
    }

    return Backbone.sync.call(this, method, this, options);
  },