Skip to content
Permalink
Browse files

Issue #769: append ::text to JSON column names in PostgreSQL WHERE cl…

…auses. Fixes "Operator does not exist" errors
  • Loading branch information...
ansgarbecker committed Oct 20, 2019
1 parent 3f0db16 commit 46de6a29aca9a3d363b50b55243ae4d6bb39805e
Showing with 21 additions and 7 deletions.
  1. +5 −0 source/dbconnection.pas
  2. +16 −7 source/main.pas
@@ -7242,7 +7242,12 @@ function TDBQuery.GetWhereClause: String;
raise EDbError.CreateFmt(_('Cannot compose WHERE clause - column missing: %s'), [NeededCols[i]]);
if Result <> '' then
Result := Result + ' AND';

Result := Result + ' ' + Connection.QuoteIdent(FColumnOrgNames[j]);
if (DataType(j).Index = dtJson) and (Self is TPGQuery) then begin
Result := Result + '::text';
end;

if Modified(j) then begin
ColVal := FCurrentUpdateRow[j].OldText;
ColIsNull := FCurrentUpdateRow[j].OldIsNull;
@@ -6338,23 +6338,28 @@ procedure TMainForm.QuickFilterClick(Sender: TObject);
begin
// Set filter for "where..."-clause
Item := Sender as TMenuItem;
Col := DataGrid.Header.Columns[DataGrid.FocusedColumn].Text;
Filter := '';

if Item.Tag = 1 then begin
// Item needs prompt
Col := DataGrid.Header.Columns[DataGrid.FocusedColumn].Text;
Col := ActiveConnection.QuoteIdent(Col, False);
if (SelectedTableColumns[DataGrid.FocusedColumn].DataType.Index = dtJson)
and (ActiveConnection.Parameters.NetTypeGroup = ngPgSQL) then begin
Col := Col + '::text';
end;
Val := DataGrid.Text[DataGrid.FocusedNode, DataGrid.FocusedColumn];
if InputQuery(_('Specify filter-value...'), Item.Caption, Val) then begin
if Item = QF8 then
Filter := ActiveConnection.QuoteIdent(Col) + ' = ''' + Val + ''''
Filter := Col + ' = ''' + Val + ''''
else if Item = QF9 then
Filter := ActiveConnection.QuoteIdent(Col) + ' != ''' + Val + ''''
Filter := Col + ' != ''' + Val + ''''
else if Item = QF10 then
Filter := ActiveConnection.QuoteIdent(Col) + ' > ''' + Val + ''''
Filter := Col + ' > ''' + Val + ''''
else if Item = QF11 then
Filter := ActiveConnection.QuoteIdent(Col) + ' < ''' + Val + ''''
Filter := Col + ' < ''' + Val + ''''
else if Item = QF12 then
Filter := ActiveConnection.QuoteIdent(Col) + ' LIKE ''%' + Val + '%''';
Filter := Col + ' LIKE ''%' + Val + '%''';
end;
end else
Filter := Item.Hint;
@@ -6855,7 +6860,11 @@ procedure TMainForm.popupDataGridPopup(Sender: TObject);
Exit;
Results := GridResult(Grid);

Col := ActiveConnection.QuoteIdent(Results.ColumnOrgNames[Grid.FocusedColumn]);
Col := ActiveConnection.QuoteIdent(Results.ColumnOrgNames[Grid.FocusedColumn], False);
if (SelectedTableColumns[Grid.FocusedColumn].DataType.Index = dtJson)
and (ActiveConnection.Parameters.NetTypeGroup = ngPgSQL) then begin
Col := Col + '::text';
end;

// Block 1: WHERE col IN ([focused cell values])
QF1.Hint := '';

0 comments on commit 46de6a2

Please sign in to comment.
You can’t perform that action at this time.