Beispiel #1
0
  _fetchRowsData: function (model) {
    var attrsChanged = model && _.keys(model.changed);
    var altersData = SQLUtils.altersData(this._querySchemaModel.get('query'));
    var isCustomQueryApplied = this._tableViewModel.isCustomQueryApplied();
    var changeComeFromSortOrOrder = false;

    if (attrsChanged && (_.contains(attrsChanged, 'sort_order') || _.contains(attrsChanged, 'order_by'))) {
      changeComeFromSortOrOrder = true;
    }

    if (this._querySchemaModel.isFetched() && !altersData) {
      this._rowsCollection.fetch({
        data: {
          page: this._tableViewModel.get('page'),
          order_by: !isCustomQueryApplied || changeComeFromSortOrOrder ? this._tableViewModel.get('order_by') : '',
          sort_order: !isCustomQueryApplied || changeComeFromSortOrOrder ? this._tableViewModel.get('sort_order') : '',
          exclude: !isCustomQueryApplied || changeComeFromSortOrOrder ? ['the_geom_webmercator'] : []
        }
      });
    }
  },
Beispiel #2
0
  it('.altersData', function () {
    expect(SQLUtils.altersData('select * from blba')).toEqual(false);

    expect(SQLUtils.altersData('alter table add column blbla')).toEqual(true);
    expect(SQLUtils.altersData('vacuum full')).toEqual(true);

    expect(SQLUtils.altersData('refresh materialized view bar')).toEqual(true);
    expect(SQLUtils.altersData('truncate table')).toEqual(true);
    expect(SQLUtils.altersData('truncate schema.table')).toEqual(true);
    expect(SQLUtils.altersData('update aaa set a = 1')).toEqual(true);
    expect(SQLUtils.altersData('update table as whatvever set a = null')).toEqual(true);
    expect(SQLUtils.altersData('update  __ramen123123     set a = 1')).toEqual(true);
    expect(SQLUtils.altersData('insert into blaba values (1,2,3,4)')).toEqual(true);
    expect(SQLUtils.altersData('insert    into blaba values (1,2,3,4)')).toEqual(true);
    expect(SQLUtils.altersData('delete from bkna')).toEqual(true);
    expect(SQLUtils.altersData('update  schema.table  set a = 1')).toEqual(true);
    expect(SQLUtils.altersData('update  "schema".table  set a = 1')).toEqual(true);
    expect(SQLUtils.altersData('update  "schema"."table"  set a = 1')).toEqual(true);
    expect(SQLUtils.altersData('update  "schema-dash".table  set a = 1')).toEqual(true);
    expect(SQLUtils.altersData('update  "schema-dash"."table"  set a = 1')).toEqual(true);
    expect(SQLUtils.altersData('update  "schema-dash"."table" as at \n set a = 1')).toEqual(true);
  });
Beispiel #3
0
  _internalParseSQL: function (callbackAfterAlterSuccess) {
    var appliedQuery = this._querySchemaModel.get('query');
    var currentQuery = this._codemirrorModel.get('content');

    // Remove last character if it has ';'
    if (currentQuery && currentQuery.slice(-1) === ';') {
      currentQuery = currentQuery.slice(0, currentQuery.length - 1);
      this._codemirrorModel.set('content', currentQuery);
    }

    var isSameQuery = SQLUtils.isSameQuery(currentQuery, appliedQuery);
    var altersData = SQLUtils.altersData(currentQuery);

    if (currentQuery === '' || isSameQuery) {
      SQLNotifications.removeNotification();
      return false;
    }

    if (altersData) {
      SQLNotifications.showNotification({
        status: 'loading',
        info: _t('notifications.sql.alter-loading'),
        closable: false
      });

      this._applyButtonStatusModel.set('loading', true);

      this._sqlModel.set('content', currentQuery);

      this._SQL.execute(currentQuery, null, {
        success: function () {
          SQLNotifications.showNotification({
            status: 'success',
            info: _t('notifications.sql.alter-success'),
            closable: true,
            delay: Notifier.DEFAULT_DELAY
          });

          this._applyButtonStatusModel.set('loading', false);

          this._applyDefaultSQLAfterAlteringData();

          if (typeof callbackAfterAlterSuccess === 'function') {
            callbackAfterAlterSuccess.call(this);
          }
        }.bind(this),
        error: function (errors) {
          var parsedErrors = this._parseErrors(errors.responseJSON && errors.responseJSON.error);

          this._applyButtonStatusModel.set('loading', false);

          this._codemirrorModel.set('errors', parsedErrors);

          SQLNotifications.showErrorNotification(parsedErrors);

          this._checkClearButton();
        }.bind(this)
      });
    } else {
      this._runQuery(currentQuery, this._saveSQL.bind(this));
    }
  },