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

'testtable' is not a function: SQL logic error #1186

Open
raidenluikang opened this issue May 25, 2023 · 1 comment
Open

'testtable' is not a function: SQL logic error #1186

raidenluikang opened this issue May 25, 2023 · 1 comment

Comments

@raidenluikang
Copy link

raidenluikang commented May 25, 2023

Following example success compiled with latest dev sqlite_orm, but on runtime gives 'testtable' is not a function: SQL logic error

#include <cstdint>
#include <string>

#include "sqlite_orm_dev.h"

namespace orm = sqlite_orm;



struct testtable
{
    std::int64_t id = 0;
    std::int64_t value = 0;
};

static inline auto init_storage(const std::string &path){
    
    return orm::make_storage(path,
			orm::make_table("testtable",
                            orm::make_column("id", &testtable::id, /*orm::autoincrement(),*/ orm::primary_key().autoincrement()),
                            orm::make_column("value", &testtable::value)
                        )
    );
}

using storage_t = decltype(init_storage(""));

int main(){

    storage_t storage = init_storage("database.sql");
    storage.sync_schema();
	testtable table;
	table.id = 20;
	table.value = 1;
	storage.replace<testtable>(table);
    auto list = storage.get_all<testtable>(
            //orm::where( //--> Imagine that, I forgotten write there orm::where
                orm::and_(orm::is_equal(&testtable::id, 20),
                           orm::is_equal(&testtable::value, 1)
                                  
                ),
            //),
            orm::limit( 1 ) 
            );
    
    for (auto&& row : list)
    {
		printf("id = %lld value = %lld\n", (long long)row.id, (long long)row.value);
	}
    return 0;
}

OUTPUT:

$ ./main
terminate called after throwing an instance of 'std::system_error'
  what():  'testtable' is not a function: SQL logic error
Aborted (core dumped)

Q: Can be detect this error in compile time ?

@fnc12
Copy link
Owner

fnc12 commented Jun 4, 2023

Hi @raidenluikang . Thanks for submitting this issue. It is a very good suggestion. get_all can't accept everything but argument check logic is forwarded to SQLite engine at run-time. Of course we can update static checks and add static_assert. The easiest way is to add static_assert which checks that get_all arguments list don't contain and product but it is not right cause we better fix it in a different way: to mark some expressions available as get_all arguments (they are called already select constraints inside the code) and allow passing only select constraints inside. It must not break existing working queries but it will break compilation for existing queries which contain run-time error. Is it what you expect?

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

No branches or pull requests

2 participants