Skip to content

Commit

Permalink
Fixed problem when replacing multiple operators | #174
Browse files Browse the repository at this point in the history
  • Loading branch information
r-prem committed Jun 17, 2022
1 parent 2f3170e commit f73f3ed
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 12 deletions.
4 changes: 0 additions & 4 deletions src/calc2/components/editorBase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,6 @@ class Relation {
attributes: Attribute[];

constructor() {
console.log('called constructor...');
this.name = '';
this.attributes = [];
}
Expand All @@ -330,7 +329,6 @@ class Relation {
str = '{ ';
}
const rows = new Array<string>();
console.log(this.attributes);
for (let i = 0; i < (1 + this.attributes[0].data.length); i++) {
rows.push('');
}
Expand Down Expand Up @@ -404,7 +402,6 @@ class Relation {
this.attributes.push(attribute);
}
}
console.log(this.attributes);
}

}
Expand Down Expand Up @@ -1304,7 +1301,6 @@ export class EditorBase extends React.Component<Props, State> {
const { result } = this.props.execFunction(this, query, offset);
const end = Date.now() - start;
this.getResultForCsv(result.props.root);
console.log(result);
this.setState({
execResult: result,
execTime: end,
Expand Down
2 changes: 0 additions & 2 deletions src/calc2/components/editorRelalg.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,7 @@ export class EditorRelalg extends React.Component<Props, State> {
// replace text (text-magic)
if (editor.getDoc().somethingSelected() === false) {
const cursorOld: { line: number, ch: number } = editor.getDoc().getCursor();

const { query, cursor } = queryWithReplacedOperatorsFromAst(text, ast.operatorPositions, { line: cursorOld.line + 1, column: cursorOld.ch + 1 }, autoreplaceOperatorsMode);

if (query !== text) {
editor.setValue(query);
editor.getDoc().setCursor({ line: cursor.line - 1, ch: cursor.column - 1 });
Expand Down
1 change: 0 additions & 1 deletion src/calc2/components/editorSql.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ export class EditorSql extends React.Component<Props> {
execFunction={(self: EditorBase, text: string, offset) => {
const ast = parseSQLSelect(text);
replaceVariables(ast, relations);
console.log(self.state)

if (ast.child === null) {
if (ast.assignments.length > 0) {
Expand Down
3 changes: 1 addition & 2 deletions src/calc2/components/result.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,8 @@ export class Result extends React.Component<Props, State> {
}

render() {
const { root, numTreeLabelColors,execTime } = this.props;
const { root, numTreeLabelColors, execTime } = this.props;
const { activeNode } = this.state;
console.log(this.props)

const result = this.result(activeNode);

Expand Down
5 changes: 5 additions & 0 deletions src/calc2/views/landing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,11 @@ export class Landing extends React.Component {

<h2 id="changelog">Changelog</h2>
<ul>
<li>0.24 - Released 17.06.2022
<ul>
<li>Fixed problem when replacing multiple operators | #174</li>
</ul>
</li>
<li>0.23 - Released 16.06.2022
<ul>
<li>Added dataset from OTH Regensburg - Webshop</li>
Expand Down
4 changes: 1 addition & 3 deletions src/db/relalg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,10 @@ export function queryWithReplacedOperatorsFromAst(
'fullOuterJoinOperator': '⟗',
},
};

for (let i = operatorPositions.length - 1; i >= 0; i--) {
const op = operatorPositions[i];
const location = op.location; // = location without surrounding whitespace
const left = query.substr(0, location.start.offset);
const left = query.substr(0, location.start.offset - 1); // fixed offset | #174
const right = query.substring(location.end.offset);
const newOperator = (newOperators[mode] as any)[op.name]; // TODO: fix typings
const oldOperator = query.substring(location.start.offset, location.end.offset);
Expand Down Expand Up @@ -121,7 +120,6 @@ export function queryWithReplacedOperatorsFromAst(
cursor.line -= location.end.line - location.start.line;
}
}

// update query
query = left + newOperator + right;
}
Expand Down

0 comments on commit f73f3ed

Please sign in to comment.