Problem phenomenon:
I used the SQLite database in the project today. I haven't learned it before, so I simply learned about it. I soon encountered the first minor problem. The error is as follows:
problem analysis:
Under the suggestion of the team leader, DBeaver database management and development tools were used (because the icon is a beaver, so I will also call it a beaver database tool);
Since I haven't been in contact with SQLite, and the team leader didn't introduce it much, he sent me a sample.db file. After I opened it with DBeaver, I found some strange garbled characters:
Although it cannot be read normally, there are still some readable information that can be seen. After browsing this garbled document; as a programmer, we must have a very casual habit, that is: press from time to time "ctrl+s", and then a pop-up window reports an error:
From the error message, you can know: This is because DBeaver uses GBK format encoding rules by default, but the file appears garbled when using GBK encoding (that is, characters that cannot be recognized by GBK), so I chose the second Button "Save as UTF-8":
Then I created and configured the SQLite database connection:
When opening the table data, an error was reported:
The database disk image is malformed (database disk image is malformed )
From the error message, you can know:
This is because the database disk image format is incorrect!
Based on the previous operations, we can quickly locate the problem:
It is because the file was saved as UTF-8 encoding rules before that caused an error.
So I started to solve:
Change the file to GBK encoding rules, then re-create and configure the database connection :
Choose Default(GBK) :
The result is still the same error:
The database disk image is malformed (database disk image is malformed )
This is because those garbled codes appeared when you pulled into DBeaver, and you converted to UTF-8 format to save, and now converted to GBK format, it will appear garbled; but please pay attention to a problem: originally pulled into DBeaver Is the encoding rule of the file at the time of GBK?
If you think about it, you will know: No!
Because there are already garbled codes when you pull in DBeaver, and DBeaver defaults to GBK parsing rules , which means that the source file has garbled codes after GBK parsing; and when you press " ctrl+s " before , it has reported an error saying that it does not conform to the GBK format. At this time, we chose to save it in UTF-8 format, because UTF-8 can parse these garbled characters, but after parsing, it is also a strange character that humans cannot recognize but the computer can recognize; therefore, it will lead to not knowing the encoding of the source file. In the case of the format, the file is modified to the UTF-8 format, so it seems that the file under the UTF-8 encoding rule cannot be used to create a database connection.
Solution:
The first: copy a source file again, this is the fastest way, do not do any operation, directly create a database connection in DBeaver using the source file:
The second type: After knowing the encoding rules of the source file, you can try to use the transcoding tool to modify its encoding rules.