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

TRUNCATE queries #136

Closed
whatyouhide opened this issue Sep 20, 2016 · 2 comments
Closed

TRUNCATE queries #136

whatyouhide opened this issue Sep 20, 2016 · 2 comments

Comments

@whatyouhide
Copy link
Contributor

It seems like this query causes problems:

iex> Mariaex.query(conn, "TRUNCATE TABLE devices")
** (Protocol.UndefinedError) protocol Enumerable not implemented for nil
    (elixir) lib/enum.ex:1: Enumerable.impl_for!/1
    (elixir) lib/enum.ex:116: Enumerable.reduce/3
    (elixir) lib/enum.ex:1636: Enum.reduce/3
             lib/mariaex/query.ex:157: DBConnection.Query.Mariaex.Query.decode/3
             lib/db_connection.ex:799: DBConnection.decode/6
             lib/mariaex.ex:142: Mariaex.query/4

It may have to do with the commands that don't return rows? I didn't try to change those at all, but I will try to look into this myself if I have some time :).

@liveforeverx
Copy link
Member

Thanks!

@JamesLavin
Copy link

JamesLavin commented Nov 2, 2016

Before laying out my similar issue (same error... different cause), I want to thank the Mariaex developers for building Mariaex!

I hit the same error but with a different use case that this solution doesn't fix because I'm trying to create a table (DDL), not truncate one. If I add query to @commands_without_rows, I'll create problems for standard queries.

I ran Ecto.Adapters.SQL.query(XYZ.Repo, ddl) where ddl is a manual create table statement (because our database team wants us to use raw SQL/DDL). My Ecto.Adapters.SQL.query call returns no results because it's a table create, not a real query, so the table gets created but the migration then blows up.

I get the same error ("(Protocol.UndefinedError) protocol Enumerable not implemented for nil") if I try

def up do
    execute "[my DDL]"
end

Other methods in the docs seem intended for use with DDL but apparently expect Ecto migration code, not raw SQL/DDL.

When I try to use Mariaex in a migration without Ecto.Adapters or execute:

    {:ok, p} = Mariaex.start_link(username: "username", password: "pw", database: "db_name")
    Mariaex.query(p, ddl)

it fails with the same error and the table doesn't get created (presumably because it's wrapped in a transaction):

18:22:46.960 [info]  == Running MyPhoenix.Repo.Migrations.CreateEligibilityRequestResponse.up/0 forward
** (Protocol.UndefinedError) protocol Enumerable not implemented for nil
    (elixir) lib/enum.ex:1: Enumerable.impl_for!/1
    (elixir) lib/enum.ex:116: Enumerable.reduce/3
    (elixir) lib/enum.ex:1636: Enum.reduce/3
    (mariaex) lib/mariaex/query.ex:157: DBConnection.Query.Mariaex.Query.decode/3
    (db_connection) lib/db_connection.ex:799: DBConnection.decode/6
    (mariaex) lib/mariaex.ex:142: Mariaex.query/4
    (stdlib) timer.erl:197: :timer.tc/3
    (ecto) lib/ecto/migration/runner.ex:26: Ecto.Migration.Runner.run/6
    (ecto) lib/ecto/migrator.ex:121: Ecto.Migrator.attempt/6
    (ecto) lib/ecto/migrator.ex:70: anonymous fn/4 in Ecto.Migrator.do_up/4
    (ecto) lib/ecto/adapters/sql.ex:508: anonymous fn/3 in Ecto.Adapters.SQL.do_transaction/3
    (db_connection) lib/db_connection.ex:1063: DBConnection.transaction_run/4
    (db_connection) lib/db_connection.ex:987: DBConnection.run_begin/3
    (db_connection) lib/db_connection.ex:667: DBConnection.transaction/3
    (ecto) lib/ecto/migrator.ex:244: anonymous fn/4 in Ecto.Migrator.migrate/4
    (elixir) lib/enum.ex:1184: Enum."-map/2-lists^map/1-0-"/2
    (ecto) lib/mix/tasks/ecto.migrate.ex:84: anonymous fn/4 in Mix.Tasks.Ecto.Migrate.run/2
    (elixir) lib/enum.ex:651: Enum."-each/2-lists^foreach/1-0-"/2
    (elixir) lib/enum.ex:651: Enum.each/2
    (mix) lib/mix/task.ex:296: Mix.Task.run_task/3

Thanks in advance for any thoughts you might have!

--James

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants