Skip to content

Commit

Permalink
Added formatting to eliminate extra zeros from odpi numbers. #604
Browse files Browse the repository at this point in the history
  • Loading branch information
acautin committed Aug 6, 2019
1 parent 88ba1b2 commit b45bc71
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 7 deletions.
56 changes: 49 additions & 7 deletions src/dderlodpi.erl
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,49 @@ cols_to_rec([#{
, type = Type
, prec = FsPrec
, readonly = ReadOnly} | cols_to_rec(Rest, NewFields)];
cols_to_rec([#{
name := AliasStr,
typeInfo := #{
oracleTypeNum := 'DPI_ORACLE_TYPE_NUMBER',
precision := 63,
scale := -127
}} | Rest], Fields
) ->
Alias = list_to_binary(AliasStr),
{Tag, ReadOnly, NewFields} = find_original_field(Alias, Fields),
[#stmtCol{ tag = Tag
, alias = Alias
, type = 'DPI_ORACLE_TYPE_NUMBER'
, len = 19
, prec = dynamic
, readonly = ReadOnly} | cols_to_rec(Rest, NewFields)];
cols_to_rec([#{
name := AliasStr,
typeInfo := #{
oracleTypeNum := 'DPI_ORACLE_TYPE_NUMBER',
scale := -127
}} | Rest], Fields
) ->
Alias = list_to_binary(AliasStr),
{Tag, ReadOnly, NewFields} = find_original_field(Alias, Fields),
[#stmtCol{ tag = Tag
, alias = Alias
, type = 'DPI_ORACLE_TYPE_NUMBER'
, len = 38
, prec = dynamic
, readonly = ReadOnly} | cols_to_rec(Rest, NewFields)];
cols_to_rec([#{
name := AliasStr,
typeInfo := #{
oracleTypeNum := Type
}} | Rest], Fields
) when Type =:= 'DPI_ORACLE_TYPE_NATIVE_DOUBLE'; Type =:= 'DPI_ORACLE_TYPE_NATIVE_FLOAT' ->
Alias = list_to_binary(AliasStr),
{Tag, ReadOnly, NewFields} = find_original_field(Alias, Fields),
[#stmtCol{ tag = Tag
, alias = Alias
, type = Type
, readonly = ReadOnly} | cols_to_rec(Rest, NewFields)];
cols_to_rec([#{
name := AliasStr,
typeInfo := #{
Expand Down Expand Up @@ -676,13 +719,12 @@ translate_datatype(Stmt, [R | RestRow], [#stmtCol{type = 'DPI_ORACLE_TYPE_TIMEST
[dpi_to_dderlts(R) | translate_datatype(Stmt, RestRow, RestCols)];
translate_datatype(Stmt, [R | RestRow], [#stmtCol{type = 'DPI_ORACLE_TYPE_DATE'} | RestCols]) ->
[dpi_to_dderltime(R) | translate_datatype(Stmt, RestRow, RestCols)];
translate_datatype(Stmt, [Mantissa | RestRow], [#stmtCol{type = 'SQLT_NUM', len = Scale, prec = dynamic} | RestCols]) ->
%% Float / Real type or unlimited numbers.
Number = dderloci_utils:clean_dynamic_prec(imem_datatype:decimal_to_io(Mantissa, Scale)),
[Number | translate_datatype(Stmt, RestRow, RestCols)];
translate_datatype(Stmt, [Mantissa | RestRow], [#stmtCol{type = 'SQLT_NUM', prec = Prec} | RestCols]) ->
Number = imem_datatype:decimal_to_io(Mantissa, Prec),
[Number | translate_datatype(Stmt, RestRow, RestCols)];
translate_datatype(Stmt, [Number | RestRow], [#stmtCol{type = Type} | RestCols]) when
Type =:= 'DPI_ORACLE_TYPE_NUMBER';
Type =:= 'DPI_ORACLE_TYPE_NATIVE_DOUBLE';
Type =:= 'DPI_ORACLE_TYPE_NATIVE_FLOAT' ->
Result = dderloci_utils:clean_dynamic_prec(float_to_binary(Number, [{decimals,20}, compact])),
[Result | translate_datatype(Stmt, RestRow, RestCols)];
translate_datatype(Stmt, [{_Pointer, Size, Path, Name} | RestRow], [#stmtCol{type = 'SQLT_BFILEE'} | RestCols]) ->
SizeBin = integer_to_binary(Size),
[<<Path/binary, $#, Name/binary, 32, $[, SizeBin/binary, $]>> | translate_datatype(Stmt, RestRow, RestCols)];
Expand Down
28 changes: 28 additions & 0 deletions src/gen_adapter.erl
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,34 @@ build_column_json([C|Cols], JCols, Counter) ->
'SQLT_LVC' -> Type = <<"text">>;
'SQLT_CLOB'-> Type = <<"text">>;
'SQLT_VST' -> Type = <<"text">>;
%% Oracle odpi types:
'DPI_ORACLE_TYPE_VARCHAR' -> Type = <<"text">>;
'DPI_ORACLE_TYPE_NVARCHAR' -> Type = <<"text">>;
'DPI_ORACLE_TYPE_CHAR' -> Type = <<"text">>;
'DPI_ORACLE_TYPE_NCHAR' -> Type = <<"text">>;
'DPI_ORACLE_TYPE_ROWID' -> Type = <<"text">>;
'DPI_ORACLE_TYPE_RAW' -> Type = <<"text">>;
'DPI_ORACLE_TYPE_NATIVE_FLOAT' -> Type = <<"numeric">>;
'DPI_ORACLE_TYPE_NATIVE_DOUBLE' -> Type = <<"numeric">>;
'DPI_ORACLE_TYPE_NATIVE_INT' -> Type = <<"numeric">>;
'DPI_ORACLE_TYPE_NATIVE_UINT' -> Type = <<"numeric">>;
'DPI_ORACLE_TYPE_NUMBER' -> Type = <<"numeric">>;
'DPI_ORACLE_TYPE_DATE' -> Type = <<"text">>;
'DPI_ORACLE_TYPE_TIMESTAMP' -> Type = <<"text">>;
'DPI_ORACLE_TYPE_TIMESTAMP_TZ' -> Type = <<"text">>;
'DPI_ORACLE_TYPE_TIMESTAMP_LTZ' -> Type = <<"text">>;
'DPI_ORACLE_TYPE_INTERVAL_DS' -> Type = <<"text">>;
'DPI_ORACLE_TYPE_INTERVAL_YM' -> Type = <<"text">>;
'DPI_ORACLE_TYPE_CLOB' -> Type = <<"text">>;
'DPI_ORACLE_TYPE_NCLOB' -> Type = <<"text">>;
'DPI_ORACLE_TYPE_BLOB' -> Type = <<"text">>;
'DPI_ORACLE_TYPE_BFILE' -> Type = <<"text">>;
'DPI_ORACLE_TYPE_STMT' -> Type = <<"text">>;
'DPI_ORACLE_TYPE_BOOLEAN' -> Type = <<"text">>;
'DPI_ORACLE_TYPE_OBJECT' -> Type = <<"text">>;
'DPI_ORACLE_TYPE_LONG_VARCHAR' -> Type = <<"text">>;
'DPI_ORACLE_TYPE_LONG_RAW' -> Type = <<"text">>;
%% Unknown types:
_ -> Type = <<"undefined">>
end,
JC = [{<<"id">>, Nm1},
Expand Down

0 comments on commit b45bc71

Please sign in to comment.