Discussion of article "SQL and MQL5: Working with SQLite Database" - page 4

 

Serhii Shevchuk:

I realise you're a hard man to get help from.

How can I help you if you don't tell me how you got to your problem.

Maybe you're running on a mac, or you have a folder with readonly permissions.

I don't know what your filesystem might be.

From the car forum:

xxx: engine crackling after replacing oil caps. Help to understand the causes and what the consequences could be

uuu: there can be many causes, but the consequences can be different.

xxx: Thanks.



I don't know why yet.

When you find out, let me know.

 
I didn't read the whole article, as these libraries are a mess. Although, I took some things for myself as it was the first thing I saw on this subject. Then I realised that I need to read official documentation because you can't learn anything from such an article. In fact, I will say that the information about sqlite3_bind_xxx functions is not correct. The author of the article is misleading. The purpose of these functions is completely different. If the author of the article did not study the topic himself or did not want to just write about it, it would be better not to write. After I read that nonsense about this functionality in the article, I had to think about it all for more than one hour. Exactly. I just started working with DBMS a week ago. I'm getting the hang of it. That's why it was not easy to understand. And when I realised what the sqlite3_bind_xxx functions are for, I was surprised. I didn't expect such a thing from the author of the article. I used to think he was a professional.
 
I have not tested the material attached to the article, but I have a similar error in the pluses. I can't open / create a base on the passed path, it is always created either in the project directory, or on the path specified from the project directory (/new folder/myDB.db)...

Iimported the functions of creating and closing the base and tried to create it. As a result, I have the database created in the downloads.
 
---:

There can be many causes and many consequences.

Thanks, that helped. Problem solved, question removed.

 
I have a very interesting situation) just yesterday everything was created and worked (though from something in the "Downloads" folder) But, overnight the base file stopped being created, but the base itself works as it should for tests tried to create a base placed in memory sqlite3_open(":memory:"") - the base is created, the data is loaded / read.

Perhaps a problem with access rights, what do you think? how to check this in Windows knows who?
 
Andrey Azatskiy:
I have a very interesting situation) just yesterday everything was created and worked (though from something in the "Downloads" folder) But, overnight the base file stopped being created, but the base itself works as it should for tests tried to create a base placed in memory sqlite3_open(":memory:"") - the base is created, the data is loaded / read.

Perhaps a problem with access rights, what do you think? how to check this in Windows knows who?

It's easy to check, actually. Try to put the database in "My Documents" for starters. If it works, then it's not a matter of rights. But in general, it depends on how you did it. I personally spent 2 weeks, until I created everything I needed to work with SQLite3. I had to translate the documentation, because in Russian there is no adequate information on this subject. As in this article there is a lot of rubbish and levak. Above I have attracted one of the moments. Then I stopped and studied the issue myself.

I have such a wrapper for it:

//==================================================================================================================================================================================
// Basic wrapper for sqlite3_open_v2. ==============================================================================================================================================
int SQLite3 :: sqlite3_open(const string& filename, intptr_t& dbHandle, int flags) {
  uchar utf8_filename[];
  stringToUtf8(filename, utf8_filename);
  return sqlite3_open_v2(utf8_filename, dbHandle, flags, 0);
}

Here is the stringToUtf8 function:

//==================================================================================================================================================================================
// Convert a string to a utf-8 byte array. =========================================================================================================================================
void stringToUtf8(const string strToConvert,                     // String to be converted into an array in utf-8 encoding
                  uchar& utf8[],                                 // Array in utf-8 encoding, in which the converted string strToConvert will be placed
                  const bool untilTerminator = true) export {    // Number of characters that will be copied to the utf8 array and converted to utf-8 encoding.
//---
  int count = untilTerminator ? -1 : StringLen(strToConvert);
  StringToCharArray(strToConvert, utf8, 0, count, CP_UTF8);
}

I have it in a separate library.

 
Viktar Dzemikhau:

It's easy to check, actually. Try to put the database in "My Documents" for starters. If it works, then it's not a matter of rights. But in general, it depends on how you did it all. I personally spent 2 weeks, until I created everything I needed to work with SQLite3. I had to translate the documentation, because in Russian there is no adequate information on this subject. As in this article there is a lot of rubbish and levak. Above I have attracted one of the moments. Then I gave up and studied the issue myself.

I have a wrapper for this:

And here is the stringToUtf8 function:

I have it in a separate library.

Yes, I had 2 errors:
1 - encoding (thanks a lot for the function, I didn't know how to translate normally to UTF -8)
2 - permissions.


 
Andrey Azatskiy:

Yes, I had 2 errors:
1 - encoding (thanks a lot for the function, I didn't know how to translate normally to UTF -8)
2 - permissions.


Yes, you're welcome. I remember how much trouble I had with this myself. With such woe-articles. There is one option. You either read the official documentation or you ask. There was no one to ask. I had to study it myself. The point is that if you write in C++, there is someone to ask. But when you write through a gasket and transfer it to µl, there are few people who can help you. It is too hard for Plus users to get into it)))

 

I think I found a memory leak:

In SQLite3Base.mqh line 250

::sqlite3_finalize(stmt); // clean

 Should be:

::sqlite3_finalize(pstmt); // clean
 
Viktar Dzemikhau:

It's easy to check, actually. Try to put the database in "My Documents" for starters. If it works, then it's not a matter of rights. But in general, it depends on how you did it all. I personally spent 2 weeks, until I created everything I needed to work with SQLite3. I had to translate the documentation, because in Russian there is no adequate information on this subject. As in this article there is a lot of rubbish and levak. Above I have attracted one of the moments. Then I gave up and studied the issue myself.

I have a wrapper for this:

And here is the stringToUtf8 function:

I have it in a separate library.

and I use it to convert to utf

int u2a(string txt,uchar &out[]){ return(StringToCharArray(txt,out))};