stefanzweifel / screeenly

📸 Screenshot as a Service
https://secure.screeenly.com
MIT License
495 stars 102 forks source link

Create new api_key fails #313

Closed hadogenes closed 4 years ago

hadogenes commented 4 years ago

When I try to add new api_key i get error:

"SQLSTATE[22P02]: Invalid text representation: 7 ERROR: invalid input syntax for integer: "8MARLdT6gVayOaSQ8YI9Bn5nRdSfqljbnD4iVBTUFPjWXDXvGj" (SQL: select * from "api_keys" where "api_keys"."id" = 8MARLdT6gVayOaSQ8YI9Bn5nRdSfqljbnD4iVBTUFPjWXDXvGj limit 1)"

I'm using postgresql

stefanzweifel commented 4 years ago

Hi,

Unfortunately I've never used postgresql in the past and can't really help you with this issue.

As screeenly uses Laravel under the hood I can only point you to the database docs.

I can also point you to the code which executes above query: https://github.com/stefanzweifel/screeenly/blob/2187309ecf80e358de3043875c642e10e5d4c94f/modules/Screeenly/Models/ApiKey.php#L36-L45

And this is the database migration which creates the database table: https://github.com/stefanzweifel/screeenly/blob/2187309ecf80e358de3043875c642e10e5d4c94f/database/migrations/2015_07_08_211146_create_api_keys_table.php#L15-L23


What is really weird is the WHERE clause. That should be api_keys.key and not api_keys.id.

select * 
from "api_keys" 
where "api_keys"."id" = 8MARLdT6gVayOaSQ8YI9Bn5nRdSfqljbnD4iVBTUFPjWXDXvGj
limit 1

This should be the query

select * 
from "api_keys" 
where "api_keys"."key" = 8MARLdT6gVayOaSQ8YI9Bn5nRdSfqljbnD4iVBTUFPjWXDXvGj 
limit 1

I've updated the code a bit in https://github.com/stefanzweifel/screeenly/commit/2187309ecf80e358de3043875c642e10e5d4c94f. Maybe you can update your copy and try it again?

hadogenes commented 4 years ago

Thanks it works now