Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
larshp committed Sep 26, 2024
1 parent c421246 commit 9f584ab
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 7 deletions.
5 changes: 4 additions & 1 deletion packages/database-pg/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@ export class PostgresDatabaseClient implements DB.DatabaseClient {
}

public async delete(options: DB.DeleteDatabaseOptions): Promise<{ subrc: number; dbcnt: number; }> {
const sql = `DELETE FROM ${options.table} WHERE ${options.where}`;
let sql = `DELETE FROM ${options.table}`;
if (options.where !== "") {
sql += ` WHERE ${options.where}`;
}

let subrc = 0;
let dbcnt = 0;
Expand Down
5 changes: 4 additions & 1 deletion packages/database-sqlite/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ export class SQLiteDatabaseClient implements DB.DatabaseClient {
}

public async delete(options: DB.DeleteDatabaseOptions) {
const sql = `DELETE FROM ${options.table} WHERE ${options.where}`;
let sql = `DELETE FROM ${options.table}`;
if (options.where !== "") {
sql += ` WHERE ${options.where}`;
}

let subrc = 0;
let dbcnt = 0;
Expand Down
6 changes: 2 additions & 4 deletions packages/runtime/src/statements/delete_database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,15 @@ export async function deleteDatabase(table: string | ICharacter, options: IDelet
abap.builtin.sy.get().subrc.set(subrc);
// @ts-ignore
abap.builtin.sy.get().dbcnt.set(dbcnt);
} else if (options.where) {
} else {
const {subrc, dbcnt} = await context.defaultDB().delete({
table: buildDbTableName(table),
where: options.where,
where: options.where || "",
});

// @ts-ignore
abap.builtin.sy.get().subrc.set(subrc);
// @ts-ignore
abap.builtin.sy.get().dbcnt.set(dbcnt);
} else {
throw "deleteDatabase todo";
}
}
2 changes: 1 addition & 1 deletion packages/transpiler/src/statements/delete_database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export class DeleteDatabaseTranspiler implements IStatementTranspiler {
public transpile(node: abaplint.Nodes.StatementNode, traversal: Traversal): Chunk {
const dbtab = node.findFirstExpression(abaplint.Expressions.DatabaseTable);
if (dbtab === undefined) {
throw new Error("internal error, InsertDatabaseTranspiler");
throw new Error("internal error, DeleteDatabaseTranspiler");
}
const table = new DatabaseTableTranspiler(false).transpile(dbtab, traversal);

Expand Down
22 changes: 22 additions & 0 deletions test/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,28 @@ describe("Top level tests, Database", () => {
});
});

it.skip("test, DELETE no conditions", async () => {
const code = `
DATA tab TYPE STANDARD TABLE OF t100 WITH DEFAULT KEY.
DATA row LIKE LINE OF tab.
row-arbgb = 'SDFDEL'.
APPEND row TO tab.
MODIFY t100 FROM TABLE tab.
DELETE FROM t100.
SELECT SINGLE * FROM t100 INTO row.
WRITE / sy-subrc.`;
const files = [
{filename: "zfoobar.prog.abap", contents: code},
{filename: "t100.tabl.xml", contents: tabl_t100xml}];
await runAllDatabases(abap, files, () => {
const cons = abap.console.get();
expect(cons).to.equal("4");
});
});

it("SELECT SINGLE, WHERE char constant", async () => {
const code = `
DATA ls_result TYPE t100.
Expand Down

0 comments on commit 9f584ab

Please sign in to comment.