core.mysql.selectCount

Hi dev,

I suspect there is a bug in this function.

In its most basic form, counting a table without using the where condition, i get the reply " Unknown column ‘id’ in ‘field list’", and all further configuration attempts all end with the same result.

Changing from selectCount to select works fine.

Hi,

Is it possible that the table does not contain a column named ‘id’? If so, then you need to provide a column name to count against. A column ‘id’ is fairly standard, so that is the default. You can change it like so:

Client-side:

core.mysql.selectCount({ db = "products", tbl = "toys", column = "name" }, onResponse)

Server-side:

local cnt, err = core.mysql.selectCount("products", { tbl = "toys", column = "name" })  

You generally want to pick a column what will always have value. Let me know if that works out.

-dev

HI dev, 

Reading the manual for the nth time i noticed that while column is not required it defaults to id.

You may want to change that to required. 

I do not use id but key as primary for all my tables so while id is more common, its not given.

Thanks for the great support as always!

Hi,

Is it possible that the table does not contain a column named ‘id’? If so, then you need to provide a column name to count against. A column ‘id’ is fairly standard, so that is the default. You can change it like so:

Client-side:

core.mysql.selectCount({ db = "products", tbl = "toys", column = "name" }, onResponse)

Server-side:

local cnt, err = core.mysql.selectCount("products", { tbl = "toys", column = "name" })  

You generally want to pick a column what will always have value. Let me know if that works out.

-dev

HI dev, 

Reading the manual for the nth time i noticed that while column is not required it defaults to id.

You may want to change that to required. 

I do not use id but key as primary for all my tables so while id is more common, its not given.

Thanks for the great support as always!