Countributions
I made some changes to the code. This is first time that I am using github. Can you anyone tell me procedure to commit code? Or I can send code to the developers and they can merge it?
You forked the lib - this is correct. Next step - modify code and commit & push it. Next go to your fork page on github and press Send pull request button. I'll receive your pull request and accept or deny it. Thanks
@Ninja-007 btw you can discuss improvements here. Please tell me what do you miss in the lib and I'll assist you or improve it. Thanks
Thanks for your reply. It is very nice.
- Usage of cout directly in library is not good. In my application, only application supposed to do cout. The library can use callback function(registered by application during initialisation) for logging. If logging is enabled, then application can log the messages from lib else can ignore it. It is upto application to decide which messages to display.
- Usage of uint8_t, uint16_t, uint32_t and int8_t as datatypes. I have some classes which I cannot change and datatype of classmembers should reflect allowed range. (I added code for this.)
- Replacing std::to_string with std::stringstream usage or better alternative. On some compliers the function is not present. ((I added code for this.) Regards
Oh thanks. Please push your changes to your repo and create a pull request. Points 1 and 3 are very good. But there is a thing about point 2. uint8_t are not language types but typedefs so we'd better add unsigned data types support so uint8_t, uint16_t, uint32_t and int8_t will be supported too.
I just did pull request. Did you receive it?
@Ninja-007 yes I did. Thanks. You did right. Let me inspect it a little bit and then I'll write you back.
New requests. If you have alternative, then add write here.
- Utilty functions
- bool IsDBPresent(const std::string& DBPath) //will verify presence of DB on disk
- bool Storage.IsTablePresent(const std::string& TableName) //will verify presence of table on in given storage intance(returned by make_storage)
- bool UserClass.IsRowPresent(T primarykey) //verifies presence of row in UserClass attached table
- Renaming Storage.replace to insert_with_id to avoid confusion and understand usage from name.
- Renaming Storage.insert to insert_make_id to avoid confusion and understand usage from name.
1.
bool IsDBPresent(const std::string& DBPath)why? What are you going to perform is db exists? What if not?bool Storage.IsTablePresent(const std::string& TableName)same question. I assumesync_schemais enoughbool UserClass.IsRowPresent(T primarykey)why? What use cases do you expect with it?
Storage::replaceis namedreplacecauseSQLitehas queryREPLACE. Details hereStorage::insertdoesn't create id in all cases - it created id if primary key column isint. But if primary key isstd::stringfor example it doesn't. To be exactStorage::insertreturns last insert row id. So I don't think we need to rename these functions.Replaceneeds primary key anyway. So theninsertis the only way to insert without primary key.
@Ninja-007 why do you use unary plus operator before adding object to stream like this:
std::stringstream stream;
stream << +t;
return stream.str();
?
To get numerical values instead ASCII characters https://stackoverflow.com/questions/19562103/uint8-t-cant-be-printed-with-cout
@Ninja-007 wow nice way. I do static_cast in this cases. Ok I leave it.
Thanks, I have to write some default values in table if it is initilized for first time. When table is present, then nothing should be done. This should be done before doing sync_schema. BTW, I wrote IsDBPresent and IsTablePresent, if you ready to integrate then I can push the code.
I checked you recent checkin.
There is code like
// char is neigher signer char nor unsigned char so it has its own specialization
template<>
struct field_printer
You have wrote signed char in function defination. Is that expected?
@Ninja-007 default values can be added with default_value constraint in make_column function. Then call sync_schema and:
- table will be added if it doesn't exist with with
DEFAULTin specified columns - noting will be done if table already exists with the same schema
- table will be altered or recreated if table exists with different schema
About field_printer's char specialization:
yes, I missed argument type in operator(). Thanks
There is no need in IsDBPresent and IsTablePresent - storage is designed to be static
@Ninja-007 what do you mean IsDBPresent? What does it returns? Whether file exists? Or whether all tables exist with a given schema?
I added simple function which checks for existence of file. /*! \fn IsDBPresent \brief verifies presence of database file on disk. \warning the file may not be valid sqlite database. */ static bool IsDBPresent(const std::string& DBPath); { struct stat buffer; return (stat (DBPath.c_str(), &buffer) == 0); }
I am made pull request to fix complier warnings. Warnings in library are not good.
checking file existence can be implemented in file system libraries: boost fs or it's C++17 standard analog. Or one can use libc for this with FILE *file = fopen("path.db"); . Also file system interaction differs on different operating systems and this is not about sqlite at all. Also there can be any other file (image probably) with the same name just accidentally but IsDBPresent returns true and this is not correct cause this file has nothing common with database. sync_schema is a better way to perform file and schema check.
Warnings will be fixed. Thanks
You have very good library. But I donot find some many forks or users of this library. Would you mind to submit this lib to https://github.com/fffaraz/awesome-cpp ?