Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
larshp committed Aug 9, 2023
1 parent f0e07db commit c294ddd
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 4 deletions.
50 changes: 50 additions & 0 deletions src/adbc/cl_sql_result_set.clas.abap
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
CLASS cl_sql_result_set DEFINITION PUBLIC.
PUBLIC SECTION.
METHODS set_param
IMPORTING
data_ref TYPE REF TO data
RAISING
cx_parameter_invalid.

METHODS next
RETURNING
VALUE(rows_ret) TYPE i
RAISING
cx_sql_exception.

METHODS close.
PRIVATE SECTION.
DATA mv_magic TYPE x LENGTH 1.
DATA mv_index TYPE i.
DATA mv_ref TYPE REF TO data.
ENDCLASS.

CLASS cl_sql_result_set IMPLEMENTATION.

METHOD set_param.
mv_ref = data_ref.
ENDMETHOD.

METHOD next.
* todo, more work needed here

DATA lv_total TYPE i.
DATA lv_value TYPE string.

WRITE '@KERNEL lv_total.set(this.mv_magic.length);'.
* WRITE '@KERNEL console.dir(this.mv_magic);'.
WRITE '@KERNEL const current = this.mv_magic[this.mv_index.get()];'.
WRITE '@KERNEL lv_value.set(Object.values(current)[0]);'.

mv_ref->* = lv_value.

mv_index = mv_index + 1.
rows_ret = lv_total - mv_index.
ENDMETHOD.

METHOD close.
* nothing here,
RETURN.
ENDMETHOD.

ENDCLASS.
35 changes: 35 additions & 0 deletions src/adbc/cl_sql_statement.clas.abap
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ CLASS cl_sql_statement DEFINITION PUBLIC.
statement TYPE string
RAISING
cx_sql_exception.

METHODS execute_query
IMPORTING
statement TYPE string
RETURNING
VALUE(result_set) TYPE REF TO cl_sql_result_set
RAISING
cx_sql_exception.
ENDCLASS.

CLASS cl_sql_statement IMPLEMENTATION.
Expand Down Expand Up @@ -33,4 +41,31 @@ CLASS cl_sql_statement IMPLEMENTATION.

ENDMETHOD.

METHOD execute_query.
DATA lv_sql_message TYPE string.

ASSERT statement IS NOT INITIAL.

WRITE '@KERNEL if (abap.context.databaseConnections["DEFAULT"] === undefined) {'.
lv_sql_message = 'not connected to db'.
WRITE '@KERNEL }'.
IF lv_sql_message IS NOT INITIAL.
RAISE EXCEPTION TYPE cx_sql_exception.
ENDIF.

CREATE OBJECT result_set.

WRITE '@KERNEL try {'.
WRITE '@KERNEL const res = await abap.context.databaseConnections["DEFAULT"].select({select: statement.get()});'.
* WRITE '@KERNEL console.dir(res.rows);'.
WRITE '@KERNEL result_set.get().mv_magic = res.rows;'.
WRITE '@KERNEL } catch(e) {'.
WRITE '@KERNEL lv_sql_message.set(e + "");'.
WRITE '@KERNEL }'.
IF lv_sql_message IS NOT INITIAL.
RAISE EXCEPTION TYPE cx_sql_exception.
ENDIF.

ENDMETHOD.

ENDCLASS.
20 changes: 16 additions & 4 deletions src/unit/osql/cl_osql_test_environment.clas.abap
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ CLASS cl_osql_test_environment IMPLEMENTATION.

METHOD initialize.

DATA lv_table LIKE LINE OF mt_tables.
DATA lv_table LIKE LINE OF mt_tables.
DATA lv_sql TYPE string.
DATA lo_result TYPE REF TO cl_sql_result_set.
DATA lr_ref TYPE REF TO data.

WRITE '@KERNEL if (abap.dbo.schemaPrefix !== "") throw new Error("already prefixed");'.

Expand All @@ -44,10 +47,19 @@ CLASS cl_osql_test_environment IMPLEMENTATION.

LOOP AT mt_tables INTO lv_table.
lv_table = to_lower( lv_table ).
mo_sql->execute_update( |CREATE TABLE { mv_schema }.{ lv_table } AS SELECT * FROM { lv_table } WHERE 0;| ).
ENDLOOP.

if_osql_test_environment~clear_doubles( ).
lo_result = mo_sql->execute_query( |SELECT sql FROM main.sqlite_master WHERE type='table' AND name='{ lv_table }';| ).
GET REFERENCE OF lv_sql INTO lr_ref.
lo_result->set_param( lr_ref ).
lo_result->next( ).
lo_result->close( ).

* WRITE / lv_sql.
REPLACE FIRST OCCURRENCE OF lv_table IN lv_sql WITH |{ mv_schema }.{ lv_table }|.
ASSERT sy-subrc = 0.

mo_sql->execute_update( lv_sql ).
ENDLOOP.

WRITE '@KERNEL abap.dbo.schemaPrefix = this.mv_schema.get() + ".";'.

Expand Down

0 comments on commit c294ddd

Please sign in to comment.