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

"Cannot use a Buf as a string" when selecting MySQL TEXT col #110

Closed
Digicrat opened this issue Dec 15, 2017 · 5 comments
Closed

"Cannot use a Buf as a string" when selecting MySQL TEXT col #110

Digicrat opened this issue Dec 15, 2017 · 5 comments
Labels

Comments

@Digicrat
Copy link

Attempting to retrieve the value of a TEXT type column from a MySQL database is throwing an error. I can avoid the error for now by not selecting that column, or by changing it to a different datatype (ie: VARCHAR).

my $sth = $dbh.prepare("SELECT * FROM tests"); # Where one column in tests is of type TEXT
$sth.execute();
my $arrayref = $sth.fetchrow_arrayref(); # Yields the error below

Cannot use a Buf as a string, but you called the Stringy method on it
in block at /usr/share/perl6/site/sources/65FFB78EFA3030486D1C4D339882A410E3C94AD2 (DBDish::StatementHandle) line 121
in method fetchrow at /usr/share/perl6/site/sources/65FFB78EFA3030486D1C4D339882A410E3C94AD2 (DBDish::StatementHandle) line 119
in method fetchrow_arrayref at /usr/share/perl6/site/sources/65FFB78EFA3030486D1C4D339882A410E3C94AD2 (DBDish::StatementHandle) line 166
in sub db_test at ../test.pl6 line 43
in sub MAIN at ../test.pl6 line 19
in block at ../test.pl6 line 23

@jonathanstowe
Copy link
Member

jonathanstowe commented Dec 15, 2017

Hi,
Yes the fetch* methods do indeed attempt to stringify the column data which is always going to be problematic with TEXT or BLOB columns, I think the behaviour should be that it leaves it as-is and makes a warning recommending you to use .row instead, but I'd like to get some other opinion on that before making the change unitlaterally.

In the meantime you probably want to use .row instead, it has the added advantage of returning properly typed data rather than Str for all columns.

@Digicrat
Copy link
Author

That works, thanks.

The example files in the repository (ie: examples/mysql.pl6) should probably be updated to use that syntax instead of fetchrow (or ideally show examples for each of the available methods with documented pros/cons for each).

@Skarsnik
Copy link
Contributor

Skarsnik commented Dec 15, 2017 via email

@salortiz
Copy link
Contributor

salortiz commented Dec 16, 2017 via email

@jonathanstowe
Copy link
Member

I'll try and take a look at fixing the examples and adding a deprecation tomorrow.

rbt added a commit that referenced this issue Jun 1, 2020
rbt added a commit that referenced this issue Jun 9, 2020
rbt added a commit that referenced this issue Jun 9, 2020
rbt added a commit that referenced this issue Jun 9, 2020
Initially discussed in #110. The README indicates they should be removed in June 2022, which is fairly generous.

Legacy tests have been converted to use the newer functions (allrows or row), or removed when functionality was duplicated.
rbt added a commit that referenced this issue Jun 9, 2020
Initially discussed in #110. The README indicates they should be removed in June 2022, which is fairly generous.

Legacy tests have been converted to use the newer functions (allrows or row), or removed when functionality was duplicated.
@rbt rbt closed this as completed Jun 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants