From 4e2a2a4654dece7f4269c8d6be3472ec27ae2635 Mon Sep 17 00:00:00 2001
From: Hernan
If automatic commit mode is turned on, each query will be considered as an individual transaction and will be automatically committed after it has been executed. If you want @@ -174,19 +174,23 @@ commit/3 explicitly to end a transaction.
The default timeout is infinity
- +>If the option binary_strings is turned on all strings will be returned as binaries and strings inputed to param_query will be expected to be binaries. The user needs to ensure that the binary is in an encoding that the database expects. By default this option is turned off.
- +As default result sets are returned as a lists of
tuples. The
>If the option integer_bigints is turned on, bigints will be + returned as integers instead of strings. By default this option is + turned off.
+Scrollable cursors are nice but causes some overhead. For
some connections speed might be more important than flexible
data access and then you can disable scrollable cursor for a
@@ -194,7 +198,7 @@
Turning the scrollable_cursors option off is noted
to make old odbc-drivers able to connect that will otherwhise fail.
If trace mode is turned on this tells the ODBC driver to write a trace log to the file SQL.LOG that is placed in the current directory of the erlang emulator. This information @@ -202,7 +206,7 @@ erlang ODBC application, and it might be relevant for you to send this file to our support. Otherwise you will probably not have much use of this.
- +For more information about the
Closes a connection to a database. This will also
- terminate all processes that may have been spawned
+ terminate all processes that may have been spawned
when the connection was opened. This call will always succeed.
If the connection cannot be disconnected gracefully it will
be brutally killed. However you may receive an error message
@@ -339,7 +343,7 @@
Executes a parameterized SQL query. For an
- example see the Use the function describe_table/[2,3] to find out which
@@ -374,12 +378,12 @@
Starts the odbc application. Default type
is temporary.
@@ -391,14 +395,14 @@
Stops the odbc application.
%%--------------------------------------------------------------------------
describe_table(ConnectionReference, Table) ->
describe_table(ConnectionReference, Table, ?DEFAULT_TIMEOUT).
-describe_table(ConnectionReference, Table, infinity) when
- is_pid(ConnectionReference), is_list(Table) ->
+describe_table(ConnectionReference, Table, infinity) when
+ is_pid(ConnectionReference), is_list(Table) ->
ODBCCmd = [?DESCRIBE, "SELECT * FROM " ++ Table],
call(ConnectionReference, {describe_table, ODBCCmd}, infinity);
-describe_table(ConnectionReference, Table, TimeOut)
- when is_pid(ConnectionReference),is_list(Table),is_integer(TimeOut),TimeOut>0 ->
+describe_table(ConnectionReference, Table, TimeOut)
+ when is_pid(ConnectionReference),is_list(Table),is_integer(TimeOut),TimeOut>0 ->
ODBCCmd = [?DESCRIBE, "SELECT * FROM " ++ Table],
call(ConnectionReference, {describe_table, ODBCCmd}, TimeOut).
%%%=========================================================================
%%% Start/stop
%%%=========================================================================
%%--------------------------------------------------------------------------
-%% start_link_sup(Args) -> {ok, Pid} | {error, Reason}
-%%
-%% Description: Callback function for the odbc supervisor. It is called
-%% : when connect/2 calls supervisor:start_child/2 to start an
+%% start_link_sup(Args) -> {ok, Pid} | {error, Reason}
+%%
+%% Description: Callback function for the odbc supervisor. It is called
+%% : when connect/2 calls supervisor:start_child/2 to start an
%% : instance of the erlang odbc control process.
%%--------------------------------------------------------------------------
start_link_sup(Args) ->
@@ -431,9 +437,9 @@ start_link_sup(Args) ->
init(Args) ->
process_flag(trap_exit, true),
{value, {client, ClientPid}} = lists:keysearch(client, 1, Args),
-
+
erlang:monitor(process, ClientPid),
-
+
Inet = case gen_tcp:listen(0, [inet6, {ip, loopback}]) of
{ok, Dummyport} ->
gen_tcp:close(Dummyport),
@@ -451,33 +457,33 @@ init(Args) ->
{active, false}, {nodelay, true},
{ip, loopback}]),
- %% Start the port program (a c program) that utilizes the odbc driver
+ %% Start the port program (a c program) that utilizes the odbc driver
case os:find_executable(?SERVERPROG, ?SERVERDIR) of
FileName when is_list(FileName)->
Port = open_port({spawn, "\""++FileName++"\""},
[{packet, ?LENGTH_INDICATOR_SIZE}, binary,
exit_status]),
- State = #state{listen_sockets =
+ State = #state{listen_sockets =
[ListenSocketSup, ListenSocketOdbc],
erlang_port = Port, owner = ClientPid},
{ok, State};
false ->
{stop, port_program_executable_not_found}
end.
-
+
%%--------------------------------------------------------------------------
%% handle_call(Request, From, State) -> {reply, Reply, State} |
%% {reply, Reply, State, Timeout} |
%% {noreply, State} |
%% {noreply, State, Timeout} |
%% {stop, Reason, Reply, State} |
-%% {stop, Reason, Reply, State}
+%% {stop, Reason, Reply, State}
%% Description: Handle incoming requests. Only requests from the process
%% that created the connection are allowed in order to preserve
%% the semantics of result sets.
%% Note: The order of the function clauses is significant.
%%--------------------------------------------------------------------------
-handle_call({Client, Msg, Timeout}, From, State =
+handle_call({Client, Msg, Timeout}, From, State =
#state{owner = Client, reply_to = undefined}) ->
handle_msg(Msg, Timeout, State#state{reply_to = From});
@@ -486,22 +492,22 @@ handle_call({Client, Msg, Timeout}, From, State =
%% request will be handled when we have received the answer to the
%% timed out request and thrown it away, if it has not already been
%% timed out itself in which case the request is thrown away.
-handle_call(Request = {Client, _, Timeout}, From,
+handle_call(Request = {Client, _, Timeout}, From,
State = #state{owner = Client, reply_to = skip,
num_timeouts = N}) when N < ?MAX_SEQ_TIMEOUTS ->
{noreply, State#state{pending_request = {Request, From}}, Timeout};
-%% The client has sent so many sequential requests that has timed out that
+%% The client has sent so many sequential requests that has timed out that
%% there might be something radically wrong causing the ODBC-driver to
-%% hang. So we give up and close the connection.
-handle_call({Client, _, _}, From,
- State = #state{owner = Client,
+%% hang. So we give up and close the connection.
+handle_call({Client, _, _}, From,
+ State = #state{owner = Client,
num_timeouts = N}) when N >= ?MAX_SEQ_TIMEOUTS ->
- gen_server:reply(From, {error, connection_closed}),
+ gen_server:reply(From, {error, connection_closed}),
{stop, too_many_sequential_timeouts, State#state{reply_to = undefined}};
handle_call(_, _, State) ->
- {reply, {error, process_not_owner_of_odbc_connection},
+ {reply, {error, process_not_owner_of_odbc_connection},
State#state{reply_to = undefined}}.
%%--------------------------------------------------------------------------
@@ -513,45 +519,45 @@ handle_msg({connect, ODBCCmd, AutoCommitMode, SrollableCursors},
Timeout, State) ->
[ListenSocketSup, ListenSocketOdbc] = State#state.listen_sockets,
-
+
%% Inform c-client so it knows where to send answers
{ok, InetPortSup} = inet:port(ListenSocketSup),
{ok, InetPortOdbc} = inet:port(ListenSocketOdbc),
-
- port_command(State#state.erlang_port,
- [integer_to_list(InetPortSup), ";",
+
+ port_command(State#state.erlang_port,
+ [integer_to_list(InetPortSup), ";",
integer_to_list(InetPortOdbc) , ?STR_TERMINATOR]),
-
+
NewState = State#state{auto_commit_mode = AutoCommitMode,
scrollable_cursors = SrollableCursors},
-
+
case gen_tcp:accept(ListenSocketSup, port_timeout()) of
{ok, SupSocket} ->
gen_tcp:close(ListenSocketSup),
case gen_tcp:accept(ListenSocketOdbc, port_timeout()) of
{ok, OdbcSocket} ->
gen_tcp:close(ListenSocketOdbc),
- odbc_send(OdbcSocket, ODBCCmd),
+ odbc_send(OdbcSocket, ODBCCmd),
{noreply, NewState#state{odbc_socket = OdbcSocket,
- sup_socket = SupSocket},
+ sup_socket = SupSocket},
Timeout};
{error, Reason} ->
{stop, Reason, {error, connection_closed}, NewState}
end;
{error, Reason} ->
{stop, Reason, {error, connection_closed}, NewState}
- end;
-
+ end;
+
handle_msg({disconnect, ODBCCmd}, Timeout, State) ->
odbc_send(State#state.odbc_socket, ODBCCmd),
{noreply, State#state{state = disconnecting}, Timeout};
-handle_msg({commit, _ODBCCmd}, Timeout,
+handle_msg({commit, _ODBCCmd}, Timeout,
State = #state{auto_commit_mode = on}) ->
- {reply, {error, not_an_explicit_commit_connection},
+ {reply, {error, not_an_explicit_commit_connection},
State#state{reply_to = undefined}, Timeout};
-handle_msg({commit, ODBCCmd}, Timeout,
+handle_msg({commit, ODBCCmd}, Timeout,
State = #state{auto_commit_mode = off}) ->
odbc_send(State#state.odbc_socket, ODBCCmd),
{noreply, State, Timeout};
@@ -577,7 +583,7 @@ handle_msg({select_cmd, absolute, ODBCCmd}, Timeout,
odbc_send(State#state.odbc_socket, ODBCCmd),
{noreply, State, Timeout};
-handle_msg({select_cmd, relative, ODBCCmd}, Timeout,
+handle_msg({select_cmd, relative, ODBCCmd}, Timeout,
State = #state{result_set = exists, relative_pos = true}) ->
odbc_send(State#state.odbc_socket, ODBCCmd),
{noreply, State, Timeout};
@@ -589,7 +595,7 @@ handle_msg({select_cmd, next, ODBCCmd}, Timeout,
handle_msg({select_cmd, _Type, _ODBCCmd}, _Timeout,
State = #state{result_set = undefined}) ->
- {reply, {error, result_set_does_not_exist},
+ {reply, {error, result_set_does_not_exist},
State#state{reply_to = undefined}};
handle_msg({select_cmd, _Type, _ODBCCmd}, _Timeout, State) ->
@@ -599,24 +605,24 @@ handle_msg({select_cmd, _Type, _ODBCCmd}, _Timeout, State) ->
off ->
{error, scrollable_cursors_disabled}
end,
-
+
{reply, Reply, State#state{reply_to = undefined}};
%---------------------------------------------------------------------------
-%% Catch all - This can oly happen if the application programmer writes
+%% Catch all - This can oly happen if the application programmer writes
%% really bad code that violates the API.
handle_msg(Request, _Timeout, State) ->
{stop, {'API_violation_connection_colsed', Request},
{error, connection_closed}, State#state{reply_to = undefined}}.
%%--------------------------------------------------------------------------
-%% handle_cast(Request, State) -> {noreply, State} |
+%% handle_cast(Request, State) -> {noreply, State} |
%% {noreply, State, Timeout} |
-%% {stop, Reason, State}
-%% Description: Handles cast messages.
+%% {stop, Reason, State}
+%% Description: Handles cast messages.
%% Note: The order of the function clauses is significant.
%%-------------------------------------------------------------------------
-%% Catch all - This can only happen if the application programmer writes
+%% Catch all - This can only happen if the application programmer writes
%% really bad code that violates the API.
handle_cast(Msg, State) ->
{stop, {'API_violation_connection_colsed', Msg}, State}.
@@ -628,21 +634,21 @@ handle_cast(Msg, State) ->
%% down messages.
%% Note: The order of the function clauses is significant.
%%--------------------------------------------------------------------------
-handle_info({tcp, Socket, BinData}, State = #state{state = connecting,
+handle_info({tcp, Socket, BinData}, State = #state{state = connecting,
reply_to = From,
odbc_socket = Socket}) ->
case binary_to_term(BinData) of
{ok, AbsolutSupport, RelativeSupport} ->
NewState = State#state{absolute_pos = AbsolutSupport,
relative_pos = RelativeSupport},
- gen_server:reply(From, ok),
+ gen_server:reply(From, ok),
{noreply, NewState#state{state = connected,
reply_to = undefined}};
Error ->
- gen_server:reply(From, Error),
+ gen_server:reply(From, Error),
{stop, normal, State#state{reply_to = undefined}}
end;
-
+
handle_info({tcp, Socket, _},
State = #state{state = connected,
@@ -656,9 +662,9 @@ handle_info({tcp, Socket, _},
handle_info({tcp, Socket, _},
State = #state{state = connected, odbc_socket = Socket,
reply_to = skip}) ->
-
+
%% Disregard this message as it is a answer to a query that has timed
- %% out and process the pending request.
+ %% out and process the pending request.
{{_, Msg, Timeout}, From} = State#state.pending_request,
handle_msg(Msg, Timeout, State#state{pending_request=undefined,
reply_to = From});
@@ -666,7 +672,7 @@ handle_info({tcp, Socket, _},
handle_info({tcp, Socket, BinData}, State = #state{state = connected,
reply_to = From,
odbc_socket = Socket}) ->
- %% Send the reply from the database (received by the erlang control
+ %% Send the reply from the database (received by the erlang control
%% process from the port program) to the waiting client.
gen_server:reply(From, BinData),
{noreply, State#state{reply_to = undefined,
@@ -676,36 +682,36 @@ handle_info({tcp, Socket, BinData}, State = #state{state = disconnecting,
reply_to = From,
odbc_socket = Socket}) ->
- %% The connection will always be closed
- gen_server:reply(From, ok),
-
+ %% The connection will always be closed
+ gen_server:reply(From, ok),
+
case binary_to_term(BinData) of
- ok ->
+ ok ->
ok;
{error, Reason} ->
- Report =
- io_lib:format("ODBC could not end connection "
+ Report =
+ io_lib:format("ODBC could not end connection "
"gracefully due to ~p~n", [Reason]),
error_logger:error_report(Report)
end,
-
+
{stop, normal, State#state{reply_to = undefined}};
-handle_info(timeout,
- State = #state{state = disconnecting,
+handle_info(timeout,
+ State = #state{state = disconnecting,
reply_to = From}) when From /= undefined ->
- gen_server:reply(From, ok),
- {stop, {timeout, "Port program is not responding to disconnect, "
+ gen_server:reply(From, ok),
+ {stop, {timeout, "Port program is not responding to disconnect, "
"will be killed"}, State};
-handle_info(timeout,
- State = #state{state = connecting,
+handle_info(timeout,
+ State = #state{state = connecting,
reply_to = From}) when From /= undefined ->
gen_server:reply(From, timeout),
{stop, normal, State#state{reply_to = undefined}};
-handle_info(timeout,
- State = #state{state = connected,
+handle_info(timeout,
+ State = #state{state = connected,
pending_request = undefined,
reply_to = From}) when From /= undefined ->
gen_server:reply(From, timeout),
@@ -713,8 +719,8 @@ handle_info(timeout,
num_timeouts = State#state.num_timeouts + 1}};
handle_info(timeout, State =
- #state{state = connected,
- pending_request = {{_, {disconnect, _}, _},
+ #state{state = connected,
+ pending_request = {{_, {disconnect, _}, _},
PendingFrom}}) ->
gen_server:reply(PendingFrom, ok),
{stop, {timeout, "Port-program busy when trying to disconnect, "
@@ -723,24 +729,24 @@ handle_info(timeout, State =
num_timeouts = State#state.num_timeouts + 1}};
handle_info(timeout, State =
- #state{state = connected,
+ #state{state = connected,
pending_request = {_, PendingFrom}}) ->
gen_server:reply(PendingFrom, timeout),
- %% The state variable reply_to should continue to have the value skip
- {noreply, State#state{pending_request = undefined,
+ %% The state variable reply_to should continue to have the value skip
+ {noreply, State#state{pending_request = undefined,
num_timeouts = State#state.num_timeouts + 1}};
-handle_info({Port, {exit_status, ?EXIT_SUCCESS}},
+handle_info({Port, {exit_status, ?EXIT_SUCCESS}},
State = #state{erlang_port = Port, state = disconnecting}) ->
- {noreply, State}; % Ignore as this is perfectly normal in this case
+ {noreply, State}; % Ignore as this is perfectly normal in this case
-handle_info({Port, {exit_status, Status}},
+handle_info({Port, {exit_status, Status}},
State = #state{erlang_port = Port}) ->
{stop, {port_exit, ?PORT_EXIT_REASON(Status)}, State};
handle_info({'EXIT', Port, _}, State = #state{erlang_port = Port,
state = disconnecting}) ->
- {noreply, State}; % Ignore as this is perfectly normal in this case
+ {noreply, State}; % Ignore as this is perfectly normal in this case
handle_info({'EXIT', Port, Reason}, State = #state{erlang_port = Port}) ->
{stop, Reason, State};
@@ -748,15 +754,15 @@ handle_info({'EXIT', Port, Reason}, State = #state{erlang_port = Port}) ->
%%% If the owning process dies there is no reson to go on
handle_info({'DOWN', _Ref, _Type, _Process, normal}, State) ->
{stop, normal, State#state{reply_to = undefined}};
-
+
handle_info({'DOWN', _Ref, _Type, _Process, timeout}, State) ->
{stop, normal, State#state{reply_to = undefined}};
handle_info({'DOWN', _Ref, _Type, _Process, shutdown}, State) ->
{stop, normal, State#state{reply_to = undefined}};
-
+
handle_info({'DOWN', _Ref, _Type, Process, Reason}, State) ->
- {stop, {stopped, {'EXIT', Process, Reason}},
+ {stop, {stopped, {'EXIT', Process, Reason}},
State#state{reply_to = undefined}};
handle_info({tcp_closed, Socket}, State = #state{odbc_socket=Socket,
@@ -765,7 +771,7 @@ handle_info({tcp_closed, Socket}, State = #state{odbc_socket=Socket,
%---------------------------------------------------------------------------
%% Catch all - throws away unknown messages (This could happen by "accident"
%% so we do not want to crash, but we make a log entry as it is an
-%% unwanted behaviour.)
+%% unwanted behaviour.)
handle_info(Info, State) ->
Report = io_lib:format("ODBC: received unexpected info: ~p~n", [Info]),
error_logger:error_report(Report),
@@ -783,7 +789,7 @@ terminate({port_exit, _Reason}, State = #state{reply_to = undefined}) ->
terminate(_Reason, State = #state{reply_to = undefined}) ->
- catch gen_tcp:send(State#state.sup_socket,
+ catch gen_tcp:send(State#state.sup_socket,
[?SHUTDOWN, ?STR_TERMINATOR]),
catch gen_tcp:close(State#state.odbc_socket),
catch gen_tcp:close(State#state.sup_socket),
@@ -804,23 +810,26 @@ code_change(_Vsn, State, _Extra) ->
%%%========================================================================
connect(ConnectionReferense, ConnectionStr, Options) ->
- {C_AutoCommitMode, ERL_AutoCommitMode} =
+ {C_AutoCommitMode, ERL_AutoCommitMode} =
connection_config(auto_commit, Options),
TimeOut = connection_config(timeout, Options),
{C_TraceDriver, _} = connection_config(trace_driver, Options),
- {C_SrollableCursors, ERL_SrollableCursors} =
+ {C_SrollableCursors, ERL_SrollableCursors} =
connection_config(scrollable_cursors, Options),
- {C_TupleRow, _} =
+ {C_TupleRow, _} =
connection_config(tuple_row, Options),
{BinaryStrings, _} = connection_config(binary_strings, Options),
{ExtendedErrors, _} = connection_config(extended_errors, Options),
+ {ReturnTypes, _} = connection_config(return_types, Options),
+ {IntegerBigInts, _} = connection_config(integer_bigints, Options),
+
+ ODBCCmd =
+ [?OPEN_CONNECTION, C_AutoCommitMode, C_TraceDriver,
+ C_SrollableCursors, C_TupleRow, BinaryStrings, ExtendedErrors, ReturnTypes,
+ IntegerBigInts, ConnectionStr],
- ODBCCmd =
- [?OPEN_CONNECTION, C_AutoCommitMode, C_TraceDriver,
- C_SrollableCursors, C_TupleRow, BinaryStrings, ExtendedErrors, ConnectionStr],
-
%% Send request, to open a database connection, to the control process.
- case call(ConnectionReferense,
+ case call(ConnectionReferense,
{connect, ODBCCmd, ERL_AutoCommitMode, ERL_SrollableCursors},
TimeOut) of
ok ->
@@ -832,17 +841,23 @@ connect(ConnectionReferense, ConnectionStr, Options) ->
%%-------------------------------------------------------------------------
odbc_send(Socket, Msg) -> %% Note currently all allowed messages are lists
NewMsg = Msg ++ [?STR_TERMINATOR],
- ok = gen_tcp:send(Socket, NewMsg),
+ case gen_tcp:send(Socket, NewMsg) of
+ ok -> ok;
+ {error, Reason} ->
+ erlang:error(#{event => odbc_send_failed,
+ reason => Reason,
+ msg => Msg})
+ end,
ok = inet:setopts(Socket, [{active, once}]).
%%--------------------------------------------------------------------------
connection_config(Key, Options) ->
case lists:keysearch(Key, 1, Options) of
- {value,{Key, on}} ->
+ {value, {Key, on}} ->
{?ON, on};
- {value,{Key, off}} ->
+ {value, {Key, off}} ->
{?OFF, off};
- {value,{Key, Value}} ->
+ {value, {Key, Value}} ->
Value;
_ ->
connection_default(Key)
@@ -856,7 +871,7 @@ connection_default(timeout) ->
?DEFAULT_TIMEOUT;
connection_default(tuple_row) ->
- {?ON, on};
+ {?ON, on};
connection_default(trace_driver) ->
{?OFF, off};
@@ -865,48 +880,52 @@ connection_default(scrollable_cursors) ->
{?ON, on};
connection_default(binary_strings) ->
{?OFF, off};
+connection_default(return_types) ->
+ {?OFF, off};
+connection_default(integer_bigints) ->
+ {?OFF, off};
connection_default(extended_errors) ->
{?OFF, off}.
%%-------------------------------------------------------------------------
call(ConnectionReference, Msg, Timeout) ->
-
- Result = (catch gen_server:call(ConnectionReference,
+
+ Result = (catch gen_server:call(ConnectionReference,
{self(), Msg, Timeout}, infinity)),
case Result of
- %% Normal case, the result from the port-program has directly
+ %% Normal case, the result from the port-program has directly
%% been forwarded to the client
- Binary when is_binary(Binary) ->
+ Binary when is_binary(Binary) ->
decode(Binary);
- timeout ->
+ timeout ->
exit(timeout);
{'EXIT', _} ->
{error, connection_closed};
%% At some occasions the erlang control process will have an
%% answer that was not directly received from the port-program.
- Term ->
+ Term ->
Term
- end.
+ end.
%%-------------------------------------------------------------------------
decode(Binary) ->
case binary_to_term(Binary) of
- [ResultSet | []] ->
+ [ResultSet | []] ->
ResultSet;
param_badarg ->
- exit({badarg, odbc, param_query, 'Params'});
+ exit({badarg, odbc, param_query, 'Params'});
MultipleResultSets_or_Other ->
MultipleResultSets_or_Other
end.
%%-------------------------------------------------------------------------
param_values(Params) ->
- case Params of
- [{_, Values} | _] ->
+ case Params of
+ [{_, Values} | _] ->
Values;
- [{_, _, Values} | _] ->
+ [{_, _, Values} | _] ->
Values;
- [] ->
+ [] ->
[]
end.
@@ -917,12 +936,12 @@ fix_params({sql_smallint, InOut, Values}) ->
{?USER_SMALL_INT, fix_inout(InOut), [256 | Values]};
fix_params({sql_tinyint, InOut, Values}) ->
{?USER_TINY_INT, fix_inout(InOut), [256 | Values]};
-fix_params({{sql_decimal, Precision, 0}, InOut,
+fix_params({{sql_decimal, Precision, 0}, InOut,
Values}) when Precision >= 0, Precision =< 9 ->
{?USER_DECIMAL, Precision, 0, fix_inout(InOut), [256 | Values]};
fix_params({{sql_decimal, Precision, Scale}, InOut, Values}) ->
{?USER_DECIMAL, Precision, Scale, fix_inout(InOut), Values};
-fix_params({{sql_numeric, Precision, 0}, InOut,
+fix_params({{sql_numeric, Precision, 0}, InOut,
Values}) when Precision >= 0, Precision =< 9 ->
{?USER_NUMERIC, Precision, 0, fix_inout(InOut), [256 | Values]};
fix_params({{sql_numeric, Precision, Scale}, InOut, Values}) ->
@@ -942,6 +961,8 @@ fix_params({{sql_wvarchar, Max}, InOut, Values}) ->
fix_params({{sql_wlongvarchar, Max}, InOut, Values}) ->
NewValues = string_terminate(Values),
{?USER_WLONGVARCHAR, Max, fix_inout(InOut), NewValues};
+fix_params({{sql_longvarbinary, Max}, InOut, Values}) ->
+ {?USER_LONGVARBINARY, Max, fix_inout(InOut), Values};
fix_params({{sql_float, Precision}, InOut, Values}) ->
{?USER_FLOAT, Precision, fix_inout(InOut), Values};
fix_params({sql_real, InOut, Values}) ->
@@ -952,7 +973,7 @@ fix_params({sql_bit, InOut, Values}) ->
{?USER_BOOLEAN, fix_inout(InOut), Values};
fix_params({'sql_timestamp', InOut, Values}) ->
NewValues =
- case (catch
+ case (catch
lists:map(
fun({{Year,Month,Day},{Hour,Minute,Second}}) ->
{Year,Month,Day,Hour,Minute,Second};
diff --git a/lib/odbc/src/odbc_internal.hrl b/lib/odbc/src/odbc_internal.hrl
index 2968c6ba54ce..35326187e4cb 100644
--- a/lib/odbc/src/odbc_internal.hrl
+++ b/lib/odbc/src/odbc_internal.hrl
@@ -19,13 +19,13 @@
%%
%
-%%
+%%
%% Path to the c-program.
-define(SERVERDIR, filename:nativename(
filename:join(code:priv_dir(odbc), "bin"))).
-%% Name of the C program
+%% Name of the C program
-define(SERVERPROG, "odbcserver").
%% Constats defining the command protocol between the erlang control
@@ -74,8 +74,9 @@
-define(USER_WVARCHAR, 13).
-define(USER_TIMESTAMP, 14).
-define(USER_WLONGVARCHAR, 15).
+-define(USER_LONGVARBINARY, 16).
-%% INPUT & OUTPUT TYPE
+%% INPUT & OUTPUT TYPE
-define(IN, 0).
-define(OUT, 1).
-define(INOUT, 2).
@@ -93,7 +94,7 @@
-define(EXIT_THREAD, 9).
-define(EXIT_PARAM_ARRAY, 10).
-define(EXIT_OLD_WINSOCK, 11).
--define(EXIT_SOCKET_CONNECT, 12).
+-define(EXIT_SOCKET_CONNECT, 12).
-define(EXIT_SOCKET_SEND_HEADER, 13).
-define(EXIT_SOCKET_SEND_BODY, 14).
-define(EXIT_SOCKET_RECV_MSGSIZE,15).
@@ -105,6 +106,7 @@
-define(EXIT_DESC, 21).
-define(EXIT_BIND, 22).
-define(EXIT_DRIVER_INFO, 23).
+-define(EXIT_LONG_DATA, 40).
%% Misc constants
-define(DEFAULT_TIMEOUT, infinity).
@@ -112,7 +114,7 @@
-define(MAX_SEQ_TIMEOUTS, 10).
%% Handling of C exit codes
--define(ENCODE_EXIT_FUN,
+-define(ENCODE_EXIT_FUN,
(fun(?EXIT_SUCCESS) ->
normal_exit;
(?EXIT_FAILURE) ->
@@ -161,9 +163,11 @@
could_not_bind_data_buffers;
(?EXIT_DRIVER_INFO) ->
collecting_of_driver_information_faild;
+ (?EXIT_LONG_DATA) ->
+ extracting_long_data_failed;
(_) ->
killed
end)).
--define(PORT_EXIT_REASON(EXIT_STATUS),
+-define(PORT_EXIT_REASON(EXIT_STATUS),
?ENCODE_EXIT_FUN(EXIT_STATUS)).
diff --git a/lib/odbc/test/mysql.erl b/lib/odbc/test/mysql.erl
index 69b136e74380..7abdddc9cd2c 100644
--- a/lib/odbc/test/mysql.erl
+++ b/lib/odbc/test/mysql.erl
@@ -193,6 +193,9 @@ bit_false_selected() ->
bit_true_selected() ->
{selected,["FIELD"], [{"1"}]}.
+non_bit_promotes_to() ->
+ error.
+
%-------------------------------------------------------------------------
%% Do not test float min/max as value is only theoretical defined in
@@ -222,6 +225,15 @@ create_real_table() ->
real_zero_selected() ->
{selected,["FIELD"],[{0.00000e+0}]}.
+%-------------------------------------------------------------------------
+% Only really works with a subset of the possible precision and scale combinations
+% It should ideally mirror the function map_dec_num_2_c_column
+expected_value(Precision, _Scale, In) when Precision > 15 ->
+ erlang:float_to_list(In);
+
+expected_value(_Precision, _Scale, In) ->
+ In.
+
%-------------------------------------------------------------------------
param_select_small_int() ->
{selected,["FIELD"],[{1}, {2}]}.
diff --git a/lib/odbc/test/odbc_data_type_SUITE.erl b/lib/odbc/test/odbc_data_type_SUITE.erl
index a3a4bc78eb24..814b1787aec4 100644
--- a/lib/odbc/test/odbc_data_type_SUITE.erl
+++ b/lib/odbc/test/odbc_data_type_SUITE.erl
@@ -33,15 +33,15 @@
%% all(Arg) -> [Doc] | [Case] | {skip, Comment}
%% Arg - doc | suite
%% Doc - string()
-%% Case - atom()
-%% Name of a test case function.
+%% Case - atom()
+%% Name of a test case function.
%% Comment - string()
%% Description: Returns documentation/test cases in this test suite
-%% or a skip tuple if the platform is not supported.
+%% or a skip tuple if the platform is not supported.
%%--------------------------------------------------------------------
suite() -> [{ct_hooks,[ts_install_cth]}].
-all() ->
+all() ->
case odbc_test_lib:odbc_check() of
ok ->
[{group, char},{group, fixed_char}, {group, binary_char},
@@ -51,7 +51,7 @@ all() ->
Other -> {skip, Other}
end.
-groups() ->
+groups() ->
[{char, [],
[varchar_lower_limit,
varchar_upper_limit, varchar_no_padding,
@@ -192,15 +192,15 @@ init_per_testcase(Case, Config) ->
common_init_per_testcase(Case, Config) ->
PlatformOptions = odbc_test_lib:platform_options(),
- {ok, Ref} =
+ {ok, Ref} =
case atom_to_list(Case) of
"binary" ++ _ ->
- odbc:connect(?RDBMS:connection_string(),
+ odbc:connect(?RDBMS:connection_string(),
[{binary_strings, on}] ++ PlatformOptions);
LCase when LCase == "utf8";
LCase == "nchar";
LCase == "nvarchar" ->
- odbc:connect(?RDBMS:connection_string(),
+ odbc:connect(?RDBMS:connection_string(),
[{binary_strings, on}] ++ PlatformOptions);
_ ->
odbc:connect(?RDBMS:connection_string(), PlatformOptions)
@@ -233,10 +233,10 @@ is_supported_bit(_) ->
end_per_testcase(_TestCase, Config) ->
Ref = proplists:get_value(connection_ref, Config),
ok = odbc:disconnect(Ref),
- %% Clean up if needed
+ %% Clean up if needed
Table = proplists:get_value(tableName, Config),
{ok, NewRef} = odbc:connect(?RDBMS:connection_string(), odbc_test_lib:platform_options()),
- odbc:sql_query(NewRef, "DROP TABLE " ++ Table),
+ odbc:sql_query(NewRef, "DROP TABLE " ++ Table),
odbc:disconnect(NewRef).
%%-------------------------------------------------------------------------
@@ -246,23 +246,23 @@ end_per_testcase(_TestCase, Config) ->
char_fixed_lower_limit() ->
[{doc,"Tests fixed length char data type lower boundaries."}].
char_fixed_lower_limit(Config) when is_list(Config) ->
- Ref = proplists:get_value(connection_ref, Config),
+ Ref = proplists:get_value(connection_ref, Config),
Table = proplists:get_value(tableName, Config),
%% Below limit
- {error, _} =
- odbc:sql_query(Ref,
- "CREATE TABLE " ++ Table ++
+ {error, _} =
+ odbc:sql_query(Ref,
+ "CREATE TABLE " ++ Table ++
?RDBMS:create_fixed_char_table(
- (?RDBMS:fixed_char_min() - 1))),
+ (?RDBMS:fixed_char_min() - 1))),
%% Lower limit
{updated, _} = % Value == 0 || -1 driver dependent!
- odbc:sql_query(Ref, "CREATE TABLE " ++ Table ++
+ odbc:sql_query(Ref, "CREATE TABLE " ++ Table ++
?RDBMS:create_fixed_char_table(
?RDBMS:fixed_char_min())),
%% Right length data
- {updated, _} =
+ {updated, _} =
odbc:sql_query(Ref, "INSERT INTO " ++ Table ++" VALUES(" ++
"'" ++ string:chars($a, ?RDBMS:fixed_char_min())
++ "')"),
@@ -273,7 +273,7 @@ char_fixed_lower_limit(Config) when is_list(Config) ->
["FIELD"] = odbc_test_lib:to_upper(Fields),
%% Too long data
- {error, _} =
+ {error, _} =
odbc:sql_query(Ref,"INSERT INTO " ++ Table ++" VALUES(" ++
"'" ++ string:chars($a,
(?RDBMS:fixed_char_min()
@@ -290,40 +290,40 @@ char_fixed_upper_limit(Config) when is_list(Config) ->
postgres ->
{skip, "Limit unknown"};
_ ->
- Ref = proplists:get_value(connection_ref, Config),
+ Ref = proplists:get_value(connection_ref, Config),
Table = proplists:get_value(tableName, Config),
-
- %% Upper limit
+
+ %% Upper limit
{updated, _} = % Value == 0 || -1 driver dependent!
- odbc:sql_query(Ref, "CREATE TABLE " ++ Table ++
+ odbc:sql_query(Ref, "CREATE TABLE " ++ Table ++
?RDBMS:create_fixed_char_table(
- ?RDBMS:fixed_char_max())),
- {updated, _} =
- odbc:sql_query(Ref,"INSERT INTO " ++ Table ++" VALUES(" ++
- "'" ++ string:chars($a,
+ ?RDBMS:fixed_char_max())),
+ {updated, _} =
+ odbc:sql_query(Ref,"INSERT INTO " ++ Table ++" VALUES(" ++
+ "'" ++ string:chars($a,
?RDBMS:fixed_char_max())
++ "')"),
%% Select data
{selected, Fields, [{CharStr}]} =
odbc:sql_query(Ref,"SELECT FIELD FROM " ++ Table),
true = length(CharStr) == ?RDBMS:fixed_char_max(),
-
+
["FIELD"] = odbc_test_lib:to_upper(Fields),
-
+
%% Too long data
- {error, _} =
- odbc:sql_query(Ref, "INSERT INTO " ++ Table ++" VALUES(" ++
- "'" ++ string:chars($a,
+ {error, _} =
+ odbc:sql_query(Ref, "INSERT INTO " ++ Table ++" VALUES(" ++
+ "'" ++ string:chars($a,
(?RDBMS:fixed_char_max()
- + 1))
- ++ "')"),
+ + 1))
+ ++ "')"),
%% Clean up
{updated, _} = % Value == 0 || -1 driver dependent!
odbc:sql_query(Ref, "DROP TABLE " ++ Table),
-
- %% Above limit
+
+ %% Above limit
{error, _} =
- odbc:sql_query(Ref, "CREATE TABLE " ++ Table ++
+ odbc:sql_query(Ref, "CREATE TABLE " ++ Table ++
?RDBMS:create_fixed_char_table(
(?RDBMS:fixed_char_max() + 1)))
end.
@@ -331,20 +331,20 @@ char_fixed_upper_limit(Config) when is_list(Config) ->
%%-------------------------------------------------------------------------
char_fixed_padding() ->
- [{doc, "Tests that data that is shorter than the given size is padded "
+ [{doc, "Tests that data that is shorter than the given size is padded "
"with blanks."}].
char_fixed_padding(Config) when is_list(Config) ->
- Ref = proplists:get_value(connection_ref, Config),
+ Ref = proplists:get_value(connection_ref, Config),
Table = proplists:get_value(tableName, Config),
%% Data should be padded with blanks
{updated, _} = % Value == 0 || -1 driver dependent!
- odbc:sql_query(Ref, "CREATE TABLE " ++ Table ++
+ odbc:sql_query(Ref, "CREATE TABLE " ++ Table ++
?RDBMS:create_fixed_char_table(
?RDBMS:fixed_char_max())),
{updated, _} =
- odbc:sql_query(Ref, "INSERT INTO " ++ Table ++" VALUES(" ++
+ odbc:sql_query(Ref, "INSERT INTO " ++ Table ++" VALUES(" ++
"'" ++ string:chars($a,
?RDBMS:fixed_char_min())
++ "')"),
@@ -359,30 +359,30 @@ char_fixed_padding(Config) when is_list(Config) ->
varchar_lower_limit() ->
[{doc,"Tests variable length char data type lower boundaries."}].
varchar_lower_limit(Config) when is_list(Config) ->
- Ref = proplists:get_value(connection_ref, Config),
+ Ref = proplists:get_value(connection_ref, Config),
Table = proplists:get_value(tableName, Config),
%% Below limit
- {error, _} =
+ {error, _} =
odbc:sql_query(Ref, "CREATE TABLE " ++ Table ++
?RDBMS:create_var_char_table(
?RDBMS:var_char_min() - 1)),
%% Lower limit
{updated, _} = % Value == 0 || -1 driver dependent!
- odbc:sql_query(Ref, "CREATE TABLE " ++ Table ++
+ odbc:sql_query(Ref, "CREATE TABLE " ++ Table ++
?RDBMS:create_var_char_table(
?RDBMS:var_char_min())),
Str = string:chars($a, ?RDBMS:var_char_min()),
%% Right length data
- {updated, _} =
- odbc:sql_query(Ref, "INSERT INTO " ++ Table ++" VALUES(" ++
+ {updated, _} =
+ odbc:sql_query(Ref, "INSERT INTO " ++ Table ++" VALUES(" ++
"'" ++ Str ++ "')"),
%% Select data
{selected, Fields, [{Str}]} =
odbc:sql_query(Ref,"SELECT FIELD FROM " ++ Table),
-
+
["FIELD"] = odbc_test_lib:to_upper(Fields),
%% Too long datae
@@ -397,7 +397,7 @@ varchar_lower_limit(Config) when is_list(Config) ->
varchar_upper_limit() ->
[{doc,"Tests variable length char data type upper boundaries."}].
varchar_upper_limit(Config) when is_list(Config) ->
- Ref = proplists:get_value(connection_ref, Config),
+ Ref = proplists:get_value(connection_ref, Config),
Table = proplists:get_value(tableName, Config),
case ?RDBMS of
@@ -406,36 +406,36 @@ varchar_upper_limit(Config) when is_list(Config) ->
postgres ->
{skip, "Limit unknown"};
_ ->
- %% Upper limit
+ %% Upper limit
{updated, _} = % Value == 0 || -1 driver dependent!
- odbc:sql_query(Ref, "CREATE TABLE " ++ Table ++
+ odbc:sql_query(Ref, "CREATE TABLE " ++ Table ++
?RDBMS:create_var_char_table(
- ?RDBMS:var_char_max())),
- {updated, _} =
- odbc:sql_query(Ref, "INSERT INTO " ++ Table ++" VALUES(" ++
- "'" ++ string:chars($a,
+ ?RDBMS:var_char_max())),
+ {updated, _} =
+ odbc:sql_query(Ref, "INSERT INTO " ++ Table ++" VALUES(" ++
+ "'" ++ string:chars($a,
?RDBMS:var_char_max())
++ "')"),
-
+
{selected, Fields, [{CharStr}]} =
odbc:sql_query(Ref,"SELECT FIELD FROM " ++ Table),
true = length(CharStr) == ?RDBMS:var_char_max(),
-
+
["FIELD"] = odbc_test_lib:to_upper(Fields),
-
+
%% Too long data
- {error, _} =
- odbc:sql_query(Ref, "INSERT INTO " ++ Table ++" VALUES(" ++
- "'" ++ string:chars($a,
- (?RDBMS:var_char_max()+1))
+ {error, _} =
+ odbc:sql_query(Ref, "INSERT INTO " ++ Table ++" VALUES(" ++
+ "'" ++ string:chars($a,
+ (?RDBMS:var_char_max()+1))
++ "')"),
%% Clean up
{updated, _} = % Value == 0 || -1 driver dependent!
- odbc:sql_query(Ref, "DROP TABLE " ++ Table),
-
- %% Above limit
+ odbc:sql_query(Ref, "DROP TABLE " ++ Table),
+
+ %% Above limit
{error, _} =
- odbc:sql_query(Ref, "CREATE TABLE " ++ Table ++
+ odbc:sql_query(Ref, "CREATE TABLE " ++ Table ++
?RDBMS:create_var_char_table(
(?RDBMS:var_char_max() + 1))),
ok
@@ -443,19 +443,19 @@ varchar_upper_limit(Config) when is_list(Config) ->
%%-------------------------------------------------------------------------
varchar_no_padding() ->
- [{doc, "Tests that data that is shorter than the given max size is not padded "
+ [{doc, "Tests that data that is shorter than the given max size is not padded "
"with blanks."}].
varchar_no_padding(Config) when is_list(Config) ->
- Ref = proplists:get_value(connection_ref, Config),
+ Ref = proplists:get_value(connection_ref, Config),
Table = proplists:get_value(tableName, Config),
%% Data should NOT be padded with blanks
{updated, _} = % Value == 0 || -1 driver dependent!
- odbc:sql_query(Ref, "CREATE TABLE " ++ Table ++
+ odbc:sql_query(Ref, "CREATE TABLE " ++ Table ++
?RDBMS:create_var_char_table(
- ?RDBMS:var_char_max())),
- {updated, _} =
- odbc:sql_query(Ref, "INSERT INTO " ++ Table ++" VALUES(" ++
+ ?RDBMS:var_char_max())),
+ {updated, _} =
+ odbc:sql_query(Ref, "INSERT INTO " ++ Table ++" VALUES(" ++
"'" ++ string:chars($a, ?RDBMS:var_char_min())
++ "')"),
@@ -469,15 +469,15 @@ varchar_no_padding(Config) when is_list(Config) ->
text_lower_limit() ->
[{doc,"Tests 'long' char data type lower boundaries."}].
text_lower_limit(Config) when is_list(Config) ->
- Ref = proplists:get_value(connection_ref, Config),
+ Ref = proplists:get_value(connection_ref, Config),
Table = proplists:get_value(tableName, Config),
{updated, _} = % Value == 0 || -1 driver dependent!
- odbc:sql_query(Ref, "CREATE TABLE " ++ Table ++
- ?RDBMS:create_text_table()),
+ odbc:sql_query(Ref, "CREATE TABLE " ++ Table ++
+ ?RDBMS:create_text_table()),
- {updated, _} =
- odbc:sql_query(Ref, "INSERT INTO " ++ Table ++" VALUES(" ++
+ {updated, _} =
+ odbc:sql_query(Ref, "INSERT INTO " ++ Table ++" VALUES(" ++
"'" ++ string:chars($a, ?RDBMS:text_min())
++ "')"),
@@ -490,16 +490,16 @@ text_lower_limit(Config) when is_list(Config) ->
text_upper_limit() ->
[{doc,"Tests 'text' char data type upper boundaries."}].
text_upper_limit(Config) when is_list(Config) ->
-
+
{skip,"Consumes too much resources" }.
%% Ref = proplists:get_value(connection_ref, Config),
%% Table = proplists:get_value(tableName, Config),
%% {updated, _} = % Value == 0 || -1 driver dependent!
-%% odbc:sql_query(Ref, "CREATE TABLE " ++ Table ++
-%% ?RDBMS:create_text_table()),
-%% {updated, _} =
-%% odbc:sql_query(Ref, "INSERT INTO " ++ Table ++" VALUES(" ++
+%% odbc:sql_query(Ref, "CREATE TABLE " ++ Table ++
+%% ?RDBMS:create_text_table()),
+%% {updated, _} =
+%% odbc:sql_query(Ref, "INSERT INTO " ++ Table ++" VALUES(" ++
%% "'" ++ string:chars($a, ?RDBMS:text_max())
%% ++ "')"),
@@ -507,10 +507,10 @@ text_upper_limit(Config) when is_list(Config) ->
%% odbc:sql_query(Ref,"SELECT FIELD FROM " ++ Table),
%% length(CharStr) == ?RDBMS:text_max(),
%% ["FIELD"] = odbc_test_lib:to_upper(Fields),
-
-%% {error, _} =
-%% odbc:sql_query(Ref, "INSERT INTO " ++ Table ++" VALUES(" ++
-%% "'" ++ string:chars($a, (?RDBMS:text_max()+1))
+
+%% {error, _} =
+%% odbc:sql_query(Ref, "INSERT INTO " ++ Table ++" VALUES(" ++
+%% "'" ++ string:chars($a, (?RDBMS:text_max()+1))
%% ++ "')").
%%-------------------------------------------------------------------------
@@ -518,25 +518,25 @@ text_upper_limit(Config) when is_list(Config) ->
binary_char_fixed_lower_limit() ->
[{doc,"Tests fixed length char data type lower boundaries."}].
binary_char_fixed_lower_limit(Config) when is_list(Config) ->
- Ref = proplists:get_value(connection_ref, Config),
+ Ref = proplists:get_value(connection_ref, Config),
Table = proplists:get_value(tableName, Config),
%% Below limit
- {error, _} =
- odbc:sql_query(Ref,
- "CREATE TABLE " ++ Table ++
+ {error, _} =
+ odbc:sql_query(Ref,
+ "CREATE TABLE " ++ Table ++
?RDBMS:create_fixed_char_table(
- (?RDBMS:fixed_char_min() - 1))),
+ (?RDBMS:fixed_char_min() - 1))),
%% Lower limit
{updated, _} = % Value == 0 || -1 driver dependent!
- odbc:sql_query(Ref, "CREATE TABLE " ++ Table ++
+ odbc:sql_query(Ref, "CREATE TABLE " ++ Table ++
?RDBMS:create_fixed_char_table(
- ?RDBMS:fixed_char_min())),
+ ?RDBMS:fixed_char_min())),
Str = string:chars($a, ?RDBMS:fixed_char_min()),
%% Right length data
- {updated, _} =
+ {updated, _} =
odbc:sql_query(Ref, "INSERT INTO " ++ Table ++" VALUES(" ++
"'" ++ Str
++ "')"),
@@ -550,11 +550,11 @@ binary_char_fixed_lower_limit(Config) when is_list(Config) ->
["FIELD"] = odbc_test_lib:to_upper(Fields),
%% Too long data
- {error, _} =
+ {error, _} =
odbc:sql_query(Ref,"INSERT INTO " ++ Table ++" VALUES(" ++
- "'" ++ string:chars($a,
+ "'" ++ string:chars($a,
(?RDBMS:fixed_char_min()
- + 1))
+ + 1))
++ "')").
%%-------------------------------------------------------------------------
@@ -566,63 +566,63 @@ binary_char_fixed_upper_limit(Config) when is_list(Config) ->
postgres ->
{skip, "Limit unknown"};
_ ->
- Ref = proplists:get_value(connection_ref, Config),
+ Ref = proplists:get_value(connection_ref, Config),
Table = proplists:get_value(tableName, Config),
-
- %% Upper limit
+
+ %% Upper limit
{updated, _} = % Value == 0 || -1 driver dependent!
- odbc:sql_query(Ref, "CREATE TABLE " ++ Table ++
+ odbc:sql_query(Ref, "CREATE TABLE " ++ Table ++
?RDBMS:create_fixed_char_table(
- ?RDBMS:fixed_char_max())),
- {updated, _} =
- odbc:sql_query(Ref,"INSERT INTO " ++ Table ++" VALUES(" ++
- "'" ++ string:chars($a,
+ ?RDBMS:fixed_char_max())),
+ {updated, _} =
+ odbc:sql_query(Ref,"INSERT INTO " ++ Table ++" VALUES(" ++
+ "'" ++ string:chars($a,
?RDBMS:fixed_char_max())
++ "')"),
%% Select data
{selected, Fields, [{CharBin}]} =
odbc:sql_query(Ref,"SELECT FIELD FROM " ++ Table),
true = size(CharBin) == ?RDBMS:fixed_char_max(),
-
+
["FIELD"] = odbc_test_lib:to_upper(Fields),
-
+
%% Too long data
- {error, _} =
- odbc:sql_query(Ref, "INSERT INTO " ++ Table ++" VALUES(" ++
- "'" ++ string:chars($a,
+ {error, _} =
+ odbc:sql_query(Ref, "INSERT INTO " ++ Table ++" VALUES(" ++
+ "'" ++ string:chars($a,
(?RDBMS:fixed_char_max()
- + 1))
- ++ "')"),
+ + 1))
+ ++ "')"),
%% Clean up
{updated, _} = % Value == 0 || -1 driver dependent!
odbc:sql_query(Ref, "DROP TABLE " ++ Table),
-
- %% Above limit
+
+ %% Above limit
{error, _} =
- odbc:sql_query(Ref, "CREATE TABLE " ++ Table ++
+ odbc:sql_query(Ref, "CREATE TABLE " ++ Table ++
?RDBMS:create_fixed_char_table(
- (?RDBMS:fixed_char_max() + 1))),
+ (?RDBMS:fixed_char_max() + 1))),
ok
end.
%%-------------------------------------------------------------------------
binary_char_fixed_padding() ->
- [{doc, "Tests that data that is shorter than the given size is padded "
+ [{doc, "Tests that data that is shorter than the given size is padded "
"with blanks."}].
binary_char_fixed_padding(Config) when is_list(Config) ->
- Ref = proplists:get_value(connection_ref, Config),
+ Ref = proplists:get_value(connection_ref, Config),
Table = proplists:get_value(tableName, Config),
%% Data should be padded with blanks
{updated, _} = % Value == 0 || -1 driver dependent!
- odbc:sql_query(Ref, "CREATE TABLE " ++ Table ++
+ odbc:sql_query(Ref, "CREATE TABLE " ++ Table ++
?RDBMS:create_fixed_char_table(
- ?RDBMS:fixed_char_max())),
+ ?RDBMS:fixed_char_max())),
- {updated, _} =
- odbc:sql_query(Ref, "INSERT INTO " ++ Table ++" VALUES(" ++
- "'" ++ string:chars($a,
+ {updated, _} =
+ odbc:sql_query(Ref, "INSERT INTO " ++ Table ++" VALUES(" ++
+ "'" ++ string:chars($a,
?RDBMS:fixed_char_min())
++ "')"),
@@ -636,25 +636,25 @@ binary_char_fixed_padding(Config) when is_list(Config) ->
binary_varchar_lower_limit() ->
[{doc,"Tests variable length char data type lower boundaries."}].
binary_varchar_lower_limit(Config) when is_list(Config) ->
- Ref = proplists:get_value(connection_ref, Config),
+ Ref = proplists:get_value(connection_ref, Config),
Table = proplists:get_value(tableName, Config),
%% Below limit
- {error, _} =
- odbc:sql_query(Ref, "CREATE TABLE " ++ Table ++
+ {error, _} =
+ odbc:sql_query(Ref, "CREATE TABLE " ++ Table ++
?RDBMS:create_var_char_table(
- ?RDBMS:var_char_min() - 1)),
+ ?RDBMS:var_char_min() - 1)),
%% Lower limit
{updated, _} = % Value == 0 || -1 driver dependent!
- odbc:sql_query(Ref, "CREATE TABLE " ++ Table ++
+ odbc:sql_query(Ref, "CREATE TABLE " ++ Table ++
?RDBMS:create_var_char_table(
- ?RDBMS:var_char_min())),
+ ?RDBMS:var_char_min())),
Str = string:chars($a, ?RDBMS:var_char_min()),
%% Right length data
- {updated, _} =
- odbc:sql_query(Ref, "INSERT INTO " ++ Table ++" VALUES(" ++
+ {updated, _} =
+ odbc:sql_query(Ref, "INSERT INTO " ++ Table ++" VALUES(" ++
"'" ++ Str
++ "')"),
BinStr = list_to_binary(Str),
@@ -662,14 +662,14 @@ binary_varchar_lower_limit(Config) when is_list(Config) ->
%% Select data
{selected, Fields, [{BinStr}]} =
odbc:sql_query(Ref,"SELECT FIELD FROM " ++ Table),
-
+
["FIELD"] = odbc_test_lib:to_upper(Fields),
%% Too long data
- {error, _} =
- odbc:sql_query(Ref, "INSERT INTO " ++ Table ++" VALUES(" ++
- "'" ++ string:chars($a,
- (?RDBMS:var_char_min()+1))
+ {error, _} =
+ odbc:sql_query(Ref, "INSERT INTO " ++ Table ++" VALUES(" ++
+ "'" ++ string:chars($a,
+ (?RDBMS:var_char_min()+1))
++ "')").
%%-------------------------------------------------------------------------
@@ -677,7 +677,7 @@ binary_varchar_lower_limit(Config) when is_list(Config) ->
binary_varchar_upper_limit() ->
[{doc,"Tests variable length char data type upper boundaries."}].
binary_varchar_upper_limit(Config) when is_list(Config) ->
- Ref = proplists:get_value(connection_ref, Config),
+ Ref = proplists:get_value(connection_ref, Config),
Table = proplists:get_value(tableName, Config),
case ?RDBMS of
@@ -686,55 +686,55 @@ binary_varchar_upper_limit(Config) when is_list(Config) ->
postgres ->
{skip, "Limit unknown"};
_ ->
- %% Upper limit
+ %% Upper limit
{updated, _} = % Value == 0 || -1 driver dependent!
- odbc:sql_query(Ref, "CREATE TABLE " ++ Table ++
+ odbc:sql_query(Ref, "CREATE TABLE " ++ Table ++
?RDBMS:create_var_char_table(
- ?RDBMS:var_char_max())),
- {updated, _} =
- odbc:sql_query(Ref, "INSERT INTO " ++ Table ++" VALUES(" ++
- "'" ++ string:chars($a,
+ ?RDBMS:var_char_max())),
+ {updated, _} =
+ odbc:sql_query(Ref, "INSERT INTO " ++ Table ++" VALUES(" ++
+ "'" ++ string:chars($a,
?RDBMS:var_char_max())
++ "')"),
-
+
{selected, Fields, [{CharBin}]} =
odbc:sql_query(Ref,"SELECT FIELD FROM " ++ Table),
true = size(CharBin) == ?RDBMS:var_char_max(),
-
+
["FIELD"] = odbc_test_lib:to_upper(Fields),
-
+
%% Too long data
- {error, _} =
- odbc:sql_query(Ref, "INSERT INTO " ++ Table ++" VALUES(" ++
- "'" ++ string:chars($a,
- (?RDBMS:var_char_max()+1))
+ {error, _} =
+ odbc:sql_query(Ref, "INSERT INTO " ++ Table ++" VALUES(" ++
+ "'" ++ string:chars($a,
+ (?RDBMS:var_char_max()+1))
++ "')"),
%% Clean up
{updated, _} = % Value == 0 || -1 driver dependent!
- odbc:sql_query(Ref, "DROP TABLE " ++ Table),
-
- %% Above limit
+ odbc:sql_query(Ref, "DROP TABLE " ++ Table),
+
+ %% Above limit
{error, _} =
- odbc:sql_query(Ref, "CREATE TABLE " ++ Table ++
+ odbc:sql_query(Ref, "CREATE TABLE " ++ Table ++
?RDBMS:create_var_char_table(
(?RDBMS:var_char_max() + 1)))
end.
%%-------------------------------------------------------------------------
binary_varchar_no_padding() ->
- [{doc,"Tests that data that is shorter than the given max size is not padded "
+ [{doc,"Tests that data that is shorter than the given max size is not padded "
"with blanks."}].
binary_varchar_no_padding(Config) when is_list(Config) ->
- Ref = proplists:get_value(connection_ref, Config),
+ Ref = proplists:get_value(connection_ref, Config),
Table = proplists:get_value(tableName, Config),
%% Data should NOT be padded with blanks
{updated, _} = % Value == 0 || -1 driver dependent!
- odbc:sql_query(Ref, "CREATE TABLE " ++ Table ++
+ odbc:sql_query(Ref, "CREATE TABLE " ++ Table ++
?RDBMS:create_var_char_table(
- ?RDBMS:var_char_max())),
- {updated, _} =
- odbc:sql_query(Ref, "INSERT INTO " ++ Table ++" VALUES(" ++
+ ?RDBMS:var_char_max())),
+ {updated, _} =
+ odbc:sql_query(Ref, "INSERT INTO " ++ Table ++" VALUES(" ++
"'" ++ string:chars($a, ?RDBMS:var_char_min())
++ "')"),
@@ -748,15 +748,15 @@ binary_varchar_no_padding(Config) when is_list(Config) ->
binary_text_lower_limit() ->
[{doc,"Tests 'long' char data type lower boundaries."}].
binary_text_lower_limit(Config) when is_list(Config) ->
- Ref = proplists:get_value(connection_ref, Config),
+ Ref = proplists:get_value(connection_ref, Config),
Table = proplists:get_value(tableName, Config),
{updated, _} = % Value == 0 || -1 driver dependent!
- odbc:sql_query(Ref, "CREATE TABLE " ++ Table ++
- ?RDBMS:create_text_table()),
+ odbc:sql_query(Ref, "CREATE TABLE " ++ Table ++
+ ?RDBMS:create_text_table()),
- {updated, _} =
- odbc:sql_query(Ref, "INSERT INTO " ++ Table ++" VALUES(" ++
+ {updated, _} =
+ odbc:sql_query(Ref, "INSERT INTO " ++ Table ++" VALUES(" ++
"'" ++ string:chars($a, ?RDBMS:text_min())
++ "')"),
@@ -769,16 +769,16 @@ binary_text_lower_limit(Config) when is_list(Config) ->
binary_text_upper_limit() ->
[{doc,"Tests text char data type upper boundaries."}].
binary_text_upper_limit(Config) when is_list(Config) ->
-
+
{skip,"Consumes too much resources" }.
%% Ref = proplists:get_value(connection_ref, Config),
%% Table = proplists:get_value(tableName, Config),
%% {updated, _} = % Value == 0 || -1 driver dependent!
-%% odbc:sql_query(Ref, "CREATE TABLE " ++ Table ++
-%% ?RDBMS:create_text_table()),
-%% {updated, _} =
-%% odbc:sql_query(Ref, "INSERT INTO " ++ Table ++" VALUES(" ++
+%% odbc:sql_query(Ref, "CREATE TABLE " ++ Table ++
+%% ?RDBMS:create_text_table()),
+%% {updated, _} =
+%% odbc:sql_query(Ref, "INSERT INTO " ++ Table ++" VALUES(" ++
%% "'" ++ string:chars($a, ?RDBMS:text_max())
%% ++ "')"),
@@ -786,10 +786,10 @@ binary_text_upper_limit(Config) when is_list(Config) ->
%% odbc:sql_query(Ref,"SELECT FIELD FROM " ++ Table),
%% size(CharBin) == ?RDBMS:text_max(),
%% ["FIELD"] = odbc_test_lib:to_upper(Fields),
-
-%% {error, _} =
-%% odbc:sql_query(Ref, "INSERT INTO " ++ Table ++" VALUES(" ++
-%% "'" ++ string:chars($a, (?RDBMS:text_max()+1))
+
+%% {error, _} =
+%% odbc:sql_query(Ref, "INSERT INTO " ++ Table ++" VALUES(" ++
+%% "'" ++ string:chars($a, (?RDBMS:text_max()+1))
%% ++ "')").
@@ -797,30 +797,30 @@ binary_text_upper_limit(Config) when is_list(Config) ->
tiny_int_lower_limit() ->
[{doc,"Tests integer of type tinyint."}].
-tiny_int_lower_limit(Config) when is_list(Config) ->
+tiny_int_lower_limit(Config) when is_list(Config) ->
case ?RDBMS of
postgres ->
{skip, "Type tiniyint not supported"};
_ ->
- Ref = proplists:get_value(connection_ref, Config),
+ Ref = proplists:get_value(connection_ref, Config),
Table = proplists:get_value(tableName, Config),
-
+
{updated, _} = % Value == 0 || -1 driver dependent!
- odbc:sql_query(Ref, "CREATE TABLE " ++ Table ++
- ?RDBMS:create_tiny_int_table()),
-
- {updated, _} =
- odbc:sql_query(Ref, "INSERT INTO " ++ Table ++" VALUES(" ++
+ odbc:sql_query(Ref, "CREATE TABLE " ++ Table ++
+ ?RDBMS:create_tiny_int_table()),
+
+ {updated, _} =
+ odbc:sql_query(Ref, "INSERT INTO " ++ Table ++" VALUES(" ++
"'" ++ integer_to_list(?RDBMS:tiny_int_min())
++ "')"),
-
+
SelectResult = ?RDBMS:tiny_int_min_selected(),
SelectResult =
odbc:sql_query(Ref,"SELECT FIELD FROM " ++ Table),
-
- {error, _} =
- odbc:sql_query(Ref, "INSERT INTO " ++ Table ++" VALUES(" ++
- "'" ++ integer_to_list(?RDBMS:tiny_int_min()
+
+ {error, _} =
+ odbc:sql_query(Ref, "INSERT INTO " ++ Table ++" VALUES(" ++
+ "'" ++ integer_to_list(?RDBMS:tiny_int_min()
- 1)
++ "')")
end.
@@ -834,24 +834,24 @@ tiny_int_upper_limit(Config) when is_list(Config) ->
postgres ->
{skip, "Type tiniyint not supported"};
_ ->
- Ref = proplists:get_value(connection_ref, Config),
+ Ref = proplists:get_value(connection_ref, Config),
Table = proplists:get_value(tableName, Config),
-
+
{updated, _} = % Value == 0 || -1 driver dependent!
- odbc:sql_query(Ref, "CREATE TABLE " ++ Table ++
- ?RDBMS:create_tiny_int_table()),
-
- {updated, _} =
- odbc:sql_query(Ref, "INSERT INTO " ++ Table ++" VALUES(" ++
+ odbc:sql_query(Ref, "CREATE TABLE " ++ Table ++
+ ?RDBMS:create_tiny_int_table()),
+
+ {updated, _} =
+ odbc:sql_query(Ref, "INSERT INTO " ++ Table ++" VALUES(" ++
"'" ++ integer_to_list(?RDBMS:tiny_int_max())
++ "')"),
-
+
SelectResult = ?RDBMS:tiny_int_max_selected(),
SelectResult =
odbc:sql_query(Ref,"SELECT FIELD FROM " ++ Table),
-
- {error, _} =
- odbc:sql_query(Ref, "INSERT INTO " ++ Table ++" VALUES(" ++
+
+ {error, _} =
+ odbc:sql_query(Ref, "INSERT INTO " ++ Table ++" VALUES(" ++
"'" ++ integer_to_list(?RDBMS:tiny_int_max()
+ 1)
++ "')")
@@ -862,15 +862,15 @@ tiny_int_upper_limit(Config) when is_list(Config) ->
small_int_lower_limit() ->
[{doc,"Tests integer of type smallint."}].
small_int_lower_limit(Config) when is_list(Config) ->
- Ref = proplists:get_value(connection_ref, Config),
+ Ref = proplists:get_value(connection_ref, Config),
Table = proplists:get_value(tableName, Config),
{updated, _} = % Value == 0 || -1 driver dependent!
- odbc:sql_query(Ref, "CREATE TABLE " ++ Table ++
- ?RDBMS:create_small_int_table()),
+ odbc:sql_query(Ref, "CREATE TABLE " ++ Table ++
+ ?RDBMS:create_small_int_table()),
- {updated, _} =
- odbc:sql_query(Ref, "INSERT INTO " ++ Table ++" VALUES(" ++
+ {updated, _} =
+ odbc:sql_query(Ref, "INSERT INTO " ++ Table ++" VALUES(" ++
"'" ++ integer_to_list(?RDBMS:small_int_min())
++ "')"),
@@ -878,8 +878,8 @@ small_int_lower_limit(Config) when is_list(Config) ->
SelectResult =
odbc:sql_query(Ref,"SELECT FIELD FROM " ++ Table),
- {error, _} =
- odbc:sql_query(Ref, "INSERT INTO " ++ Table ++" VALUES(" ++
+ {error, _} =
+ odbc:sql_query(Ref, "INSERT INTO " ++ Table ++" VALUES(" ++
"'" ++ integer_to_list(?RDBMS:small_int_min()
- 1)
++ "')").
@@ -889,15 +889,15 @@ small_int_lower_limit(Config) when is_list(Config) ->
small_int_upper_limit() ->
[{doc,"Tests integer of type smallint."}].
small_int_upper_limit(Config) when is_list(Config) ->
- Ref = proplists:get_value(connection_ref, Config),
+ Ref = proplists:get_value(connection_ref, Config),
Table = proplists:get_value(tableName, Config),
{updated, _} = % Value == 0 || -1 driver dependent!
- odbc:sql_query(Ref, "CREATE TABLE " ++ Table ++
- ?RDBMS:create_small_int_table()),
+ odbc:sql_query(Ref, "CREATE TABLE " ++ Table ++
+ ?RDBMS:create_small_int_table()),
- {updated, _} =
- odbc:sql_query(Ref, "INSERT INTO " ++ Table ++" VALUES(" ++
+ {updated, _} =
+ odbc:sql_query(Ref, "INSERT INTO " ++ Table ++" VALUES(" ++
"'" ++ integer_to_list(?RDBMS:small_int_max())
++ "')"),
@@ -905,9 +905,9 @@ small_int_upper_limit(Config) when is_list(Config) ->
SelectResult =
odbc:sql_query(Ref,"SELECT FIELD FROM " ++ Table),
- {error, _} =
- odbc:sql_query(Ref,"INSERT INTO " ++ Table ++" VALUES(" ++
- "'" ++ integer_to_list(?RDBMS:small_int_max()
+ {error, _} =
+ odbc:sql_query(Ref,"INSERT INTO " ++ Table ++" VALUES(" ++
+ "'" ++ integer_to_list(?RDBMS:small_int_max()
+ 1)
++ "')").
@@ -915,15 +915,15 @@ small_int_upper_limit(Config) when is_list(Config) ->
int_lower_limit() ->
[{doc,"Tests integer of type int."}].
int_lower_limit(Config) when is_list(Config) ->
- Ref = proplists:get_value(connection_ref, Config),
+ Ref = proplists:get_value(connection_ref, Config),
Table = proplists:get_value(tableName, Config),
{updated, _} = % Value == 0 || -1 driver dependent!
- odbc:sql_query(Ref, "CREATE TABLE " ++ Table ++
- ?RDBMS:create_int_table()),
+ odbc:sql_query(Ref, "CREATE TABLE " ++ Table ++
+ ?RDBMS:create_int_table()),
- {updated, _} =
- odbc:sql_query(Ref, "INSERT INTO " ++ Table ++" VALUES(" ++
+ {updated, _} =
+ odbc:sql_query(Ref, "INSERT INTO " ++ Table ++" VALUES(" ++
"'" ++ integer_to_list(?RDBMS:int_min())
++ "')"),
@@ -931,8 +931,8 @@ int_lower_limit(Config) when is_list(Config) ->
SelectResult =
odbc:sql_query(Ref,"SELECT FIELD FROM " ++ Table),
- {error, _} =
- odbc:sql_query(Ref, "INSERT INTO " ++ Table ++" VALUES(" ++
+ {error, _} =
+ odbc:sql_query(Ref, "INSERT INTO " ++ Table ++" VALUES(" ++
"'" ++ integer_to_list(?RDBMS:int_min() - 1)
++ "')").
@@ -941,15 +941,15 @@ int_lower_limit(Config) when is_list(Config) ->
int_upper_limit() ->
[{doc,"Tests integer of type int."}].
int_upper_limit(Config) when is_list(Config) ->
- Ref = proplists:get_value(connection_ref, Config),
+ Ref = proplists:get_value(connection_ref, Config),
Table = proplists:get_value(tableName, Config),
{updated, _} = % Value == 0 || -1 driver dependent!
- odbc:sql_query(Ref, "CREATE TABLE " ++ Table ++
- ?RDBMS:create_int_table()),
+ odbc:sql_query(Ref, "CREATE TABLE " ++ Table ++
+ ?RDBMS:create_int_table()),
- {updated, _} =
- odbc:sql_query(Ref, "INSERT INTO " ++ Table ++" VALUES(" ++
+ {updated, _} =
+ odbc:sql_query(Ref, "INSERT INTO " ++ Table ++" VALUES(" ++
"'" ++ integer_to_list(?RDBMS:int_max())
++ "')"),
@@ -957,8 +957,8 @@ int_upper_limit(Config) when is_list(Config) ->
SelectResult =
odbc:sql_query(Ref,"SELECT FIELD FROM " ++ Table),
- {error, _} =
- odbc:sql_query(Ref, "INSERT INTO " ++ Table ++" VALUES(" ++
+ {error, _} =
+ odbc:sql_query(Ref, "INSERT INTO " ++ Table ++" VALUES(" ++
"'" ++ integer_to_list(?RDBMS:int_max() + 1)
++ "')").
@@ -967,15 +967,15 @@ int_upper_limit(Config) when is_list(Config) ->
big_int_lower_limit() ->
[{doc,"Tests integer of type bigint"}].
big_int_lower_limit(Config) when is_list(Config) ->
- Ref = proplists:get_value(connection_ref, Config),
+ Ref = proplists:get_value(connection_ref, Config),
Table = proplists:get_value(tableName, Config),
{updated, _} = % Value == 0 || -1 driver dependent!
- odbc:sql_query(Ref, "CREATE TABLE " ++ Table ++
- ?RDBMS:create_big_int_table()),
+ odbc:sql_query(Ref, "CREATE TABLE " ++ Table ++
+ ?RDBMS:create_big_int_table()),
- {updated, _} =
- odbc:sql_query(Ref, "INSERT INTO " ++ Table ++" VALUES(" ++
+ {updated, _} =
+ odbc:sql_query(Ref, "INSERT INTO " ++ Table ++" VALUES(" ++
"'" ++ integer_to_list(?RDBMS:big_int_min())
++ "')"),
@@ -983,9 +983,9 @@ big_int_lower_limit(Config) when is_list(Config) ->
SelectResult =
odbc:sql_query(Ref,"SELECT FIELD FROM " ++ Table),
- {error, _} =
- odbc:sql_query(Ref, "INSERT INTO " ++ Table ++" VALUES(" ++
- "'" ++ integer_to_list(?RDBMS:big_int_min()
+ {error, _} =
+ odbc:sql_query(Ref, "INSERT INTO " ++ Table ++" VALUES(" ++
+ "'" ++ integer_to_list(?RDBMS:big_int_min()
- 1)
++ "')").
@@ -994,15 +994,15 @@ big_int_lower_limit(Config) when is_list(Config) ->
big_int_upper_limit() ->
[{doc,"Tests integer of type bigint."}].
big_int_upper_limit(Config) when is_list(Config) ->
- Ref = proplists:get_value(connection_ref, Config),
+ Ref = proplists:get_value(connection_ref, Config),
Table = proplists:get_value(tableName, Config),
{updated, _} = % Value == 0 || -1 driver dependent!
- odbc:sql_query(Ref, "CREATE TABLE " ++ Table ++
- ?RDBMS:create_big_int_table()),
+ odbc:sql_query(Ref, "CREATE TABLE " ++ Table ++
+ ?RDBMS:create_big_int_table()),
- {updated, _} =
- odbc:sql_query(Ref, "INSERT INTO " ++ Table ++" VALUES(" ++
+ {updated, _} =
+ odbc:sql_query(Ref, "INSERT INTO " ++ Table ++" VALUES(" ++
"'" ++ integer_to_list(?RDBMS:big_int_max())
++ "')"),
@@ -1010,39 +1010,44 @@ big_int_upper_limit(Config) when is_list(Config) ->
SelectResult =
odbc:sql_query(Ref,"SELECT FIELD FROM " ++ Table),
- {error, _} =
- odbc:sql_query(Ref, "INSERT INTO " ++ Table ++" VALUES(" ++
- "'" ++ integer_to_list(?RDBMS:big_int_max()
+ {error, _} =
+ odbc:sql_query(Ref, "INSERT INTO " ++ Table ++" VALUES(" ++
+ "'" ++ integer_to_list(?RDBMS:big_int_max()
+ 1)
++ "')").
%%-------------------------------------------------------------------------
-bit_false(Config) when is_list(Config) ->
+bit_false(Config) when is_list(Config) ->
case ?RDBMS of
oracle ->
{skip, "Not supported by driver"};
_ ->
- Ref = proplists:get_value(connection_ref, Config),
+ Ref = proplists:get_value(connection_ref, Config),
Table = proplists:get_value(tableName, Config),
-
+
{updated, _} = % Value == 0 || -1 driver dependent!
- odbc:sql_query(Ref, "CREATE TABLE " ++ Table ++
- ?RDBMS:create_bit_table()),
-
- {updated, _} =
+ odbc:sql_query(Ref, "CREATE TABLE " ++ Table ++
+ ?RDBMS:create_bit_table()),
+
+ {updated, _} =
odbc:sql_query(Ref, "INSERT INTO " ++ Table ++
- " VALUES(" ++
+ " VALUES(" ++
"'" ++ integer_to_list(?RDBMS:bit_false())
++ "')"),
-
+
SelectResult = ?RDBMS:bit_false_selected(),
SelectResult =
odbc:sql_query(Ref,"SELECT FIELD FROM " ++ Table),
-
- {error, _} =
- odbc:sql_query(Ref, "INSERT INTO " ++ Table ++" VALUES(" ++
- "'" ++ integer_to_list(-1)
- ++ "')")
+
+ InvalidInsert = odbc:sql_query(Ref, "INSERT INTO " ++ Table ++
+ " VALUES(" ++ "'" ++
+ integer_to_list(-1) ++ "')"),
+ case ?RDBMS:non_bit_promotes_to() of
+ error ->
+ {error, _} = InvalidInsert;
+ Value ->
+ {updated, Value} = InvalidInsert
+ end
end.
%%-------------------------------------------------------------------------
@@ -1052,35 +1057,40 @@ bit_true(Config) when is_list(Config) ->
oracle ->
{skip, "Not supported by driver"};
_ ->
- Ref = proplists:get_value(connection_ref, Config),
+ Ref = proplists:get_value(connection_ref, Config),
Table = proplists:get_value(tableName, Config),
-
-
+
+
{updated, _} = % Value == 0 || -1 driver dependent!
- odbc:sql_query(Ref, "CREATE TABLE " ++ Table ++
- ?RDBMS:create_bit_table()),
-
- {updated, _} =
- odbc:sql_query(Ref,
- "INSERT INTO " ++ Table ++" VALUES(" ++
+ odbc:sql_query(Ref, "CREATE TABLE " ++ Table ++
+ ?RDBMS:create_bit_table()),
+
+ {updated, _} =
+ odbc:sql_query(Ref,
+ "INSERT INTO " ++ Table ++" VALUES(" ++
"'" ++ integer_to_list(?RDBMS:bit_true())
++ "')"),
-
+
SelectResult = ?RDBMS:bit_true_selected(),
SelectResult =
odbc:sql_query(Ref,"SELECT FIELD FROM " ++ Table),
-
- {error, _} =
- odbc:sql_query(Ref, "INSERT INTO " ++ Table ++" VALUES(" ++
- "'" ++ integer_to_list(-1)
- ++ "')")
+
+ InvalidInsert = odbc:sql_query(Ref, "INSERT INTO " ++ Table ++
+ " VALUES(" ++ "'" ++
+ integer_to_list(-1) ++ "')"),
+ case ?RDBMS:non_bit_promotes_to() of
+ error ->
+ {error, _} = InvalidInsert;
+ Value ->
+ {updated, Value} = InvalidInsert
+ end
end.
%%-------------------------------------------------------------------------
-float_lower_limit(Config) when is_list(Config) ->
+float_lower_limit(Config) when is_list(Config) ->
- Ref = proplists:get_value(connection_ref, Config),
+ Ref = proplists:get_value(connection_ref, Config),
Table = proplists:get_value(tableName, Config),
case ?RDBMS of
@@ -1088,11 +1098,11 @@ float_lower_limit(Config) when is_list(Config) ->
{skip, "Not clearly defined in MYSQL"};
_ ->
{updated, _} = % Value == 0 || -1 driver dependent!
- odbc:sql_query(Ref, "CREATE TABLE " ++ Table ++
+ odbc:sql_query(Ref, "CREATE TABLE " ++ Table ++
?RDBMS:create_float_table()),
- {updated, _} =
- odbc:sql_query(Ref, "INSERT INTO " ++ Table ++" VALUES(" ++
+ {updated, _} =
+ odbc:sql_query(Ref, "INSERT INTO " ++ Table ++" VALUES(" ++
"'" ++ float_to_list(
?RDBMS:float_min())
++ "')"),
@@ -1125,8 +1135,8 @@ float_lower_limit(Config) when is_list(Config) ->
%%-------------------------------------------------------------------------
-float_upper_limit(Config) when is_list(Config) ->
- Ref = proplists:get_value(connection_ref, Config),
+float_upper_limit(Config) when is_list(Config) ->
+ Ref = proplists:get_value(connection_ref, Config),
Table = proplists:get_value(tableName, Config),
case ?RDBMS of
@@ -1155,15 +1165,15 @@ float_upper_limit(Config) when is_list(Config) ->
%%-------------------------------------------------------------------------
float_zero() ->
[{doc,"Test the float value zero."}].
-float_zero(Config) when is_list(Config) ->
- Ref = proplists:get_value(connection_ref, Config),
+float_zero(Config) when is_list(Config) ->
+ Ref = proplists:get_value(connection_ref, Config),
Table = proplists:get_value(tableName, Config),
{updated, _} = % Value == 0 || -1 driver dependent!
- odbc:sql_query(Ref, "CREATE TABLE " ++ Table ++
- ?RDBMS:create_float_table()),
+ odbc:sql_query(Ref, "CREATE TABLE " ++ Table ++
+ ?RDBMS:create_float_table()),
- {updated, _} =
+ {updated, _} =
odbc:sql_query(Ref, "INSERT INTO " ++ Table ++" VALUES('0')"),
SelectResult = ?RDBMS:float_zero_selected(),
@@ -1172,19 +1182,19 @@ float_zero(Config) when is_list(Config) ->
%%-------------------------------------------------------------------------
real_zero() ->
[{doc,"Test the real value zero."}].
-real_zero(Config) when is_list(Config) ->
- Ref = proplists:get_value(connection_ref, Config),
+real_zero(Config) when is_list(Config) ->
+ Ref = proplists:get_value(connection_ref, Config),
Table = proplists:get_value(tableName, Config),
case ?RDBMS of
oracle ->
- {skip, "Not supported in Oracle"};
- _ ->
+ {skip, "Not supported in Oracle"};
+ _ ->
{updated, _} = % Value == 0 || -1 driver dependent!
- odbc:sql_query(Ref, "CREATE TABLE " ++ Table ++
- ?RDBMS:create_real_table()),
+ odbc:sql_query(Ref, "CREATE TABLE " ++ Table ++
+ ?RDBMS:create_real_table()),
- {updated, _} =
+ {updated, _} =
odbc:sql_query(Ref, "INSERT INTO " ++ Table ++
" VALUES('0')"),
@@ -1196,14 +1206,14 @@ real_zero(Config) when is_list(Config) ->
dec_long(suit) ->
[];
dec_long(Config) when is_list(Config) ->
- Ref = proplists:get_value(connection_ref, Config),
+ Ref = proplists:get_value(connection_ref, Config),
Table = proplists:get_value(tableName, Config),
{updated, _} = % Value == 0 || -1 driver dependent!
- odbc:sql_query(Ref, "CREATE TABLE " ++ Table ++
- "(FIELD DECIMAL (9,0))"),
+ odbc:sql_query(Ref, "CREATE TABLE " ++ Table ++
+ "(FIELD DECIMAL (9,0))"),
- {updated, _} =
+ {updated, _} =
odbc:sql_query(Ref, "INSERT INTO " ++ Table ++" VALUES(1.6)"),
{selected, Fields, [{2}]} =
@@ -1213,45 +1223,48 @@ dec_long(Config) when is_list(Config) ->
dec_double(suit) ->
[];
dec_double(Config) when is_list(Config) ->
- Ref = proplists:get_value(connection_ref, Config),
+ Ref = proplists:get_value(connection_ref, Config),
Table = proplists:get_value(tableName, Config),
{updated, _} = % Value == 0 || -1 driver dependent!
- odbc:sql_query(Ref, "CREATE TABLE " ++ Table ++
- "(FIELD DECIMAL (10,0))"),
- {updated, _} =
+ odbc:sql_query(Ref, "CREATE TABLE " ++ Table ++
+ "(FIELD DECIMAL (10,0))"),
+ {updated, _} =
odbc:sql_query(Ref, "INSERT INTO " ++ Table ++" VALUES(1.6)"),
- {selected, Fields, [{2.00000}]} =
+ ExpectedValue1 = ?RDBMS:expected_value(10, 0, 1.6),
+ {selected, Fields, [{ExpectedValue1}]} =
odbc:sql_query(Ref,"SELECT FIELD FROM " ++ Table),
["FIELD"] = odbc_test_lib:to_upper(Fields),
%% Clean up
{updated, _} = % Value == 0 || -1 driver dependent!
- odbc:sql_query(Ref, "DROP TABLE " ++ Table),
+ odbc:sql_query(Ref, "DROP TABLE " ++ Table),
{updated, _} = % Value == 0 || -1 driver dependent!
- odbc:sql_query(Ref, "CREATE TABLE " ++ Table ++
- "(FIELD DECIMAL (15,0))"),
- {updated, _} =
+ odbc:sql_query(Ref, "CREATE TABLE " ++ Table ++
+ "(FIELD DECIMAL (15,0))"),
+ {updated, _} =
odbc:sql_query(Ref, "INSERT INTO " ++ Table ++" VALUES(1.6)"),
- {selected, Fields1, [{2.00000}]} =
+ ExpectedValue2 = ?RDBMS:expected_value(15, 0, 1.6),
+ {selected, Fields1, [{ExpectedValue2}]} =
odbc:sql_query(Ref,"SELECT FIELD FROM " ++ Table),
["FIELD"] = odbc_test_lib:to_upper(Fields1),
%% Clean up
{updated, _} = % Value == 0 || -1 driver dependent!
- odbc:sql_query(Ref, "DROP TABLE " ++ Table),
+ odbc:sql_query(Ref, "DROP TABLE " ++ Table),
{updated, _} = % Value == 0 || -1 driver dependent!
- odbc:sql_query(Ref, "CREATE TABLE " ++ Table ++
- "(FIELD DECIMAL (15, 1))"),
- {updated, _} =
+ odbc:sql_query(Ref, "CREATE TABLE " ++ Table ++
+ "(FIELD DECIMAL (15, 1))"),
+ {updated, _} =
odbc:sql_query(Ref, "INSERT INTO " ++ Table ++" VALUES(1.6)"),
- {selected, Fields2, [{1.60000}]} =
+ ExpectedValue3 = ?RDBMS:expected_value(15, 1, 1.6),
+ {selected, Fields2, [{ExpectedValue3}]} =
odbc:sql_query(Ref,"SELECT FIELD FROM " ++ Table),
["FIELD"] = odbc_test_lib:to_upper(Fields2).
@@ -1259,44 +1272,46 @@ dec_double(Config) when is_list(Config) ->
dec_bignum(suit) ->
[];
dec_bignum(Config) when is_list(Config) ->
- Ref = proplists:get_value(connection_ref, Config),
+ Ref = proplists:get_value(connection_ref, Config),
Table = proplists:get_value(tableName, Config),
{updated, _} = % Value == 0 || -1 driver dependent!
- odbc:sql_query(Ref, "CREATE TABLE " ++ Table ++
- "(FIELD DECIMAL (16,0))"),
- {updated, _} =
+ odbc:sql_query(Ref, "CREATE TABLE " ++ Table ++
+ "(FIELD DECIMAL (16,0))"),
+ {updated, _} =
odbc:sql_query(Ref, "INSERT INTO " ++ Table ++" VALUES(1.6)"),
- {selected, Fields, [{"2"}]} =
+ ExpectedValue1 = ?RDBMS:expected_value(16, 0, 1.6),
+ {selected, Fields, [{ExpectedValue1}]} =
odbc:sql_query(Ref,"SELECT FIELD FROM " ++ Table),
["FIELD"] = odbc_test_lib:to_upper(Fields),
%% Clean up
{updated, _} = % Value == 0 || -1 driver dependent!
- odbc:sql_query(Ref, "DROP TABLE " ++ Table),
+ odbc:sql_query(Ref, "DROP TABLE " ++ Table),
{updated, _} = % Value == 0 || -1 driver dependent!
- odbc:sql_query(Ref, "CREATE TABLE " ++ Table ++
- "(FIELD DECIMAL (16,1))"),
- {updated, _} =
+ odbc:sql_query(Ref, "CREATE TABLE " ++ Table ++
+ "(FIELD DECIMAL (16,1))"),
+ {updated, _} =
odbc:sql_query(Ref, "INSERT INTO " ++ Table ++" VALUES(1.6)"),
- {selected, Fields1, [{"1.6"}]} =
+ ExpectedValue2 = ?RDBMS:expected_value(16, 1, 1.6),
+ {selected, Fields1, [{ExpectedValue2}]} =
odbc:sql_query(Ref,"SELECT FIELD FROM " ++ Table),
["FIELD"] = odbc_test_lib:to_upper(Fields1).
%%------------------------------------------------------------------------
num_long(suit) ->
[];
num_long(Config) when is_list(Config) ->
- Ref = proplists:get_value(connection_ref, Config),
+ Ref = proplists:get_value(connection_ref, Config),
Table = proplists:get_value(tableName, Config),
{updated, _} = % Value == 0 || -1 driver dependent!
- odbc:sql_query(Ref, "CREATE TABLE " ++ Table ++
- "(FIELD DECIMAL (9,0))"),
+ odbc:sql_query(Ref, "CREATE TABLE " ++ Table ++
+ "(FIELD DECIMAL (9,0))"),
- {updated, _} =
+ {updated, _} =
odbc:sql_query(Ref, "INSERT INTO " ++ Table ++" VALUES(1.5)"),
{selected, Fields, [{2}]} =
@@ -1306,74 +1321,79 @@ num_long(Config) when is_list(Config) ->
num_double(suit) ->
[];
num_double(Config) when is_list(Config) ->
- Ref = proplists:get_value(connection_ref, Config),
+ Ref = proplists:get_value(connection_ref, Config),
Table = proplists:get_value(tableName, Config),
{updated, _} = % Value == 0 || -1 driver dependent!
- odbc:sql_query(Ref, "CREATE TABLE " ++ Table ++
- "(FIELD DECIMAL (10,0))"),
- {updated, _} =
+ odbc:sql_query(Ref, "CREATE TABLE " ++ Table ++
+ "(FIELD DECIMAL (10,0))"),
+ {updated, _} =
odbc:sql_query(Ref, "INSERT INTO " ++ Table ++" VALUES(1.6)"),
- {selected, Fields, [{2.0000}]} =
+ ExpectedValue1 = ?RDBMS:expected_value(10, 0, 1.6),
+ {selected, Fields, [{ExpectedValue1}]} =
odbc:sql_query(Ref,"SELECT FIELD FROM " ++ Table),
["FIELD"] = odbc_test_lib:to_upper(Fields),
%% Clean up
{updated, _} = % Value == 0 || -1 driver dependent!
- odbc:sql_query(Ref, "DROP TABLE " ++ Table),
+ odbc:sql_query(Ref, "DROP TABLE " ++ Table),
{updated, _} = % Value == 0 || -1 driver dependent!
- odbc:sql_query(Ref, "CREATE TABLE " ++ Table ++
- "(FIELD DECIMAL (15,0))"),
- {updated, _} =
+ odbc:sql_query(Ref, "CREATE TABLE " ++ Table ++
+ "(FIELD DECIMAL (15,0))"),
+ {updated, _} =
odbc:sql_query(Ref, "INSERT INTO " ++ Table ++" VALUES(1.6)"),
- {selected, Fields1, [{2.0000}]} =
+ ExpectedValue2 = ?RDBMS:expected_value(15, 0, 1.6),
+ {selected, Fields1, [{ExpectedValue2}]} =
odbc:sql_query(Ref,"SELECT FIELD FROM " ++ Table),
["FIELD"] = odbc_test_lib:to_upper(Fields1),
%% Clean up
{updated, _} = % Value == 0 || -1 driver dependent!
- odbc:sql_query(Ref, "DROP TABLE " ++ Table),
+ odbc:sql_query(Ref, "DROP TABLE " ++ Table),
{updated, _} = % Value == 0 || -1 driver dependent!
- odbc:sql_query(Ref, "CREATE TABLE " ++ Table ++
- "(FIELD DECIMAL (15,1))"),
- {updated, _} =
+ odbc:sql_query(Ref, "CREATE TABLE " ++ Table ++
+ "(FIELD DECIMAL (15,1))"),
+ {updated, _} =
odbc:sql_query(Ref, "INSERT INTO " ++ Table ++" VALUES(1.6)"),
- {selected, Fields2, [{1.6000}]} =
+ ExpectedValue3 = ?RDBMS:expected_value(15, 1, 1.6),
+ {selected, Fields2, [{ExpectedValue3}]} =
odbc:sql_query(Ref,"SELECT FIELD FROM " ++ Table),
["FIELD"] = odbc_test_lib:to_upper(Fields2).
%%------------------------------------------------------------------------
num_bignum(suit) ->
[];
num_bignum(Config) when is_list(Config) ->
- Ref = proplists:get_value(connection_ref, Config),
+ Ref = proplists:get_value(connection_ref, Config),
Table = proplists:get_value(tableName, Config),
{updated, _} = % Value == 0 || -1 driver dependent!
- odbc:sql_query(Ref, "CREATE TABLE " ++ Table ++
- "(FIELD DECIMAL (16,0))"),
- {updated, _} =
+ odbc:sql_query(Ref, "CREATE TABLE " ++ Table ++
+ "(FIELD DECIMAL (16,0))"),
+ {updated, _} =
odbc:sql_query(Ref, "INSERT INTO " ++ Table ++" VALUES(1.6)"),
- {selected, Fields, [{"2"}]} =
+ ExpectedValue1 = ?RDBMS:expected_value(16, 0, 1.6),
+ {selected, Fields, [{ExpectedValue1}]} =
odbc:sql_query(Ref,"SELECT FIELD FROM " ++ Table),
["FIELD"] = odbc_test_lib:to_upper(Fields),
%% Clean up
{updated, _} = % Value == 0 || -1 driver dependent!
- odbc:sql_query(Ref, "DROP TABLE " ++ Table),
+ odbc:sql_query(Ref, "DROP TABLE " ++ Table),
{updated, _} = % Value == 0 || -1 driver dependent!
- odbc:sql_query(Ref, "CREATE TABLE " ++ Table ++
- "(FIELD DECIMAL (16,1))"),
- {updated, _} =
+ odbc:sql_query(Ref, "CREATE TABLE " ++ Table ++
+ "(FIELD DECIMAL (16,1))"),
+ {updated, _} =
odbc:sql_query(Ref, "INSERT INTO " ++ Table ++" VALUES(1.6)"),
- {selected, Fields1, [{"1.6"}]} =
+ ExpectedValue2 = ?RDBMS:expected_value(16, 1, 1.6),
+ {selected, Fields1, [{ExpectedValue2}]} =
odbc:sql_query(Ref,"SELECT FIELD FROM " ++ Table),
["FIELD"] = odbc_test_lib:to_upper(Fields1).
@@ -1383,9 +1403,9 @@ utf8() ->
utf8(suit) ->
[];
utf8(Config) when is_list(Config) ->
- Ref = proplists:get_value(connection_ref, Config),
+ Ref = proplists:get_value(connection_ref, Config),
Table = proplists:get_value(tableName, Config),
-
+
odbc:sql_query(Ref, "CREATE TABLE " ++ Table ++ "(FIELD text)"),
Latin1Data = ["ÖÄÅÄÖÅäöå",
@@ -1400,26 +1420,26 @@ utf8(Config) when is_list(Config) ->
"Row 10",
"Row 11",
"Row 12"],
-
+
UnicodeIn = lists:map(fun(String) ->
unicode:characters_to_binary(String,latin1,utf8)
end,
Latin1Data),
-
+
ct:pal("UnicodeIn: ~p ~n",[UnicodeIn]),
{updated, _} = odbc:param_query(Ref,"INSERT INTO " ++ Table ++ "(FIELD) values(?)",
[{{sql_varchar,50}, UnicodeIn}]),
-
+
{selected,_,UnicodeOut} = odbc:sql_query(Ref,"SELECT * FROM " ++ Table),
ct:pal("UnicodeOut: ~p~n", [UnicodeOut]),
-
+
Result = lists:map(fun({Char}) ->
unicode:characters_to_list(Char,utf8)
end, UnicodeOut),
ct:pal("Result: ~p ~n", [Result]),
-
+
Latin1Data = Result.
%%------------------------------------------------------------------------
@@ -1457,11 +1477,11 @@ nvarchar(Config) when is_list(Config) ->
timestamp(suit) ->
[];
timestamp(Config) when is_list(Config) ->
- Ref = proplists:get_value(connection_ref, Config),
+ Ref = proplists:get_value(connection_ref, Config),
Table = proplists:get_value(tableName, Config),
{updated, _} = % Value == 0 || -1 driver dependent!
- odbc:sql_query(Ref, "CREATE TABLE " ++ Table ++
+ odbc:sql_query(Ref, "CREATE TABLE " ++ Table ++
?RDBMS:create_timestamp_table()),
Data = [calendar:local_time(),
@@ -1470,13 +1490,13 @@ timestamp(Config) when is_list(Config) ->
{{2009,6,19},{20,54,59}},
{{2009,6,20},{20,54,59}},
{{2009,6,21},{20,54,59}}],
-
+
{updated, _} = odbc:param_query(Ref,"INSERT INTO " ++ Table ++ "(FIELD) values(?)",
[{sql_timestamp,Data}]),
-
- %%% Crate list or database table rows
+
+ %%% Crate list or database table rows
TimeStamps = lists:map(fun(Value) -> {Value} end, Data),
-
+
{selected,_, TimeStamps} = odbc:sql_query(Ref, "SELECT * FROM " ++ Table).
%%------------------------------------------------------------------------
diff --git a/lib/odbc/test/odbc_query_SUITE.erl b/lib/odbc/test/odbc_query_SUITE.erl
index c283872965c9..70f08a2b0367 100644
--- a/lib/odbc/test/odbc_query_SUITE.erl
+++ b/lib/odbc/test/odbc_query_SUITE.erl
@@ -32,15 +32,15 @@
%% all(Arg) -> [Doc] | [Case] | {skip, Comment}
%% Arg - doc | suite
%% Doc - string()
-%% Case - atom()
-%% Name of a test case function.
+%% Case - atom()
+%% Name of a test case function.
%% Comment - string()
%% Description: Returns documentation/test cases in this test suite
-%% or a skip tuple if the platform is not supported.
+%% or a skip tuple if the platform is not supported.
%%--------------------------------------------------------------------
suite() -> [{ct_hooks,[ts_install_cth]}].
-all() ->
+all() ->
case odbc_test_lib:odbc_check() of
ok ->
[stored_proc, sql_query, next, {group, scrollable_cursors}, select_count,
@@ -53,7 +53,7 @@ all() ->
Other -> {skip, Other}
end.
-groups() ->
+groups() ->
[{multiple_result_sets, [], [multiple_select_result_sets,
multiple_mix_result_sets,
multiple_result_sets_error]},
@@ -161,10 +161,10 @@ init_per_testcase(_Case, Config) ->
end_per_testcase(_Case, Config) ->
Ref = proplists:get_value(connection_ref, Config),
ok = odbc:disconnect(Ref),
- %% Clean up if needed
+ %% Clean up if needed
Table = proplists:get_value(tableName, Config),
{ok, NewRef} = odbc:connect(?RDBMS:connection_string(), odbc_test_lib:platform_options()),
- odbc:sql_query(NewRef, "DROP TABLE " ++ Table),
+ odbc:sql_query(NewRef, "DROP TABLE " ++ Table),
odbc:disconnect(NewRef).
%%-------------------------------------------------------------------------
@@ -196,32 +196,32 @@ sql_query(Config) when is_list(Config) ->
Table = proplists:get_value(tableName, Config),
{updated, _} =
- odbc:sql_query(Ref,
- "CREATE TABLE " ++ Table ++
+ odbc:sql_query(Ref,
+ "CREATE TABLE " ++ Table ++
" (ID integer, DATA varchar(10))"),
- {updated, Count} =
+ {updated, Count} =
odbc:sql_query(Ref, "INSERT INTO " ++ Table ++ " VALUES(1,'bar')"),
true = odbc_test_lib:check_row_count(1, Count),
InsertResult = ?RDBMS:insert_result(),
- InsertResult =
+ InsertResult =
odbc:sql_query(Ref, "SELECT * FROM " ++ Table),
- {updated, NewCount} =
- odbc:sql_query(Ref, "UPDATE " ++ Table ++
+ {updated, NewCount} =
+ odbc:sql_query(Ref, "UPDATE " ++ Table ++
" SET DATA = 'foo' WHERE ID = 1"),
-
+
true = odbc_test_lib:check_row_count(1, NewCount),
UpdateResult = ?RDBMS:update_result(),
- UpdateResult =
+ UpdateResult =
odbc:sql_query(Ref, "SELECT * FROM " ++ Table),
- {updated, NewCount1} = odbc:sql_query(Ref, "DELETE FROM " ++ Table ++
+ {updated, NewCount1} = odbc:sql_query(Ref, "DELETE FROM " ++ Table ++
" WHERE ID = 1"),
-
+
true = odbc_test_lib:check_row_count(1, NewCount1),
{selected, Fields, []} =
@@ -231,7 +231,7 @@ sql_query(Config) when is_list(Config) ->
ok.
%%-------------------------------------------------------------------------
-select_count() ->
+select_count() ->
[{doc, "Tests select_count/[2,3]'s timeout, "
" select_count's functionality will be better tested by other tests "
" such as first."}].
@@ -240,16 +240,16 @@ select_count(Config) when is_list(Config) ->
Ref = proplists:get_value(connection_ref, Config),
Table = proplists:get_value(tableName, Config),
- {updated, _} = odbc:sql_query(Ref,
+ {updated, _} = odbc:sql_query(Ref,
"CREATE TABLE " ++ Table ++
" (ID integer)"),
{updated, Count} = odbc:sql_query(Ref, "INSERT INTO " ++ Table ++
" VALUES(1)"),
true = odbc_test_lib:check_row_count(1, Count),
- {ok, _} =
+ {ok, _} =
odbc:select_count(Ref, "SELECT * FROM " ++ Table, ?TIMEOUT),
- {'EXIT', {function_clause, _}} =
+ {'EXIT', {function_clause, _}} =
(catch odbc:select_count(Ref, "SELECT * FROM ", -1)),
ok.
%%-------------------------------------------------------------------------
@@ -259,10 +259,10 @@ first(Config) when is_list(Config) ->
Ref = proplists:get_value(connection_ref, Config),
Table = proplists:get_value(tableName, Config),
- {updated, _} = odbc:sql_query(Ref,
+ {updated, _} = odbc:sql_query(Ref,
"CREATE TABLE " ++ Table ++
" (ID integer)"),
-
+
{updated, Count} = odbc:sql_query(Ref, "INSERT INTO " ++ Table ++
" VALUES(1)"),
true = odbc_test_lib:check_row_count(1, Count),
@@ -274,7 +274,7 @@ first(Config) when is_list(Config) ->
FirstResult = ?RDBMS:selected_ID(1, first),
FirstResult = odbc:first(Ref),
- FirstResult = odbc:first(Ref, ?TIMEOUT),
+ FirstResult = odbc:first(Ref, ?TIMEOUT),
{'EXIT', {function_clause, _}} = (catch odbc:first(Ref, -1)),
ok.
@@ -285,7 +285,7 @@ last(Config) when is_list(Config) ->
Ref = proplists:get_value(connection_ref, Config),
Table = proplists:get_value(tableName, Config),
- {updated, _} = odbc:sql_query(Ref,
+ {updated, _} = odbc:sql_query(Ref,
"CREATE TABLE " ++ Table ++
" (ID integer)"),
@@ -300,7 +300,7 @@ last(Config) when is_list(Config) ->
LastResult = ?RDBMS:selected_ID(2, last),
LastResult = odbc:last(Ref),
- LastResult = odbc:last(Ref, ?TIMEOUT),
+ LastResult = odbc:last(Ref, ?TIMEOUT),
{'EXIT', {function_clause, _}} = (catch odbc:last(Ref, -1)),
ok.
@@ -311,7 +311,7 @@ next(Config) when is_list(Config) ->
Ref = proplists:get_value(connection_ref, Config),
Table = proplists:get_value(tableName, Config),
- {updated, _} = odbc:sql_query(Ref,
+ {updated, _} = odbc:sql_query(Ref,
"CREATE TABLE " ++ Table ++
" (ID integer)"),
@@ -326,7 +326,7 @@ next(Config) when is_list(Config) ->
NextResult = ?RDBMS:selected_ID(1, next),
NextResult = odbc:next(Ref),
NextResult2 = ?RDBMS:selected_ID(2, next),
- NextResult2 = odbc:next(Ref, ?TIMEOUT),
+ NextResult2 = odbc:next(Ref, ?TIMEOUT),
{'EXIT', {function_clause, _}} = (catch odbc:next(Ref, -1)),
ok.
%%-------------------------------------------------------------------------
@@ -336,7 +336,7 @@ prev(Config) when is_list(Config) ->
Ref = proplists:get_value(connection_ref, Config),
Table = proplists:get_value(tableName, Config),
- {updated, _} = odbc:sql_query(Ref,
+ {updated, _} = odbc:sql_query(Ref,
"CREATE TABLE " ++ Table ++
" (ID integer)"),
@@ -354,7 +354,7 @@ prev(Config) when is_list(Config) ->
PrevResult = odbc:prev(Ref),
odbc:last(Ref), % Position cursor last so there will be a prev
- PrevResult = odbc:prev(Ref, ?TIMEOUT),
+ PrevResult = odbc:prev(Ref, ?TIMEOUT),
{'EXIT', {function_clause, _}} = (catch odbc:prev(Ref, -1)),
ok.
%%-------------------------------------------------------------------------
@@ -365,7 +365,7 @@ select_next(Config) when is_list(Config) ->
Ref = proplists:get_value(connection_ref, Config),
Table = proplists:get_value(tableName, Config),
- {updated, _} = odbc:sql_query(Ref,
+ {updated, _} = odbc:sql_query(Ref,
"CREATE TABLE " ++ Table ++
" (ID integer)"),
@@ -380,15 +380,15 @@ select_next(Config) when is_list(Config) ->
{updated, 1} = odbc:sql_query(Ref, "INSERT INTO " ++ Table ++
" VALUES(5)"),
- {ok, _} = odbc:select_count(Ref, "SELECT * FROM " ++ Table),
+ {ok, _} = odbc:select_count(Ref, "SELECT * FROM " ++ Table),
SelectResult1 = ?RDBMS:selected_next_N(1),
SelectResult1 = odbc:select(Ref, next, 3),
%% Test that selecting stops at the end of the result set
SelectResult2 = ?RDBMS:selected_next_N(2),
- SelectResult2 = odbc:select(Ref, next, 3, ?TIMEOUT),
- {'EXIT',{function_clause, _}} =
+ SelectResult2 = odbc:select(Ref, next, 3, ?TIMEOUT),
+ {'EXIT',{function_clause, _}} =
(catch odbc:select(Ref, next, 2, -1)),
%% If you try fetching data beyond the the end of result set,
@@ -406,14 +406,14 @@ select_relative(Config) when is_list(Config) ->
Ref = proplists:get_value(connection_ref, Config),
Table = proplists:get_value(tableName, Config),
- {updated, _} = odbc:sql_query(Ref,
+ {updated, _} = odbc:sql_query(Ref,
"CREATE TABLE " ++ Table ++
" (ID integer)"),
{updated, 1} = odbc:sql_query(Ref, "INSERT INTO " ++ Table ++
" VALUES(1)"),
{updated, 1} = odbc:sql_query(Ref, "INSERT INTO " ++ Table ++
- " VALUES(2)"),
+ " VALUES(2)"),
{updated, 1} = odbc:sql_query(Ref, "INSERT INTO " ++ Table ++
" VALUES(3)"),
{updated, 1} = odbc:sql_query(Ref, "INSERT INTO " ++ Table ++
@@ -435,7 +435,7 @@ select_relative(Config) when is_list(Config) ->
%% Test that selecting stops at the end of the result set
SelectResult2 = ?RDBMS:selected_relative_N(2),
SelectResult2 = odbc:select(Ref, {relative, 3}, 3, ?TIMEOUT),
- {'EXIT',{function_clause, _}} =
+ {'EXIT',{function_clause, _}} =
(catch odbc:select(Ref, {relative, 3} , 2, -1)),
ok.
@@ -447,7 +447,7 @@ select_absolute(Config) when is_list(Config) ->
Ref = proplists:get_value(connection_ref, Config),
Table = proplists:get_value(tableName, Config),
- {updated, _} = odbc:sql_query(Ref,
+ {updated, _} = odbc:sql_query(Ref,
"CREATE TABLE " ++ Table ++
" (ID integer)"),
@@ -461,7 +461,7 @@ select_absolute(Config) when is_list(Config) ->
" VALUES(4)"),
{updated, 1} = odbc:sql_query(Ref, "INSERT INTO " ++ Table ++
" VALUES(5)"),
- {ok, _} = odbc:select_count(Ref, "SELECT * FROM " ++ Table),
+ {ok, _} = odbc:select_count(Ref, "SELECT * FROM " ++ Table),
SelectResult1 = ?RDBMS:selected_absolute_N(1),
SelectResult1 = odbc:select(Ref, {absolute, 1}, 3),
@@ -469,7 +469,7 @@ select_absolute(Config) when is_list(Config) ->
%% Test that selecting stops at the end of the result set
SelectResult2 = ?RDBMS:selected_absolute_N(2),
SelectResult2 = odbc:select(Ref, {absolute, 1}, 6, ?TIMEOUT),
- {'EXIT',{function_clause, _}} =
+ {'EXIT',{function_clause, _}} =
(catch odbc:select(Ref, {absolute, 1}, 2, -1)),
ok.
@@ -477,15 +477,15 @@ select_absolute(Config) when is_list(Config) ->
create_table_twice() ->
[{doc, "Test what happens if you try to create the same table twice."}].
create_table_twice(Config) when is_list(Config) ->
- Ref = proplists:get_value(connection_ref, Config),
+ Ref = proplists:get_value(connection_ref, Config),
Table = proplists:get_value(tableName, Config),
- {updated, _} =
- odbc:sql_query(Ref,
+ {updated, _} =
+ odbc:sql_query(Ref,
"CREATE TABLE " ++ Table ++
" (ID integer, DATA varchar(10))"),
- {error, Error} =
- odbc:sql_query(Ref,
+ {error, Error} =
+ odbc:sql_query(Ref,
"CREATE TABLE " ++ Table ++
" (ID integer, DATA varchar(10))"),
is_driver_error(Error),
@@ -495,11 +495,11 @@ create_table_twice(Config) when is_list(Config) ->
delete_table_twice() ->
[{doc, "Test what happens if you try to delete the same table twice."}].
delete_table_twice(Config) when is_list(Config) ->
- Ref = proplists:get_value(connection_ref, Config),
+ Ref = proplists:get_value(connection_ref, Config),
Table = proplists:get_value(tableName, Config),
- {updated, _} =
- odbc:sql_query(Ref,
+ {updated, _} =
+ odbc:sql_query(Ref,
"CREATE TABLE " ++ Table ++
" (ID integer, DATA varchar(10))"),
{updated, _} = odbc:sql_query(Ref, "DROP TABLE " ++ Table),
@@ -512,15 +512,15 @@ duplicate_key() ->
[{doc, "Test what happens if you try to use the same key twice"}].
duplicate_key(suit) -> [];
duplicate_key(Config) when is_list(Config) ->
- Ref = proplists:get_value(connection_ref, Config),
+ Ref = proplists:get_value(connection_ref, Config),
Table = proplists:get_value(tableName, Config),
- {updated, _} =
- odbc:sql_query(Ref,
+ {updated, _} =
+ odbc:sql_query(Ref,
"CREATE TABLE " ++ Table ++
" (ID integer, DATA char(10), PRIMARY KEY(ID))"),
- {updated, 1} =
+ {updated, 1} =
odbc:sql_query(Ref, "INSERT INTO " ++ Table ++ " VALUES(1,'bar')"),
{error, Error} =
@@ -533,12 +533,12 @@ not_connection_owner() ->
[{doc, "Test what happens if a process that did not start the connection"
" tries to acess it."}].
not_connection_owner(Config) when is_list(Config) ->
- Ref = proplists:get_value(connection_ref, Config),
+ Ref = proplists:get_value(connection_ref, Config),
Table = proplists:get_value(tableName, Config),
spawn_link(?MODULE, not_owner, [self(), Ref, Table]),
- receive
+ receive
continue ->
ok
end.
@@ -557,36 +557,36 @@ no_result_set() ->
[{doc, "Tests what happens if you try to use a function that needs an "
"associated result set when there is none."}].
no_result_set(Config) when is_list(Config) ->
- Ref = proplists:get_value(connection_ref, Config),
+ Ref = proplists:get_value(connection_ref, Config),
{error, result_set_does_not_exist} = odbc:first(Ref),
{error, result_set_does_not_exist} = odbc:last(Ref),
{error, result_set_does_not_exist} = odbc:next(Ref),
{error, result_set_does_not_exist} = odbc:prev(Ref),
{error, result_set_does_not_exist} = odbc:select(Ref, next, 1),
- {error, result_set_does_not_exist} =
+ {error, result_set_does_not_exist} =
odbc:select(Ref, {absolute, 2}, 1),
- {error, result_set_does_not_exist} =
+ {error, result_set_does_not_exist} =
odbc:select(Ref, {relative, 2}, 1),
ok.
%%-------------------------------------------------------------------------
query_error() ->
[{doc, "Test what happens if there is an error in the query."}].
query_error(Config) when is_list(Config) ->
- Ref = proplists:get_value(connection_ref, Config),
+ Ref = proplists:get_value(connection_ref, Config),
Table = proplists:get_value(tableName, Config),
- {updated, _} =
- odbc:sql_query(Ref,
+ {updated, _} =
+ odbc:sql_query(Ref,
"CREATE TABLE " ++ Table ++
" (ID integer, DATA char(10), PRIMARY KEY(ID))"),
- {updated, 1} =
+ {updated, 1} =
odbc:sql_query(Ref, "INSERT INTO " ++ Table ++ " VALUES(1,'bar')"),
- {error, _} =
+ {error, _} =
odbc:sql_query(Ref, "INSERT INTO " ++ Table ++ " VALUES(1,'bar')"),
- {error, _} =
+ {error, _} =
odbc:sql_query(Ref, "INSERT ONTO " ++ Table ++ " VALUES(1,'bar')"),
ok.
@@ -596,33 +596,33 @@ multiple_select_result_sets() ->
multiple_select_result_sets(Config) when is_list(Config) ->
case ?RDBMS of
sqlserver ->
- Ref = proplists:get_value(connection_ref, Config),
+ Ref = proplists:get_value(connection_ref, Config),
Table = proplists:get_value(tableName, Config),
-
- {updated, _} =
- odbc:sql_query(Ref,
+
+ {updated, _} =
+ odbc:sql_query(Ref,
"CREATE TABLE " ++ Table ++
" (ID integer, DATA varchar(10), "
"PRIMARY KEY(ID))"),
- {updated, 1} =
- odbc:sql_query(Ref, "INSERT INTO " ++ Table ++
+ {updated, 1} =
+ odbc:sql_query(Ref, "INSERT INTO " ++ Table ++
" VALUES(1,'bar')"),
-
- {updated, 1} =
- odbc:sql_query(Ref, "INSERT INTO " ++ Table ++
+
+ {updated, 1} =
+ odbc:sql_query(Ref, "INSERT INTO " ++ Table ++
" VALUES(2, 'foo')"),
-
+
MultipleResult = ?RDBMS:multiple_select(),
-
- MultipleResult =
- odbc:sql_query(Ref, "SELECT * FROM " ++ Table ++
- "; SELECT DATA FROM "++ Table ++
+
+ MultipleResult =
+ odbc:sql_query(Ref, "SELECT * FROM " ++ Table ++
+ "; SELECT DATA FROM "++ Table ++
" WHERE ID=2"),
ok;
_ ->
{skip, "multiple result_set not supported"}
end.
-
+
%%-------------------------------------------------------------------------
multiple_mix_result_sets() ->
[{doc, "Test what happens if you have a batch of select and other type of"
@@ -630,25 +630,25 @@ multiple_mix_result_sets() ->
multiple_mix_result_sets(Config) when is_list(Config) ->
case ?RDBMS of
sqlserver ->
- Ref = proplists:get_value(connection_ref, Config),
+ Ref = proplists:get_value(connection_ref, Config),
Table = proplists:get_value(tableName, Config),
-
- {updated, _} =
- odbc:sql_query(Ref,
+
+ {updated, _} =
+ odbc:sql_query(Ref,
"CREATE TABLE " ++ Table ++
" (ID integer, DATA varchar(10), "
"PRIMARY KEY(ID))"),
- {updated, 1} =
- odbc:sql_query(Ref, "INSERT INTO " ++ Table ++
+ {updated, 1} =
+ odbc:sql_query(Ref, "INSERT INTO " ++ Table ++
" VALUES(1,'bar')"),
MultipleResult = ?RDBMS:multiple_mix(),
-
- MultipleResult =
- odbc:sql_query(Ref, "INSERT INTO " ++ Table ++
- " VALUES(2,'foo'); UPDATE " ++ Table ++
+
+ MultipleResult =
+ odbc:sql_query(Ref, "INSERT INTO " ++ Table ++
+ " VALUES(2,'foo'); UPDATE " ++ Table ++
" SET DATA = 'foobar' WHERE ID =1;SELECT "
- "* FROM "
+ "* FROM "
++ Table ++ ";DELETE FROM " ++ Table ++
" WHERE ID =1; SELECT DATA FROM " ++ Table),
ok;
@@ -661,62 +661,62 @@ multiple_result_sets_error() ->
multiple_result_sets_error(Config) when is_list(Config) ->
case ?RDBMS of
sqlserver ->
- Ref = proplists:get_value(connection_ref, Config),
+ Ref = proplists:get_value(connection_ref, Config),
Table = proplists:get_value(tableName, Config),
-
- {updated, _} =
- odbc:sql_query(Ref,
+
+ {updated, _} =
+ odbc:sql_query(Ref,
"CREATE TABLE " ++ Table ++
" (ID integer, DATA varchar(10), "
"PRIMARY KEY(ID))"),
- {updated, 1} =
- odbc:sql_query(Ref, "INSERT INTO " ++ Table ++
+ {updated, 1} =
+ odbc:sql_query(Ref, "INSERT INTO " ++ Table ++
" VALUES(1,'bar')"),
-
- {error, Error} =
- odbc:sql_query(Ref, "INSERT INTO " ++ Table ++
+
+ {error, Error} =
+ odbc:sql_query(Ref, "INSERT INTO " ++ Table ++
" VALUES(1,'foo'); SELECT * FROM " ++ Table),
is_driver_error(Error),
-
- {error, NewError} =
- odbc:sql_query(Ref, "SELECT * FROM "
- ++ Table ++ ";INSERT INTO " ++ Table ++
+
+ {error, NewError} =
+ odbc:sql_query(Ref, "SELECT * FROM "
+ ++ Table ++ ";INSERT INTO " ++ Table ++
" VALUES(1,'foo')"),
is_driver_error(NewError),
ok;
_ ->
{skip, "multiple result_set not supported"}
- end.
+ end.
%%-------------------------------------------------------------------------
param_insert_tiny_int()->
[{doc,"Test insertion of tiny ints by parameterized queries."}].
param_insert_tiny_int(Config) when is_list(Config) ->
- case ?RDBMS of
+ case ?RDBMS of
sqlserver ->
- Ref = proplists:get_value(connection_ref, Config),
+ Ref = proplists:get_value(connection_ref, Config),
Table = proplists:get_value(tableName, Config),
-
- {updated, _} =
- odbc:sql_query(Ref,
+
+ {updated, _} =
+ odbc:sql_query(Ref,
"CREATE TABLE " ++ Table ++
" (FIELD TINYINT)"),
-
- {updated, Count} =
- odbc:param_query(Ref, "INSERT INTO " ++ Table ++
- "(FIELD) VALUES(?)",
+
+ {updated, Count} =
+ odbc:param_query(Ref, "INSERT INTO " ++ Table ++
+ "(FIELD) VALUES(?)",
[{sql_tinyint, [1, 2]}],
?TIMEOUT),%Make sure to test timeout clause
-
+
true = odbc_test_lib:check_row_count(2, Count),
-
+
InsertResult = ?RDBMS:param_select_tiny_int(),
-
- InsertResult =
+
+ InsertResult =
odbc:sql_query(Ref, "SELECT * FROM " ++ Table),
-
- {'EXIT',{badarg,odbc,param_query,'Params'}} =
- (catch odbc:param_query(Ref, "INSERT INTO " ++ Table ++
+
+ {'EXIT',{badarg,odbc,param_query,'Params'}} =
+ (catch odbc:param_query(Ref, "INSERT INTO " ++ Table ++
"(FIELD) VALUES(?)",
[{sql_tinyint, [1, "2"]}])),
ok;
@@ -727,16 +727,16 @@ param_insert_tiny_int(Config) when is_list(Config) ->
param_insert_small_int()->
[{doc,"Test insertion of small ints by parameterized queries."}].
param_insert_small_int(Config) when is_list(Config) ->
- Ref = proplists:get_value(connection_ref, Config),
+ Ref = proplists:get_value(connection_ref, Config),
Table = proplists:get_value(tableName, Config),
- {updated, _} =
- odbc:sql_query(Ref,
+ {updated, _} =
+ odbc:sql_query(Ref,
"CREATE TABLE " ++ Table ++
" (FIELD SMALLINT)"),
- {updated, Count} =
- odbc:param_query(Ref, "INSERT INTO " ++ Table ++
+ {updated, Count} =
+ odbc:param_query(Ref, "INSERT INTO " ++ Table ++
"(FIELD) VALUES(?)", [{sql_smallint, [1, 2]}],
?TIMEOUT), %% Make sure to test timeout clause
@@ -744,41 +744,41 @@ param_insert_small_int(Config) when is_list(Config) ->
InsertResult = ?RDBMS:param_select_small_int(),
- InsertResult =
+ InsertResult =
odbc:sql_query(Ref, "SELECT * FROM " ++ Table),
- {'EXIT',{badarg,odbc,param_query,'Params'}} =
- (catch odbc:param_query(Ref, "INSERT INTO " ++ Table ++
+ {'EXIT',{badarg,odbc,param_query,'Params'}} =
+ (catch odbc:param_query(Ref, "INSERT INTO " ++ Table ++
"(FIELD) VALUES(?)",
- [{sql_smallint, [1, "2"]}])),
+ [{sql_smallint, [1, "2"]}])),
ok.
%%-------------------------------------------------------------------------
param_insert_int()->
[{doc,"Test insertion of ints by parameterized queries."}].
param_insert_int(Config) when is_list(Config) ->
- Ref = proplists:get_value(connection_ref, Config),
+ Ref = proplists:get_value(connection_ref, Config),
Table = proplists:get_value(tableName, Config),
- {updated, _} =
- odbc:sql_query(Ref,
+ {updated, _} =
+ odbc:sql_query(Ref,
"CREATE TABLE " ++ Table ++
" (FIELD INT)"),
Int = ?RDBMS:small_int_max() + 1,
- {updated, Count} = odbc:param_query(Ref, "INSERT INTO " ++ Table ++
- "(FIELD) VALUES(?)",
+ {updated, Count} = odbc:param_query(Ref, "INSERT INTO " ++ Table ++
+ "(FIELD) VALUES(?)",
[{sql_integer, [1, Int]}]),
true = odbc_test_lib:check_row_count(2, Count),
-
+
InsertResult = ?RDBMS:param_select_int(),
- InsertResult =
+ InsertResult =
odbc:sql_query(Ref, "SELECT * FROM " ++ Table),
- {'EXIT',{badarg,odbc,param_query,'Params'}} =
- (catch odbc:param_query(Ref, "INSERT INTO " ++ Table ++
+ {'EXIT',{badarg,odbc,param_query,'Params'}} =
+ (catch odbc:param_query(Ref, "INSERT INTO " ++ Table ++
"(FIELD) VALUES(?)",
[{sql_integer, [1, "2"]}])),
ok.
@@ -787,123 +787,123 @@ param_insert_int(Config) when is_list(Config) ->
param_insert_integer()->
[{doc,"Test insertion of integers by parameterized queries."}].
param_insert_integer(Config) when is_list(Config) ->
- Ref = proplists:get_value(connection_ref, Config),
+ Ref = proplists:get_value(connection_ref, Config),
Table = proplists:get_value(tableName, Config),
- {updated, _} =
- odbc:sql_query(Ref,
+ {updated, _} =
+ odbc:sql_query(Ref,
"CREATE TABLE " ++ Table ++
" (FIELD INTEGER)"),
Int = ?RDBMS:small_int_max() + 1,
- {updated, Count} = odbc:param_query(Ref, "INSERT INTO " ++ Table ++
- "(FIELD) VALUES(?)",
+ {updated, Count} = odbc:param_query(Ref, "INSERT INTO " ++ Table ++
+ "(FIELD) VALUES(?)",
[{sql_integer, [1, Int]}]),
true = odbc_test_lib:check_row_count(2, Count),
InsertResult = ?RDBMS:param_select_int(),
- InsertResult =
+ InsertResult =
odbc:sql_query(Ref, "SELECT * FROM " ++ Table),
- {'EXIT',{badarg,odbc,param_query,'Params'}} =
- (catch odbc:param_query(Ref, "INSERT INTO " ++ Table ++
- "(FIELD) VALUES(?)",
- [{sql_integer, [1, 2.3]}])),
+ {'EXIT',{badarg,odbc,param_query,'Params'}} =
+ (catch odbc:param_query(Ref, "INSERT INTO " ++ Table ++
+ "(FIELD) VALUES(?)",
+ [{sql_integer, [1, 2.3]}])),
ok.
%%-------------------------------------------------------------------------
param_insert_decimal()->
[{doc,"Test insertion of decimal numbers by parameterized queries."}].
param_insert_decimal(Config) when is_list(Config) ->
- Ref = proplists:get_value(connection_ref, Config),
+ Ref = proplists:get_value(connection_ref, Config),
Table = proplists:get_value(tableName, Config),
- {updated, _} =
- odbc:sql_query(Ref,
+ {updated, _} =
+ odbc:sql_query(Ref,
"CREATE TABLE " ++ Table ++
" (FIELD DECIMAL (3,0))"),
- {updated, Count} = odbc:param_query(Ref, "INSERT INTO " ++ Table ++
- "(FIELD) VALUES(?)",
+ {updated, Count} = odbc:param_query(Ref, "INSERT INTO " ++ Table ++
+ "(FIELD) VALUES(?)",
[{{sql_decimal, 3, 0}, [1, 2]}]),
true = odbc_test_lib:check_row_count(2, Count),
-
+
InsertResult = ?RDBMS:param_select_decimal(),
- InsertResult =
+ InsertResult =
odbc:sql_query(Ref, "SELECT * FROM " ++ Table),
- {'EXIT',{badarg,odbc,param_query,'Params'}} =
- (catch odbc:param_query(Ref, "INSERT INTO " ++ Table ++
- "(FIELD) VALUES(?)",
+ {'EXIT',{badarg,odbc,param_query,'Params'}} =
+ (catch odbc:param_query(Ref, "INSERT INTO " ++ Table ++
+ "(FIELD) VALUES(?)",
[{{sql_decimal, 3, 0}, [1, "2"]}])),
odbc:sql_query(Ref, "DROP TABLE " ++ Table),
- {updated, _} =
- odbc:sql_query(Ref,
+ {updated, _} =
+ odbc:sql_query(Ref,
"CREATE TABLE " ++ Table ++
" (FIELD DECIMAL (3,1))"),
- {updated, NewCount} = odbc:param_query(Ref, "INSERT INTO " ++ Table ++
- "(FIELD) VALUES(?)",
+ {updated, NewCount} = odbc:param_query(Ref, "INSERT INTO " ++ Table ++
+ "(FIELD) VALUES(?)",
[{{sql_decimal, 3, 1}, [0.25]}]),
true = odbc_test_lib:check_row_count(1, NewCount),
-
- {selected, Fields, [{Value}]} =
+
+ {selected, Fields, [{Value}]} =
odbc:sql_query(Ref, "SELECT * FROM " ++ Table),
["FIELD"] = odbc_test_lib:to_upper(Fields),
-
+
odbc_test_lib:match_float(Value, 0.3, 0.01),
-
+
ok.
%%-------------------------------------------------------------------------
param_insert_numeric()->
[{doc,"Test insertion of numeric numbers by parameterized queries."}].
param_insert_numeric(Config) when is_list(Config) ->
- Ref = proplists:get_value(connection_ref, Config),
+ Ref = proplists:get_value(connection_ref, Config),
Table = proplists:get_value(tableName, Config),
- {updated, _} =
- odbc:sql_query(Ref,
+ {updated, _} =
+ odbc:sql_query(Ref,
"CREATE TABLE " ++ Table ++
" (FIELD NUMERIC (3,0))"),
- {updated, Count} = odbc:param_query(Ref, "INSERT INTO " ++ Table ++
- "(FIELD) VALUES(?)",
+ {updated, Count} = odbc:param_query(Ref, "INSERT INTO " ++ Table ++
+ "(FIELD) VALUES(?)",
[{{sql_numeric,3,0}, [1, 2]}]),
true = odbc_test_lib:check_row_count(2, Count),
InsertResult = ?RDBMS:param_select_numeric(),
- InsertResult =
+ InsertResult =
odbc:sql_query(Ref, "SELECT * FROM " ++ Table),
- {'EXIT',{badarg,odbc,param_query,'Params'}} =
- (catch odbc:param_query(Ref, "INSERT INTO " ++ Table ++
- "(FIELD) VALUES(?)",
- [{{sql_decimal, 3, 0}, [1, "2"]}])),
+ {'EXIT',{badarg,odbc,param_query,'Params'}} =
+ (catch odbc:param_query(Ref, "INSERT INTO " ++ Table ++
+ "(FIELD) VALUES(?)",
+ [{{sql_decimal, 3, 0}, [1, "2"]}])),
odbc:sql_query(Ref, "DROP TABLE " ++ Table),
- {updated, _} =
- odbc:sql_query(Ref,
+ {updated, _} =
+ odbc:sql_query(Ref,
"CREATE TABLE " ++ Table ++
" (FIELD NUMERIC (3,1))"),
- {updated, NewCount} = odbc:param_query(Ref, "INSERT INTO " ++ Table ++
- "(FIELD) VALUES(?)",
+ {updated, NewCount} = odbc:param_query(Ref, "INSERT INTO " ++ Table ++
+ "(FIELD) VALUES(?)",
[{{sql_numeric, 3, 1}, [0.25]}]),
true = odbc_test_lib:check_row_count(1, NewCount),
- {selected, Fileds, [{Value}]} =
+ {selected, Fileds, [{Value}]} =
odbc:sql_query(Ref, "SELECT * FROM " ++ Table),
["FIELD"] = odbc_test_lib:to_upper(Fileds),
@@ -915,17 +915,17 @@ param_insert_numeric(Config) when is_list(Config) ->
param_insert_char()->
[{doc,"Test insertion of fixed length string by parameterized queries."}].
param_insert_char(Config) when is_list(Config) ->
- Ref = proplists:get_value(connection_ref, Config),
+ Ref = proplists:get_value(connection_ref, Config),
Table = proplists:get_value(tableName, Config),
- {updated, _} =
- odbc:sql_query(Ref,
+ {updated, _} =
+ odbc:sql_query(Ref,
"CREATE TABLE " ++ Table ++
" (FIELD CHAR (10))"),
- {updated, Count} = odbc:param_query(Ref, "INSERT INTO " ++ Table ++
- "(FIELD) VALUES(?)",
- [{{sql_char, 10},
+ {updated, Count} = odbc:param_query(Ref, "INSERT INTO " ++ Table ++
+ "(FIELD) VALUES(?)",
+ [{{sql_char, 10},
["foofoofoof", "0123456789"]}]),
true = odbc_test_lib:check_row_count(2, Count),
@@ -934,32 +934,32 @@ param_insert_char(Config) when is_list(Config) ->
["FIELD"] = odbc_test_lib:to_upper(Fileds),
- {error, _} = odbc:param_query(Ref, "INSERT INTO " ++ Table ++
- "(FIELD) VALUES(?)",
- [{{sql_char, 10},
+ {error, _} = odbc:param_query(Ref, "INSERT INTO " ++ Table ++
+ "(FIELD) VALUES(?)",
+ [{{sql_char, 10},
["foo", "01234567890"]}]),
- {'EXIT',{badarg,odbc,param_query,'Params'}} =
- (catch odbc:param_query(Ref, "INSERT INTO " ++ Table ++
+ {'EXIT',{badarg,odbc,param_query,'Params'}} =
+ (catch odbc:param_query(Ref, "INSERT INTO " ++ Table ++
"(FIELD) VALUES(?)",
- [{{sql_char, 10}, ["1", 2.3]}])),
+ [{{sql_char, 10}, ["1", 2.3]}])),
ok.
%%-------------------------------------------------------------------------
param_insert_character()->
[{doc,"Test insertion of fixed length string by parameterized queries."}].
param_insert_character(Config) when is_list(Config) ->
- Ref = proplists:get_value(connection_ref, Config),
+ Ref = proplists:get_value(connection_ref, Config),
Table = proplists:get_value(tableName, Config),
- {updated, _} =
- odbc:sql_query(Ref,
+ {updated, _} =
+ odbc:sql_query(Ref,
"CREATE TABLE " ++ Table ++
" (FIELD CHARACTER (10))"),
- {updated, Count} = odbc:param_query(Ref, "INSERT INTO " ++ Table ++
- "(FIELD) VALUES(?)",
- [{{sql_char, 10},
+ {updated, Count} = odbc:param_query(Ref, "INSERT INTO " ++ Table ++
+ "(FIELD) VALUES(?)",
+ [{{sql_char, 10},
["foofoofoof", "0123456789"]}]),
true = odbc_test_lib:check_row_count(2, Count),
@@ -969,34 +969,34 @@ param_insert_character(Config) when is_list(Config) ->
["FIELD"] = odbc_test_lib:to_upper(Fileds),
- {error, _} = odbc:param_query(Ref, "INSERT INTO " ++ Table ++
- "(FIELD) VALUES(?)",
- [{{sql_char, 10},
+ {error, _} = odbc:param_query(Ref, "INSERT INTO " ++ Table ++
+ "(FIELD) VALUES(?)",
+ [{{sql_char, 10},
["foo", "01234567890"]}]),
- {'EXIT',{badarg,odbc,param_query,'Params'}} =
- (catch odbc:param_query(Ref, "INSERT INTO " ++ Table ++
- "(FIELD) VALUES(?)",
- [{{sql_char, 10}, ["1", 2]}])),
+ {'EXIT',{badarg,odbc,param_query,'Params'}} =
+ (catch odbc:param_query(Ref, "INSERT INTO " ++ Table ++
+ "(FIELD) VALUES(?)",
+ [{{sql_char, 10}, ["1", 2]}])),
ok.
%%------------------------------------------------------------------------
param_insert_char_varying()->
[{doc,"Test insertion of variable length strings by parameterized queries."}].
param_insert_char_varying(Config) when is_list(Config) ->
- Ref = proplists:get_value(connection_ref, Config),
+ Ref = proplists:get_value(connection_ref, Config),
Table = proplists:get_value(tableName, Config),
- {updated, _} =
- odbc:sql_query(Ref,
+ {updated, _} =
+ odbc:sql_query(Ref,
"CREATE TABLE " ++ Table ++
" (FIELD CHAR VARYING(10))"),
- {updated, Count} = odbc:param_query(Ref, "INSERT INTO " ++ Table ++
- "(FIELD) VALUES(?)",
- [{{sql_varchar, 10},
+ {updated, Count} = odbc:param_query(Ref, "INSERT INTO " ++ Table ++
+ "(FIELD) VALUES(?)",
+ [{{sql_varchar, 10},
["foo", "0123456789"]}]),
-
+
true = odbc_test_lib:check_row_count(2, Count),
{selected, Fileds, [{"foo"}, {"0123456789"}]} =
@@ -1004,33 +1004,33 @@ param_insert_char_varying(Config) when is_list(Config) ->
["FIELD"] = odbc_test_lib:to_upper(Fileds),
- {error, _} = odbc:param_query(Ref, "INSERT INTO " ++ Table ++
- "(FIELD) VALUES(?)",
- [{{sql_varchar, 10},
+ {error, _} = odbc:param_query(Ref, "INSERT INTO " ++ Table ++
+ "(FIELD) VALUES(?)",
+ [{{sql_varchar, 10},
["foo", "01234567890"]}]),
- {'EXIT',{badarg,odbc,param_query,'Params'}} =
- (catch odbc:param_query(Ref, "INSERT INTO " ++ Table ++
- "(FIELD) VALUES(?)",
- [{{sql_varchar, 10}, ["1", 2.3]}])),
+ {'EXIT',{badarg,odbc,param_query,'Params'}} =
+ (catch odbc:param_query(Ref, "INSERT INTO " ++ Table ++
+ "(FIELD) VALUES(?)",
+ [{{sql_varchar, 10}, ["1", 2.3]}])),
ok.
%%-------------------------------------------------------------------------
param_insert_character_varying()->
[{doc,"Test insertion of variable length strings by parameterized queries."}].
param_insert_character_varying(Config) when is_list(Config) ->
- Ref = proplists:get_value(connection_ref, Config),
+ Ref = proplists:get_value(connection_ref, Config),
Table = proplists:get_value(tableName, Config),
- {updated, _} =
- odbc:sql_query(Ref,
+ {updated, _} =
+ odbc:sql_query(Ref,
"CREATE TABLE " ++ Table ++
" (FIELD CHARACTER VARYING(10))"),
- {updated, Count} = odbc:param_query(Ref, "INSERT INTO " ++ Table ++
- "(FIELD) VALUES(?)",
- [{{sql_varchar, 10},
+ {updated, Count} = odbc:param_query(Ref, "INSERT INTO " ++ Table ++
+ "(FIELD) VALUES(?)",
+ [{{sql_varchar, 10},
["foo", "0123456789"]}]),
true = odbc_test_lib:check_row_count(2, Count),
@@ -1040,30 +1040,30 @@ param_insert_character_varying(Config) when is_list(Config) ->
["FIELD"] = odbc_test_lib:to_upper(Fileds),
- {error, _} = odbc:param_query(Ref, "INSERT INTO " ++ Table ++
- "(FIELD) VALUES(?)",
- [{{sql_varchar, 10},
+ {error, _} = odbc:param_query(Ref, "INSERT INTO " ++ Table ++
+ "(FIELD) VALUES(?)",
+ [{{sql_varchar, 10},
["foo", "01234567890"]}]),
- {'EXIT',{badarg,odbc,param_query,'Params'}} =
- (catch odbc:param_query(Ref, "INSERT INTO " ++ Table ++
- "(FIELD) VALUES(?)",
- [{{sql_varchar, 10}, ["1", 2]}])),
+ {'EXIT',{badarg,odbc,param_query,'Params'}} =
+ (catch odbc:param_query(Ref, "INSERT INTO " ++ Table ++
+ "(FIELD) VALUES(?)",
+ [{{sql_varchar, 10}, ["1", 2]}])),
ok.
%%-------------------------------------------------------------------------
param_insert_float()->
[{doc,"Test insertion of floats by parameterized queries."}].
param_insert_float(Config) when is_list(Config) ->
- Ref = proplists:get_value(connection_ref, Config),
+ Ref = proplists:get_value(connection_ref, Config),
Table = proplists:get_value(tableName, Config),
- {updated, _} =
- odbc:sql_query(Ref,
+ {updated, _} =
+ odbc:sql_query(Ref,
"CREATE TABLE " ++ Table ++
" (FIELD FLOAT(5))"),
- {updated, Count} = odbc:param_query(Ref, "INSERT INTO " ++ Table ++
- "(FIELD) VALUES(?)",
+ {updated, Count} = odbc:param_query(Ref, "INSERT INTO " ++ Table ++
+ "(FIELD) VALUES(?)",
[{{sql_float,5}, [1.3, 1.2]}]),
true = odbc_test_lib:check_row_count(2, Count),
@@ -1073,7 +1073,7 @@ param_insert_float(Config) when is_list(Config) ->
["FIELD"] = odbc_test_lib:to_upper(Fileds),
- case (odbc_test_lib:match_float(Float1, 1.3, 0.000001) and
+ case (odbc_test_lib:match_float(Float1, 1.3, 0.000001) and
odbc_test_lib:match_float(Float2, 1.2, 0.000001)) of
true ->
ok;
@@ -1081,8 +1081,8 @@ param_insert_float(Config) when is_list(Config) ->
ct:fail(float_numbers_do_not_match)
end,
- {'EXIT',{badarg,odbc,param_query,'Params'}} =
- (catch odbc:param_query(Ref, "INSERT INTO " ++ Table ++
+ {'EXIT',{badarg,odbc,param_query,'Params'}} =
+ (catch odbc:param_query(Ref, "INSERT INTO " ++ Table ++
"(FIELD) VALUES(?)",
[{{sql_float, 5}, [1.0, "2"]}])),
ok.
@@ -1091,16 +1091,16 @@ param_insert_float(Config) when is_list(Config) ->
param_insert_real()->
[{doc,"Test insertion of real numbers by parameterized queries."}].
param_insert_real(Config) when is_list(Config) ->
- Ref = proplists:get_value(connection_ref, Config),
+ Ref = proplists:get_value(connection_ref, Config),
Table = proplists:get_value(tableName, Config),
- {updated, _} =
- odbc:sql_query(Ref,
+ {updated, _} =
+ odbc:sql_query(Ref,
"CREATE TABLE " ++ Table ++
" (FIELD REAL)"),
- {updated, Count} = odbc:param_query(Ref, "INSERT INTO " ++ Table ++
- "(FIELD) VALUES(?)",
+ {updated, Count} = odbc:param_query(Ref, "INSERT INTO " ++ Table ++
+ "(FIELD) VALUES(?)",
[{sql_real, [1.3, 1.2]}]),
true = odbc_test_lib:check_row_count(2, Count),
@@ -1112,7 +1112,7 @@ param_insert_real(Config) when is_list(Config) ->
["FIELD"] = odbc_test_lib:to_upper(Fileds),
- case (odbc_test_lib:match_float(Real1, 1.3, 0.000001) and
+ case (odbc_test_lib:match_float(Real1, 1.3, 0.000001) and
odbc_test_lib:match_float(Real2, 1.2, 0.000001)) of
true ->
ok;
@@ -1120,8 +1120,8 @@ param_insert_real(Config) when is_list(Config) ->
ct:fail(real_numbers_do_not_match)
end,
- {'EXIT',{badarg,odbc,param_query,'Params'}} =
- (catch odbc:param_query(Ref, "INSERT INTO " ++ Table ++
+ {'EXIT',{badarg,odbc,param_query,'Params'}} =
+ (catch odbc:param_query(Ref, "INSERT INTO " ++ Table ++
"(FIELD) VALUES(?)",
[{sql_real,[1.0, "2"]}])),
ok.
@@ -1130,16 +1130,16 @@ param_insert_real(Config) when is_list(Config) ->
param_insert_double()->
[{doc,"Test insertion of doubles by parameterized queries."}].
param_insert_double(Config) when is_list(Config) ->
- Ref = proplists:get_value(connection_ref, Config),
+ Ref = proplists:get_value(connection_ref, Config),
Table = proplists:get_value(tableName, Config),
- {updated, _} =
- odbc:sql_query(Ref,
+ {updated, _} =
+ odbc:sql_query(Ref,
"CREATE TABLE " ++ Table ++
" (FIELD DOUBLE PRECISION)"),
- {updated, Count} = odbc:param_query(Ref, "INSERT INTO " ++ Table ++
- "(FIELD) VALUES(?)",
+ {updated, Count} = odbc:param_query(Ref, "INSERT INTO " ++ Table ++
+ "(FIELD) VALUES(?)",
[{sql_double, [1.3, 1.2]}]),
true = odbc_test_lib:check_row_count(2, Count),
@@ -1149,7 +1149,7 @@ param_insert_double(Config) when is_list(Config) ->
["FIELD"] = odbc_test_lib:to_upper(Fileds),
- case (odbc_test_lib:match_float(Double1, 1.3, 0.000001) and
+ case (odbc_test_lib:match_float(Double1, 1.3, 0.000001) and
odbc_test_lib:match_float(Double2, 1.2, 0.000001)) of
true ->
ok;
@@ -1157,9 +1157,9 @@ param_insert_double(Config) when is_list(Config) ->
ct:fail(double_numbers_do_not_match)
end,
- {'EXIT',{badarg,odbc,param_query,'Params'}} =
- (catch odbc:param_query(Ref, "INSERT INTO " ++ Table ++
- "(FIELD) VALUES(?)",
+ {'EXIT',{badarg,odbc,param_query,'Params'}} =
+ (catch odbc:param_query(Ref, "INSERT INTO " ++ Table ++
+ "(FIELD) VALUES(?)",
[{sql_double, [1.0, "2"]}])),
ok.
@@ -1167,57 +1167,57 @@ param_insert_double(Config) when is_list(Config) ->
param_insert_mix()->
[{doc,"Test insertion of a mixture of datatypes by parameterized queries."}].
param_insert_mix(Config) when is_list(Config) ->
- Ref = proplists:get_value(connection_ref, Config),
+ Ref = proplists:get_value(connection_ref, Config),
Table = proplists:get_value(tableName, Config),
- {updated, _} =
- odbc:sql_query(Ref,
+ {updated, _} =
+ odbc:sql_query(Ref,
"CREATE TABLE " ++ Table ++
" (ID INTEGER, DATA CHARACTER VARYING(10),"
" PRIMARY KEY(ID))"),
- {updated, Count} = odbc:param_query(Ref, "INSERT INTO " ++ Table ++
+ {updated, Count} = odbc:param_query(Ref, "INSERT INTO " ++ Table ++
"(ID, DATA) VALUES(?, ?)",
- [{sql_integer, [1, 2]},
+ [{sql_integer, [1, 2]},
{{sql_varchar, 10}, ["foo", "bar"]}]),
true = odbc_test_lib:check_row_count(2, Count),
InsertResult = ?RDBMS:param_select_mix(),
- InsertResult =
+ InsertResult =
odbc:sql_query(Ref, "SELECT * FROM " ++ Table),
ok.
%%-------------------------------------------------------------------------
param_update()->
[{doc,"Test parameterized update query."}].
param_update(Config) when is_list(Config) ->
- Ref = proplists:get_value(connection_ref, Config),
+ Ref = proplists:get_value(connection_ref, Config),
Table = proplists:get_value(tableName, Config),
- {updated, _} =
- odbc:sql_query(Ref,
+ {updated, _} =
+ odbc:sql_query(Ref,
"CREATE TABLE " ++ Table ++
" (ID INTEGER, DATA CHARACTER VARYING(10),"
" PRIMARY KEY(ID))"),
- {updated, Count} = odbc:param_query(Ref, "INSERT INTO " ++ Table ++
+ {updated, Count} = odbc:param_query(Ref, "INSERT INTO " ++ Table ++
"(ID, DATA) VALUES(?, ?)",
- [{sql_integer, [1, 2, 3]},
- {{sql_varchar, 10},
+ [{sql_integer, [1, 2, 3]},
+ {{sql_varchar, 10},
["foo", "bar", "baz"]}]),
true = odbc_test_lib:check_row_count(3, Count),
{updated, NewCount} = odbc:param_query(Ref, "UPDATE " ++ Table ++
" SET DATA = 'foobar' WHERE ID = ?",
- [{sql_integer, [1, 2]}]),
+ [{sql_integer, [1, 2]}]),
true = odbc_test_lib:check_row_count(2, NewCount),
UpdateResult = ?RDBMS:param_update(),
- UpdateResult =
+ UpdateResult =
odbc:sql_query(Ref, "SELECT * FROM " ++ Table),
ok.
@@ -1226,18 +1226,18 @@ delete_nonexisting_row() -> % OTP-5759
[{doc, "Make a delete...where with false conditions (0 rows deleted). ",
"This used to give an error message (see ticket OTP-5759)."}].
delete_nonexisting_row(Config) when is_list(Config) ->
- Ref = proplists:get_value(connection_ref, Config),
+ Ref = proplists:get_value(connection_ref, Config),
Table = proplists:get_value(tableName, Config),
{updated, _} =
odbc:sql_query(Ref, "CREATE TABLE " ++ Table
++ " (ID INTEGER, DATA CHARACTER VARYING(10))"),
{updated, Count} =
- odbc:param_query(Ref, "INSERT INTO " ++ Table ++
+ odbc:param_query(Ref, "INSERT INTO " ++ Table ++
"(ID, DATA) VALUES(?, ?)",
[{sql_integer, [1, 2, 3]},
{{sql_varchar, 10}, ["foo", "bar", "baz"]}]),
-
+
true = odbc_test_lib:check_row_count(3, Count),
{updated, NewCount} =
@@ -1254,31 +1254,31 @@ delete_nonexisting_row(Config) when is_list(Config) ->
param_delete() ->
[{doc,"Test parameterized delete query."}].
param_delete(Config) when is_list(Config) ->
- Ref = proplists:get_value(connection_ref, Config),
+ Ref = proplists:get_value(connection_ref, Config),
Table = proplists:get_value(tableName, Config),
- {updated, _} =
- odbc:sql_query(Ref,
+ {updated, _} =
+ odbc:sql_query(Ref,
"CREATE TABLE " ++ Table ++
" (ID INTEGER, DATA CHARACTER VARYING(10),"
" PRIMARY KEY(ID))"),
- {updated, Count} = odbc:param_query(Ref, "INSERT INTO " ++ Table ++
+ {updated, Count} = odbc:param_query(Ref, "INSERT INTO " ++ Table ++
"(ID, DATA) VALUES(?, ?)",
- [{sql_integer, [1, 2, 3]},
- {{sql_varchar, 10},
+ [{sql_integer, [1, 2, 3]},
+ {{sql_varchar, 10},
["foo", "bar", "baz"]}]),
true = odbc_test_lib:check_row_count(3, Count),
{updated, NewCount} = odbc:param_query(Ref, "DELETE FROM " ++ Table ++
" WHERE ID = ?",
- [{sql_integer, [1, 2]}]),
+ [{sql_integer, [1, 2]}]),
true = odbc_test_lib:check_row_count(2, NewCount),
UpdateResult = ?RDBMS:param_delete(),
- UpdateResult =
+ UpdateResult =
odbc:sql_query(Ref, "SELECT * FROM " ++ Table),
ok.
@@ -1287,19 +1287,19 @@ param_delete(Config) when is_list(Config) ->
param_select() ->
[{doc,"Test parameterized select query."}].
param_select(Config) when is_list(Config) ->
- Ref = proplists:get_value(connection_ref, Config),
+ Ref = proplists:get_value(connection_ref, Config),
Table = proplists:get_value(tableName, Config),
- {updated, _} =
- odbc:sql_query(Ref,
+ {updated, _} =
+ odbc:sql_query(Ref,
"CREATE TABLE " ++ Table ++
" (ID INTEGER, DATA CHARACTER VARYING(10),"
" PRIMARY KEY(ID))"),
- {updated, Count} = odbc:param_query(Ref, "INSERT INTO " ++ Table ++
+ {updated, Count} = odbc:param_query(Ref, "INSERT INTO " ++ Table ++
"(ID, DATA) VALUES(?, ?)",
- [{sql_integer, [1, 2, 3]},
- {{sql_varchar, 10},
+ [{sql_integer, [1, 2, 3]},
+ {{sql_varchar, 10},
["foo", "bar", "foo"]}]),
true = odbc_test_lib:check_row_count(3, Count),
@@ -1308,26 +1308,26 @@ param_select(Config) when is_list(Config) ->
SelectResult = odbc:param_query(Ref, "SELECT * FROM " ++ Table ++
" WHERE DATA = ?",
- [{{sql_varchar, 10}, ["foo"]}]),
+ [{{sql_varchar, 10}, ["foo"]}]),
ok.
%%-------------------------------------------------------------------------
param_select_empty_params() ->
[{doc,"Test parameterized select query with no parameters."}].
param_select_empty_params(Config) when is_list(Config) ->
- Ref = proplists:get_value(connection_ref, Config),
+ Ref = proplists:get_value(connection_ref, Config),
Table = proplists:get_value(tableName, Config),
- {updated, _} =
- odbc:sql_query(Ref,
+ {updated, _} =
+ odbc:sql_query(Ref,
"CREATE TABLE " ++ Table ++
" (ID INTEGER, DATA CHARACTER VARYING(10),"
" PRIMARY KEY(ID))"),
- {updated, Count} = odbc:param_query(Ref, "INSERT INTO " ++ Table ++
+ {updated, Count} = odbc:param_query(Ref, "INSERT INTO " ++ Table ++
"(ID, DATA) VALUES(?, ?)",
- [{sql_integer, [1, 2, 3]},
- {{sql_varchar, 10},
+ [{sql_integer, [1, 2, 3]},
+ {{sql_varchar, 10},
["foo", "bar", "foo"]}]),
true = odbc_test_lib:check_row_count(3, Count),
@@ -1336,67 +1336,67 @@ param_select_empty_params(Config) when is_list(Config) ->
SelectResult = odbc:param_query(Ref, "SELECT * FROM " ++ Table ++
" WHERE DATA = \'foo\'",
- []),
+ []),
ok.
%%-------------------------------------------------------------------------
param_delete_empty_params() ->
[{doc,"Test parameterized delete query with no parameters."}].
param_delete_empty_params(Config) when is_list(Config) ->
- Ref = proplists:get_value(connection_ref, Config),
+ Ref = proplists:get_value(connection_ref, Config),
Table = proplists:get_value(tableName, Config),
- {updated, _} =
- odbc:sql_query(Ref,
+ {updated, _} =
+ odbc:sql_query(Ref,
"CREATE TABLE " ++ Table ++
" (ID INTEGER, DATA CHARACTER VARYING(10),"
" PRIMARY KEY(ID))"),
- {updated, Count} = odbc:param_query(Ref, "INSERT INTO " ++ Table ++
+ {updated, Count} = odbc:param_query(Ref, "INSERT INTO " ++ Table ++
"(ID, DATA) VALUES(?, ?)",
- [{sql_integer, [1, 2, 3]},
- {{sql_varchar, 10},
+ [{sql_integer, [1, 2, 3]},
+ {{sql_varchar, 10},
["foo", "bar", "baz"]}]),
true = odbc_test_lib:check_row_count(3, Count),
{updated, NewCount} = odbc:param_query(Ref, "DELETE FROM " ++ Table ++
" WHERE ID = 1 OR ID = 2",
- []),
+ []),
true = odbc_test_lib:check_row_count(2, NewCount),
UpdateResult = ?RDBMS:param_delete(),
- UpdateResult =
+ UpdateResult =
odbc:sql_query(Ref, "SELECT * FROM " ++ Table),
ok.
%%-------------------------------------------------------------------------
describe_integer() ->
[{doc,"Test describe_table/[2,3] for integer columns."}].
-describe_integer(Config) when is_list(Config) ->
- Ref = proplists:get_value(connection_ref, Config),
+describe_integer(Config) when is_list(Config) ->
+ Ref = proplists:get_value(connection_ref, Config),
Table = proplists:get_value(tableName, Config),
- {updated, _} =
- odbc:sql_query(Ref,
+ {updated, _} =
+ odbc:sql_query(Ref,
"CREATE TABLE " ++ Table ++
" (myint1 SMALLINT, myint2 INT, myint3 INTEGER)"),
Decs = ?RDBMS:describe_integer(),
%% Make sure to test timeout clause
- Decs = odbc:describe_table(Ref, Table, ?TIMEOUT),
+ Decs = odbc:describe_table(Ref, Table, ?TIMEOUT),
ok.
%%-------------------------------------------------------------------------
describe_string() ->
[{doc,"Test describe_table/[2,3] for string columns."}].
describe_string(Config) when is_list(Config) ->
- Ref = proplists:get_value(connection_ref, Config),
+ Ref = proplists:get_value(connection_ref, Config),
Table = proplists:get_value(tableName, Config),
- {updated, _} =
- odbc:sql_query(Ref,
+ {updated, _} =
+ odbc:sql_query(Ref,
"CREATE TABLE " ++ Table ++
" (str1 char(10), str2 character(10), "
"str3 CHAR VARYING(10), str4 "
@@ -1411,11 +1411,11 @@ describe_string(Config) when is_list(Config) ->
describe_floating() ->
[{doc,"Test describe_table/[2,3] for floting columns."}].
describe_floating(Config) when is_list(Config) ->
- Ref = proplists:get_value(connection_ref, Config),
+ Ref = proplists:get_value(connection_ref, Config),
Table = proplists:get_value(tableName, Config),
- {updated, _} =
- odbc:sql_query(Ref,
+ {updated, _} =
+ odbc:sql_query(Ref,
"CREATE TABLE " ++ Table ++
" (f FLOAT(5), r REAL, "
"d DOUBLE PRECISION)"),
@@ -1430,11 +1430,11 @@ describe_dec_num() ->
[{doc,"Test describe_table/[2,3] for decimal and numerical columns"}].
describe_dec_num(Config) when is_list(Config) ->
- Ref = proplists:get_value(connection_ref, Config),
+ Ref = proplists:get_value(connection_ref, Config),
Table = proplists:get_value(tableName, Config),
- {updated, _} =
- odbc:sql_query(Ref,
+ {updated, _} =
+ odbc:sql_query(Ref,
"CREATE TABLE " ++ Table ++
" (mydec DECIMAL(9,3), mynum NUMERIC(9,2))"),
@@ -1448,12 +1448,12 @@ describe_dec_num(Config) when is_list(Config) ->
describe_timestamp() ->
[{doc,"Test describe_table/[2,3] for tinmestap columns"}].
describe_timestamp(Config) when is_list(Config) ->
-
- Ref = proplists:get_value(connection_ref, Config),
+
+ Ref = proplists:get_value(connection_ref, Config),
Table = proplists:get_value(tableName, Config),
-
+
{updated, _} = % Value == 0 || -1 driver dependent!
- odbc:sql_query(Ref, "CREATE TABLE " ++ Table ++
+ odbc:sql_query(Ref, "CREATE TABLE " ++ Table ++
?RDBMS:create_timestamp_table()),
Decs = ?RDBMS:describe_timestamp(),
@@ -1466,7 +1466,7 @@ describe_no_such_table() ->
[{doc,"Test what happens if you try to describe a table that does not exist."}].
describe_no_such_table(Config) when is_list(Config) ->
- Ref = proplists:get_value(connection_ref, Config),
+ Ref = proplists:get_value(connection_ref, Config),
Table = proplists:get_value(tableName, Config),
{error, _ } = odbc:describe_table(Ref, Table),
diff --git a/lib/odbc/test/odbc_test.hrl b/lib/odbc/test/odbc_test.hrl
index 24ae2a4c2937..169f9e935499 100644
--- a/lib/odbc/test/odbc_test.hrl
+++ b/lib/odbc/test/odbc_test.hrl
@@ -18,7 +18,7 @@
%% %CopyrightEnd%
%%
-
+
% Default timetrap timeout (set in init_per_testcase).
% This should be set relatively high (10-15 times the expected
% max testcasetime).
@@ -30,9 +30,9 @@
{unix,linux} ->
case erlang:system_info({wordsize, external}) of
4 ->
- mysql;
+ sqlserver;
_ ->
- postgres
+ sqlserver
end;
{unix, darwin} ->
mysql;
diff --git a/lib/odbc/test/oracle.erl b/lib/odbc/test/oracle.erl
index 589401b8229f..c73b072053b6 100644
--- a/lib/odbc/test/oracle.erl
+++ b/lib/odbc/test/oracle.erl
@@ -61,7 +61,7 @@ selected_absolute_N(_)->
selected_list_rows() ->
{selected,["ID", "DATA"],[["1", "bar"],["2","foo"]]}.
-
+
first_list_rows() ->
{error, driver_does_not_support_function}.
last_list_rows() ->
@@ -94,7 +94,7 @@ create_fixed_char_table(Size) ->
var_char_min() ->
1.
var_char_max() ->
- 2000.
+ 2000.
create_var_char_table(Size) ->
" (FIELD varchar2(" ++ integer_to_list(Size) ++ "))".
@@ -103,14 +103,14 @@ create_var_char_table(Size) ->
text_min() ->
1.
text_max() ->
- 2147483646. % 2147483647. %% 2^31 - 1
+ 2147483646. % 2147483647. %% 2^31 - 1
create_text_table() ->
" (FIELD long)". %Oracle long is variable length char data
%-------------------------------------------------------------------------
create_timestamp_table() ->
- " (FIELD DATETIME)".
+ " (FIELD DATETIME)".
%-------------------------------------------------------------------------
tiny_int_min() ->
@@ -160,7 +160,7 @@ int_max_selected() ->
%-------------------------------------------------------------------------
big_int_min() ->
-99999999999999999999999999999999999999.
-
+
big_int_max() ->
99999999999999999999999999999999999999.
@@ -176,7 +176,7 @@ big_int_max_selected() ->
%-------------------------------------------------------------------------
float_min() ->
1.40129846432481707e-45.
-
+
float_max() ->
3.40282346638528860e+38.
@@ -192,6 +192,17 @@ float_zero_selected() ->
{selected,["FIELD"],[{0.00000e+0}]}.
%-------------------------------------------------------------------------
+
+% Only really works with a subset of the possible precision and scale combinations
+% It should ideally mirror the function map_dec_num_2_c_column
+expected_value(Precision, _Scale, In) when Precision > 15 ->
+ erlang:float_to_list(In);
+
+expected_value(_Precision, _Scale, In) ->
+ In.
+
+%-------------------------------------------------------------------------
+
param_select_small_int() ->
{selected,["FIELD"],[{"1"}, {"2"}]}.
@@ -230,9 +241,9 @@ param_select() ->
describe_integer() ->
{ok,[{"MYINT1",{sql_decimal,38,0}},{"MYINT2",{sql_decimal,38,0}},
{"MYINT3",{sql_decimal,38,0}}]}.
-
+
describe_string() ->
- {ok,[{"STR1",{sql_char,10}},
+ {ok,[{"STR1",{sql_char,10}},
{"STR2",{sql_char,10}},
{"STR3",{sql_varchar,10}},
{"STR4",{sql_varchar,10}}]}.
diff --git a/lib/odbc/test/postgres.erl b/lib/odbc/test/postgres.erl
index e055be954478..e07d6e94fa05 100644
--- a/lib/odbc/test/postgres.erl
+++ b/lib/odbc/test/postgres.erl
@@ -32,14 +32,14 @@ connection_string() ->
"DSN=Postgres;UID=odbctest";
{unix, linux} ->
Size = erlang:system_info({wordsize, external}),
- linux_dist_connection_string(Size)
+ linux_dist_connection_string(Size)
end.
linux_dist_connection_string(4) ->
case linux_dist() of
"ubuntu" ->
- "DSN=PostgresLinuxUbuntu;UID=odbctest";
- _ ->
+ "DSN=PostgresLinuxUbuntu;UID=odbctest";
+ _ ->
"DSN=PostgresLinux;UID=odbctest"
end;
@@ -50,7 +50,7 @@ linux_dist_connection_string(_) ->
_ ->
"DSN=PostgresLinux64;UID=odbctest"
end.
-
+
linux_dist() ->
case file:read_file("/etc/issue") of
{ok, Binary} ->
@@ -59,8 +59,8 @@ linux_dist() ->
{error, _} ->
other
end.
-
-
+
+
%-------------------------------------------------------------------------
insert_result() ->
{selected,["id","data"],[{1,"bar"}]}.
@@ -93,7 +93,7 @@ selected_absolute_N(_)->
selected_list_rows() ->
{selected,["id", "data"],[[1, "bar"],[2,"foo"]]}.
-
+
first_list_rows() ->
{error, driver_does_not_support_function}.
last_list_rows() ->
@@ -117,7 +117,7 @@ multiple_mix()->
fixed_char_min() ->
1.
fixed_char_max() ->
- 2000.
+ 2000.
create_fixed_char_table(Size) ->
" (FIELD char(" ++ integer_to_list(Size) ++ "))".
@@ -126,7 +126,7 @@ create_fixed_char_table(Size) ->
var_char_min() ->
1.
var_char_max() ->
- 2000.
+ 2000.
create_var_char_table(Size) ->
" (FIELD varchar(" ++ integer_to_list(Size) ++ "))".
@@ -135,14 +135,14 @@ create_var_char_table(Size) ->
text_min() ->
1.
text_max() ->
- 2147483646. % 2147483647. %% 2^31 - 1
+ 2147483646. % 2147483647. %% 2^31 - 1
create_text_table() ->
- " (FIELD text)".
+ " (FIELD text)".
%-------------------------------------------------------------------------
create_timestamp_table() ->
- " (FIELD TIMESTAMP)".
+ " (FIELD TIMESTAMP)".
%-------------------------------------------------------------------------
small_int_min() ->
@@ -177,7 +177,7 @@ int_max_selected() ->
%-------------------------------------------------------------------------
big_int_min() ->
-9223372036854775808.
-
+
big_int_max() ->
9223372036854775807.
@@ -205,6 +205,9 @@ bit_false_selected() ->
bit_true_selected() ->
{selected,["field"], [{"1"}]}.
+non_bit_promotes_to() ->
+ error.
+
%-------------------------------------------------------------------------
float_min() ->
5.0e-324.
@@ -241,6 +244,17 @@ real_zero_selected() ->
{selected,["field"],[{0.00000e+0}]}.
%-------------------------------------------------------------------------
+
+% Only really works with a subset of the possible precision and scale combinations
+% It should ideally mirror the function map_dec_num_2_c_column
+expected_value(Precision, _Scale, In) when Precision > 15 ->
+ erlang:float_to_list(In);
+
+expected_value(_Precision, _Scale, In) ->
+ In.
+
+%-------------------------------------------------------------------------
+
param_select_small_int() ->
{selected,["field"],[{1}, {2}]}.
@@ -282,7 +296,7 @@ describe_integer() ->
{"myint3",sql_integer}]}.
describe_string() ->
- {ok,[{"str1",{sql_char,10}},
+ {ok,[{"str1",{sql_char,10}},
{"str2",{sql_char,10}},
{"str3",{sql_varchar,10}},
{"str4",{sql_varchar,10}}]}.
diff --git a/lib/odbc/test/sqlserver.erl b/lib/odbc/test/sqlserver.erl
index faffeaae04cf..95b62a7ab2c6 100644
--- a/lib/odbc/test/sqlserver.erl
+++ b/lib/odbc/test/sqlserver.erl
@@ -27,7 +27,7 @@
%-------------------------------------------------------------------------
connection_string() ->
- "DSN=sql-server;UID=odbctest;PWD=gurka".
+ "DSN=hernan-mssql;UID=hernan;PWD=hernan".
%-------------------------------------------------------------------------
insert_result() ->
@@ -110,7 +110,7 @@ create_fixed_char_table(Size) ->
var_char_min() ->
1.
var_char_max() ->
- 8000.
+ 8000.
create_var_char_table(Size) ->
" (FIELD varchar(" ++ integer_to_list(Size) ++ "))".
@@ -118,14 +118,14 @@ create_var_char_table(Size) ->
text_min() ->
1.
text_max() ->
- 2147483647. %% 2^31 - 1
+ 2147483647. %% 2^31 - 1
create_text_table() ->
" (FIELD text)".
%-------------------------------------------------------------------------
create_timestamp_table() ->
- " (FIELD DATETIME)".
+ " (FIELD DATETIME)".
%-------------------------------------------------------------------------
tiny_int_min() ->
@@ -179,7 +179,7 @@ big_int_max() ->
9223372036854775807. % 2^63-1
create_big_int_table() ->
- " (FIELD bigint)".
+ " (FIELD bigint)".
big_int_min_selected() ->
{selected,["FIELD"],[{integer_to_list(big_int_min())}]}.
@@ -194,13 +194,17 @@ bit_true() ->
1.
create_bit_table() ->
- " (FIELD bit)".
+ " (FIELD bit)".
bit_false_selected() ->
{selected,["FIELD"],[{false}]}.
bit_true_selected() ->
{selected,["FIELD"], [{true}]}.
+
+non_bit_promotes_to() ->
+ bit_true().
+
%-------------------------------------------------------------------------
float_min() ->
-1.79e+308.
@@ -236,6 +240,14 @@ create_real_table() ->
real_zero_selected() ->
{selected,["FIELD"],[{0.00000e+0}]}.
%-------------------------------------------------------------------------
+% Only really works with a subset of the possible precision and scale combinations
+% It should ideally mirror the function map_dec_num_2_c_column
+expected_value(_Precision, _Scale = 0, In) ->
+ round(In);
+
+expected_value(_Precision, _Scale, In) ->
+ In.
+%-------------------------------------------------------------------------
param_select_tiny_int() ->
{selected,["FIELD"],[{1}, {2}]}.
@@ -280,7 +292,7 @@ describe_integer() ->
{"myint3", sql_integer}]}.
describe_string() ->
- {ok,[{"str1",{sql_char,10}},
+ {ok,[{"str1",{sql_char,10}},
{"str2",{sql_char,10}},
{"str3",{sql_varchar,10}},
{"str4",{sql_varchar,10}}]}.