Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix the prepared query cannot be modified #14

Merged
merged 2 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ erlang.mk
_build
rebar.lock
*.swp
.DS_Store
2 changes: 1 addition & 1 deletion src/ecql.app.src
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{application, ecql,
[
{description, "Cassandra Native CQL Driver"},
{vsn, "0.7.0"},
{vsn, "0.7.1"},
{modules, []},
{registered, []},
{applications, [
Expand Down
22 changes: 10 additions & 12 deletions src/ecql.erl
Original file line number Diff line number Diff line change
Expand Up @@ -381,18 +381,16 @@ established({call, From}, {prepare, Query}, State = #state{proto_state = ProtoSa
established({call, From}, {prepare, PreparedKey, Query}, State = #state{requests = Reqs,
prepared = Prepared,
proto_state = ProtoSate}) ->
case dict:find(PreparedKey, Prepared) of
{ok, Id} ->
%%TODO: unprepare?
{keep_state, State, [{reply, From, {ok, Id}}]};
error ->
{Frame, ProtoState} = ecql_proto:prepare(Query, ProtoSate),
StreamId = ecql_frame:stream(Frame),
NewState = State#state{proto_state = ProtoState,
prepared = dict:store({pending, StreamId}, PreparedKey, Prepared),
requests = dict:store(StreamId, From, Reqs)},
{keep_state, NewState}
end;
%% Since the [Native protocol](https://cassandra.apache.org/_/native_protocol.html)
%% doesn't support Unprepare opertation, all we need to do here is to send each prepare
%% request to Cassandra and store the PreparedId of each Response without caring if the
%% PreparedKey already exists.
{Frame, ProtoState} = ecql_proto:prepare(Query, ProtoSate),
StreamId = ecql_frame:stream(Frame),
NewState = State#state{proto_state = ProtoState,
prepared = dict:store({pending, StreamId}, PreparedKey, Prepared),
requests = dict:store(StreamId, From, Reqs)},
{keep_state, NewState};

established({call, From}, {execute, ?PREPARED_STMT_ID(Id), Query}, State = #state{proto_state = ProtoSate}) ->
request(From, fun ecql_proto:execute/3, [Id, Query, ProtoSate], State);
Expand Down