# DBInterface or MySQL.jl problem?

**URL:** <https://discourse.julialang.org/t/dbinterface-or-mysql-jl-problem/97084>\
**Category:** General Usage\
**Tags:** mysql\
**Created:** [April 4, 2023, 8:48pm UTC](https://discourse.julialang.org/t/dbinterface-or-mysql-jl-problem/97084 "2023-04-04T20:48:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ronneesley](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ronneesley/32/11072_2.png) [@Ronneesley](https://discourse.julialang.org/u/Ronneesley)\
**Post date:** [April 4, 2023, 8:48pm UTC](https://discourse.julialang.org/t/dbinterface-or-mysql-jl-problem/97084/1 "2023-04-04T20:48:12Z")

</div>

Hello,

When I execute two queries, the first result becomes random.

Given the database:

```sql
create database test;

use test;

create table person (
	id int auto_increment,
	name varchar(100),
	primary key (id)
);

create table address (
    id int auto_increment primary key,
    person int,
    description varchar(200),
    foreign key (person) references person(id)
);

insert into person(name) values('Roni');
insert into address(person, description) values(1, 'Street 1');

```

Given the code:

```julia
julia> using DBInterface, MySQL

julia> con = DBInterface.connect(MySQL.Connection, "127.0.0.1", "root", 
                            "PASSWORD", db="test", port=3306);

julia> r1 = first(DBInterface.execute(con, 
                            "select * from address where id = 1"))
MySQL.TextRow{true}: (id = 1, person = 1, description = "Street 1")

julia> r1.id
1

julia> r1.person
1

julia> r2 = first(DBInterface.execute(con, 
                            "select * from person where id = 1"))
MySQL.TextRow{true}: (id = 1, name = "Roni")

julia> r2.id
1

julia> r2.name
"Roni"

julia> r1.description
"\0_9\n\x02\0\0\0\0b9\n\x02\0\0\0\0e9..."

```

Note that result `r1.description` is incorrect! The correct answer is: `"Street 1"`, but  
when I do the second query and store the result at `r2`, the first result `r1` turns incorrect.

Why?

**PS: I know I can make a join to get the both result with only one query.**

---

<div class="post-metadata">

**Author:** ![quinnj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/quinnj/32/11_2.png) [@quinnj](https://discourse.julialang.org/u/quinnj)\
**Post date:** [April 4, 2023, 9:51pm UTC](https://discourse.julialang.org/t/dbinterface-or-mysql-jl-problem/97084/2 "2023-04-04T21:51:59Z")

</div>

It looks like the data for the 1st query is no longer valid once you’ve executed the 2nd query; this looks like a bug to me. If you file an issue at the MySQL.jl repo, I can take a look at it. Thanks.

---

<div class="post-metadata">

**Author:** ![Ronneesley](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ronneesley/32/11072_2.png) [@Ronneesley](https://discourse.julialang.org/u/Ronneesley)\
**Post date:** [April 5, 2023, 2:26am UTC](https://discourse.julialang.org/t/dbinterface-or-mysql-jl-problem/97084/3 "2023-04-05T02:26:25Z")

</div>

Thanks @quinnj! I opened the issue at:

> <https://github.com/JuliaDatabases/MySQL.jl/issues/206>
>
> Hello,
> 
> When I execute two queries, the first result becomes random.
> 
> Given …the database:
> 
> \`\`\`sql
> create database test;
> 
> use test;
> 
> create table person (
> id int auto\_increment,
> name varchar(100),
> primary key (id)
> );
> 
> create table address (
> id int auto\_increment primary key,
> person int,
> description varchar(200),
> foreign key (person) references person(id)
> );
> 
> insert into person(name) values('Roni');
> insert into address(person, description) values(1, 'Street 1');
> \`\`\`
> 
> Given the code:
> 
> \`\`\`julia
> julia\> using DBInterface, MySQL
> 
> julia\> con = DBInterface.connect(MySQL.Connection, "127.0.0.1", "root", 
> "PASSWORD", db="test", port=3306);
> 
> julia\> r1 = first(DBInterface.execute(con, 
> "select \* from address where id = 1"))
> MySQL.TextRow{true}: (id = 1, person = 1, description = "Street 1")
> 
> julia\> r1.id
> 1
> 
> julia\> r1.person
> 1
> 
> julia\> r2 = first(DBInterface.execute(con, 
> "select \* from person where id = 1"))
> MySQL.TextRow{true}: (id = 1, name = "Roni")
> 
> julia\> r2.id
> 1
> 
> julia\> r2.name
> "Roni"
> 
> julia\> r1.description
> "\\0\_9\\n\\x02\\0\\0\\0\\0b9\\n\\x02\\0\\0\\0\\0e9..."
> \`\`\`
> 
> Note that result \`r1.description\` is incorrect! The correct answer is: \`"Street 1"\`, but
> when I do the second query and store the result at \`r2\`, the first result \`r1\` turns incorrect.
