Middleware and method for reading and writing SQLite database
By providing middleware for reading and writing SQLite databases, it automatically analyzes and adapts to changes in table structure, solving the problem of manually modifying code when SQLite database table structure changes, thus simplifying operations and improving development efficiency.
Patent Information
- Application Number
- CN202511631220.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-11-10
- Publication Date
- 2025-12-05
- Estimated Expiration
- 2045-11-10
AI Technical Summary
When the table structure of a traditional SQLite database changes, the read and write code must be modified manually, which leads to a mismatch between the files and the code, increasing development complexity.
This provides a middleware for reading and writing SQLite databases. It enables reading and writing table data through a unified interface, automatically analyzes changes in table structure, establishes a mapping relationship between field data types and processing functions, and adapts to changes in field structure.
It simplifies the operation process, reduces development complexity, improves code flexibility and maintainability, reduces errors and debugging time, improves development efficiency, and supports code sharing and reuse.
Smart Images

Figure CN121071024A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the field of SQLite database, in particular, to a middleware and method for reading and writing SQLite database. BACKGROUND
[0002] Conventionally, when the table structure of SQLite database changes, the reading and writing code corresponding to the database table needs to be manually modified, but this is easy to cause the database file to be unmatched with the reading and writing code, thereby causing the data in the database table to be inaccessible, and increasing the complexity of development. SUMMARY
[0003] The present application aims to provide a middleware and method for reading and writing SQLite database, so as to solve the problem caused by the manual modification of the reading and writing code corresponding to the database table when the table structure of SQLite database changes.
[0004] In a first aspect, the present application provides a middleware for reading and writing SQLite database, comprising a system interface and a user interface. The system interface comprises a pre-initialization interface and a release interface; the pre-initialization interface is used to establish a mapping relationship between the built-in field data type of SQLite database and the field data type processing function; the release interface is used to release the mapping relationship when the system object is destroyed. The user interface comprises an initialization interface, a reading interface and a writing interface; the initialization interface is used to establish a corresponding relationship table between the table name in SQLite database and the corresponding operation object; the reading interface is used to complete data reading based on the mapping relationship and the corresponding relationship table; the writing interface is used to complete data writing based on the mapping relationship and the corresponding relationship table.
[0005] In a preferred embodiment, the user interface further comprises an execution interface; the execution interface is used to execute a custom SQL statement.
[0006] In a preferred embodiment, the execution interface is further used to check the syntax of the SQL statement.
[0007] In a second aspect, the present application provides a method for reading and writing SQLite database, comprising: The pre-initialization interface establishes a mapping relationship between the built-in field data type of SQLite database and the field data type processing function; the mapping relationship is released by the release interface when the system object is destroyed; The initialization interface establishes a corresponding relationship table between the table name in SQLite database and the corresponding operation object; The reading interface completes data reading based on the mapping relationship and the corresponding relationship table; The write interface completes data writing based on the mapping relationship and the correspondence table.
[0008] In a preferred embodiment, the pre-initialization interface establishes a mapping relationship between the built-in field data type of the SQLite database and the field data type processing function, comprising: Step S101: initializing the SQLite database engine driver and saving the SQLite database connection object; Step S102: creating the built-in field data type processing function of the SQLite database; Step S103: establishing a mapping relationship between the built-in field data type of the SQLite database and the field data type processing function in step S102, and saving the mapping relationship.
[0009] In a preferred embodiment, the initialization interface establishes a correspondence table between the table name in the SQLite database and the corresponding operation object, comprising: Step S301: passing the initialization interface parameter to the database link object in the initialization interface to open the SQLite database file to be parsed; the initialization interface parameter is the complete path name of the SQLite database file to be parsed passed by the user; Step S302: checking whether the SQLite database file is successfully opened, if the SQLite database file is successfully opened, executing step S303, otherwise executing step S304; Step S303: after obtaining the names of all tables in the SQLite database, establishing and saving the correspondence table between the table name in the SQLite database and the corresponding operation object, replacing the interface return value code with the opening success identification code, and executing step S305; Step S304: replacing the interface return value code with the opening failure identification code, and executing step S305; Step S305: passing the interface return value code to the user through the interface return value.
[0010] In a preferred embodiment, the read interface completes data reading based on the mapping relationship and the correspondence table, comprising: Step S401: the user passes parameters to the read interface, including the table name to be read and the container variable for saving the table data; Step S402: checking whether the table name exists in the correspondence table, if not, executing step S414, if yes, executing step S403; Step S403: using the correspondence table to obtain the operation object corresponding to the SQLite database table to be read currently; Step S404: through the operation object in step S403, the SQL table structure query statement automatically constructed by the system is executed, the table structure is obtained and saved, including all column names in the table, all columns in the SQLite database corresponding data types and the total number of columns; Step S405: according to the obtained table column name, the SQL query statement is automatically constructed and generated; Step S406: the SQL query statement is passed to the operation object in step S403, and the table data is obtained; Step S407: whether the number of rows of the table data obtained in step S406 is 0 is judged, if yes, step S415 is executed, otherwise, step S408 is executed; Step S408: the relationship between the current data analysis row index and the number of rows of the table data is judged, if the current data analysis row index is greater than or equal to the number of rows of the table data, step S416 is executed, otherwise, step S409 is executed; Step S409: if the current data analysis column index is greater than or equal to the total number of columns obtained in step S404, step S410 is executed, otherwise, step S411 is executed; Step S410: the current data analysis row index is added by one, and step S408 is executed; Step S411: according to the data types corresponding to all columns obtained in step S404, the data type of the current analysis column is obtained, and the corresponding field data type processing function is obtained according to the mapping relationship, then the field data type processing function is executed, and the data value corresponding to the column is obtained; Step S412: the data value in step S411 is saved to the container variable for saving table data in step S401; Step S413: the current data analysis column index is added by one, and step S409 is executed; Step S414: the interface return value code is replaced by the error code that the table name does not exist, and step S417 is executed; Step S415: the interface return value code is replaced by the code that the number of rows of the table data is 0, and step S417 is executed; Step S416: the interface return value code is replaced by the successful analysis code, and step S417 is executed; Step S417: the interface return value code is passed to the user through the interface return value.
[0011] In a preferred embodiment, the write interface completes data writing based on the mapping relationship and the corresponding relationship table, including: Step S501: the user passes the write table name and the database table data container variable to be written; Step S502: judging whether the write-in table name is in the corresponding relation table in step S303, if not, executing step S513, otherwise executing step S503; Step S503: obtaining the operation object corresponding to the SQLite database table to be written in according to the corresponding relation table; Step S504: the system automatically constructs the SQL delete database table data sentence, and delivers the SQL delete database table data sentence to the operation object in step S503 and executes; Step S505: executing the SQL table structure query sentence automatically constructed by the system through the operation object in step S503, saving the query table structure, including the total column number, the data type of the column, and the mapping relation between the column index and the data type and the field data type processing function of the column; Step S506: parsing the data to be written line by line; Step S507: judging whether the current parsing line index is greater than or equal to the total line number of the data to be written, if yes, executing step S514, otherwise executing step S508; Step S508: parsing the data to be written column by column, forming the SQL insert sentence, executing the SQL insert sentence accumulated to the set amount at a time, and completing the data writing; Step S509: judging whether the current parsing column index is greater than the total column number in step S503, if yes, executing step S510, otherwise executing step S512; Step S510: delivering the SQL insert sentence in step S508 to the operation object in step S503 for execution; Step S511: executing step S507 by adding one to the current parsing line index; Step S512: obtaining the data type corresponding to the current column from step S505 according to the current parsing column index, constructing the SQL code of the field data type processing function corresponding to the current column into the SQL insert sentence in step S508, and executing step S509; Step S513: replacing the interface return value code with the error code that the write-in table name does not exist, and executing step S515; Step S514: replacing the interface return value code with the code of successfully writing in the data, and executing step S515; Step S515: delivering the interface return value code to the user through the interface return value.
[0012] In a preferred embodiment, the method for reading and writing the SQLite database further comprises: executing the interface to execute the custom SQL sentence.
[0013] In a preferred embodiment, the execution interface performs a syntax check of the custom SQL statement before executing the custom SQL statement.
[0014] In summary, due to the adoption of the above technical solutions, the beneficial effects of the present application are: 1. Simplified operation: The middleware of the present application realizes the read and write operations on the SQLite database table data through a unified interface, without the need to write SQL statements, greatly simplifying the operation process of the SQLite database and reducing the coding work quality of the developers.
[0015] 2. Adaptability: The middleware can automatically analyze the database table structure and adapt to changes in the table field structure without the need to manually modify the middleware code, improving the flexibility and maintainability of the code.
[0016] 3. Improved efficiency: Using the middleware of the present application can speed up the development process, reduce errors and debugging time caused by manual code modification, and improve the development efficiency.
[0017] 4. Code sharing and reuse: The design of the middleware allows the SQLite database operation code to be shared and reused between different projects, saving the time and effort of the developers and improving the production efficiency.
[0018] 5. Convenience: The existence of the middleware provides developers with traversal, making database operations more simple and intuitive, reducing the learning cost and improving the development efficiency. BRIEF DESCRIPTION OF DRAWINGS
[0019] Figure 1 A schematic diagram of a middleware for reading and writing SQLite databases according to an embodiment of the present application.
[0020] Figure 2 A flowchart of the data reading process of the reading interface according to an embodiment of the present application.
[0021] Figure 3 A flowchart of the data writing process of the writing interface according to an embodiment of the present application. DETAILED DESCRIPTION
[0022] To make the purpose, technical solutions and advantages of the embodiments of the present application clearer, the technical solutions of the embodiments of the present application will be described clearly and completely below with reference to the drawings of the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. The components of the embodiments of the present application described and shown in the drawings herein can be arranged and designed in various different configurations.
[0023] Therefore, the following detailed description of the embodiments of the application provided in the drawings is not intended to limit the scope of the claimed application, but merely represents selected embodiments of the application. Based upon these embodiments of the application, those skilled in the art who have the benefit of the present application can obtain all other embodiments of the application without making an inventive effort.
[0024] Embodiment As shown in the drawings, the embodiment of the application provides a middleware for reading and writing SQLite database, which comprises a system interface and a user interface; Figure 1 The system interface comprises a pre-initialization interface and a release interface; the pre-initialization interface is used to establish a mapping relationship between the built-in field data type of SQLite database and the field data type processing function; the release interface is used to release the mapping relationship when the system object is destroyed; The user interface comprises an initialization interface, a reading interface and a writing interface; the initialization interface is used to establish a corresponding relationship table between the table name in SQLite database and the operation object corresponding thereto; the reading interface is used to complete data reading based on the mapping relationship and the corresponding relationship table; and the writing interface is used to complete data writing based on the mapping relationship and the corresponding relationship table. Thus, the middleware in the application provides a unified interface, and the user can complete reading and writing of the table content of SQLite database by calling the reading interface and the writing interface without writing SQL statements. The middleware can dynamically analyze the table structure of SQLite database and adapt to the change of the table field structure, thereby overcoming the problem of manually modifying code in the prior art and improving the development efficiency.
[0025] Further, the user interface further comprises an execution interface; the execution interface is used to execute a custom SQL statement. Thus, the execution interface for executing the custom statement can be reserved as needed in the application. Preferably, the execution interface is further used to check the syntax of the SQL statement.
[0026] It should be noted that the system interface is called prior to the user interface. The system interface does not need to be called by the user, and the system automatically completes the calling. The pre-initialization interface will be automatically called when the system object is created, and the release interface will be automatically called when the system object is destroyed. The calling of the reading interface, the writing interface and the execution interface is not subject to the sequence, but must be called after the initialization interface.
[0027] The following is a method for reading and writing SQLite database based on the middleware for reading and writing SQLite database, and the working principle of the middleware for reading and writing SQLite database is described in detail.
[0028]
[0029] The method for reading and writing the SQLite database comprises: The pre-initialization interface establishes a mapping relationship between the built-in field data type of the SQLite database and the field data type processing function; and the mapping relationship is released by the releasing interface when the operation object is destroyed; The initialization interface establishes a corresponding relationship table between the table name in the SQLite database and the corresponding operation object; the reading interface completes data reading based on the mapping relationship and the corresponding relationship table; and the writing interface completes data writing based on the mapping relationship and the corresponding relationship table.
[0030] In one implementation scheme, the pre-initialization interface establishes a mapping relationship between the built-in field data type of the SQLite database and the field data type processing function, and comprises: Step S101: initializing the SQLite database engine driver and saving the SQLite database connection object; Step S102: creating the SQLite database built-in field data type processing function; Step S103: establishing a mapping relationship between the SQLite database built-in field data type and the field data type processing function in step S102, and saving the mapping relationship for easy calling; in the embodiment of the application, the SQLite database built-in field data type comprises TEXT (text type), INTEGER (integer type), DOUBLE (double-precision floating point number), BOOLEAN (Boolean type), UINT (unsigned integer type), USHORT (unsigned short integer), SHORT (short integer), etc.
[0031] Therefore, through the pre-initialization interface, when the SQLite database table cell field is parsed, the field data type processing function matched with the cell field data type is called according to the mapping relationship to obtain the data value of the cell, and the data value of the cell is returned to provide a system other interface for calling, so as to realize the parsing of the SQLite database table cell content.
[0032] In one implementation scheme, the releasing interface releases the mapping relationship, and comprises: Step S201: when the operation object is about to be destroyed, the mapping relationship between the SQLite database field data type and the field data type processing function is released; Step S202: closing the SQLite database connection.
[0033] Therefore, through the releasing interface, when the operation object is about to be destroyed, the releasing interface is automatically called to return the memory applied in the pre-initialization interface to the operating system.
[0034] In one implementation, the initialization interface establishes a correspondence table between table names in the SQLite database and operation objects corresponding thereto, including: Step S301: passing initialization interface parameters to a database link object in the initialization interface to open an SQLite database file to be parsed; the initialization interface parameters are full path names of the SQLite database file to be parsed passed by a user; Step S302: checking whether the SQLite database file is successfully opened, if the SQLite database file is successfully opened, executing step S303, otherwise executing step S304; Step S303: after obtaining names of all tables in the SQLite database, establishing and saving a correspondence table between table names in the SQLite database and operation objects corresponding thereto, replacing an interface return value code with an opening success identification code, and executing step S305; Step S304: replacing the interface return value code with an opening failure identification code, and executing step S305; Step S305: passing the interface return value code to the user through an interface return value.
[0035] Thus, all table names in the SQLite database are parsed through the initialization interface, providing a basis for subsequent calling of a reading interface, a writing interface and an execution interface.
[0036] In one implementation, a principle of the reading interface for completing data reading based on the mapping relationship and the correspondence table is as follows: a user passes a table name in the SQLite database and a variable container for saving table data, parses a table structure, and obtains a number of rows and a number of columns of the SQLite database table; a data type of cell data content in the SQLite database table is parsed, corresponding field data type processing functions are obtained and called according to the mapping relationship table in the pre-initialization interface, the cell data is parsed, the parsing result is saved in the variable container, the next cell data is continuously parsed, and the data in the table is parsed until the data is parsed. Figure 2 As shown in the figure, the method specifically includes the following steps: Step S401: passing parameters to the reading interface by the user, including a table name to be read and a container variable for saving table data; Step S402: checking whether the table name exists in the correspondence table of step S303, if not, executing step S414, if yes, executing step S403; Step S403: obtaining an operation object corresponding to the SQLite database table to be read currently by using the correspondence table; Step S404: Through the operation object in step S403, the SQL table structure query statement automatically constructed by the system is executed to obtain and save the table structure, including all column names in the table, all columns in the corresponding data types in the SQLite database, and the total number of columns; Step S405: According to the obtained table column names, an SQL query statement is automatically constructed and generated; Step S406: The SQL query statement is passed to the operation object in step S403 to obtain table data; Step S407: It is judged whether the number of rows of table data obtained in step S406 is 0, if yes, step S415 is executed, otherwise, step S408 is executed; Step S408: It is judged whether the current data parsing row index is greater than or equal to the number of rows of table data, if yes, step S416 is executed, otherwise, step S409 is executed; Step S409: If the current data parsing column index is greater than or equal to the total number of columns obtained in step S404, step S410 is executed, otherwise, step S411 is executed; Step S410: The current data parsing row index is incremented by one, and step S408 is executed; Step S411: According to the data types corresponding to all columns obtained in step S404, the data type of the current parsing column is obtained, and according to the mapping relationship in step S103, the field data type processing function corresponding to the field data type is obtained, and then the field data type processing function is executed to obtain the data value corresponding to the column; Step S412: The data value in step S411 is saved to the container variable for saving table data in step S401; Step S413: The current data parsing column index is incremented by one, and step S409 is executed; Step S414: The interface return value code is replaced with an error code indicating that the table name does not exist, and step S417 is executed; Step S415: The interface return value code is replaced with a code indicating that the number of rows of table data is 0, and step S417 is executed; Step S416: The interface return value code is replaced with a successful parsing code, and step S417 is executed; Step S417: The interface return value code is passed to the user through the interface return value.
[0037] Thus, by calling the read interface to parse data row by row and column by column, the user can obtain all column data in the specified table in the SQLite database.
[0038] In one implementation, the write interface completes data writing based on the mapping relationship and the correspondence table, which includes the following steps: passing in the SQLite database table name, and parsing the SQLite database table structure and the data type of each column; then automatically generating and executing an SQL delete database table data statement; then analyzing the data to be written, and automatically generating an SQL insert statement; finally, executing the SQL insert statement accumulated to a set amount at one time to realize writing data into the SQLite database. Figure 3 As shown in the figure, the method specifically includes the following steps: Step S501: the user passes in the write table name and the database table data container variable to be written; Step S502: it is judged whether the write table name is located in the correspondence table in step S303, if not, step S513 is executed, otherwise, step S503 is executed; Step S503: according to the correspondence table in step S303, the operation object corresponding to the SQLite database table to be written is obtained; Step S504: the system automatically constructs an SQL delete database table data statement, and passes and executes the SQL delete database table data statement to the operation object in step S503; Step S505: through the operation object in step S503, an SQL table structure query statement automatically constructed by the system is executed, and the query table structure is saved, including the total column number, the data type of the column, and the mapping relationship between the column index and the data type and the field data type processing function corresponding to the column; Step S506: the data to be written is parsed line by line; Step S507: it is judged whether the current parsing line index is greater than or equal to the total line number of the data to be written, if yes, step S514 is executed, otherwise, step S508 is executed; Step S508: the data to be written is parsed column by column to form an SQL insert statement, and the SQL insert statement accumulated to a set amount is executed at one time to complete data writing; Step S509: it is judged whether the current parsing column index is greater than the total column number in step S503, if yes, step S510 is executed, otherwise, step S512 is executed; Step S510: the SQL insert statement in step S508 is passed to the operation object in step S503 for execution; Step S511: the current parsing line index is incremented by one, and step S507 is executed; Step S512: according to the current parsing column index, the data type corresponding to the current column is obtained from step S505, the SQL code of the field data type processing function corresponding to the current column is constructed into the SQL insert statement in step S508, and step S509 is executed; Step S513: replace the interface return value code with an error code for the non-existent write table name, and execute step S515; Step S514: replace the interface return value code with a successful data write code, and execute step S515; Step S515: return the interface return value code to the user through the interface return value.
[0039] Thus, by calling the write interface, the data in the table to be written in the SQLite database is first deleted, and then the data is written into the SQLite database row by row and column by column, completing the data writing operation to the SQLite database.
[0040] In one implementation scheme, the method for reading and writing the SQLite database further comprises: executing an interface to execute a custom SQL statement, specifically comprising the following steps: Step S601: the user passes a custom SQL statement; Step S602: pass the custom SQL statement to the execution interface of the operation object of the SQLite database, and save the return code of the execution interface into the interface return value; Step S603: return the interface return value to the user.
[0041] Thus, by calling the execution interface, the user passes the custom SQL statement to the execution interface, executes the custom SQL statement through the operation object of the SQLite database, and returns whether the execution of the custom SQL statement is successful to the user, thereby realizing the execution of the custom SQL statement. In particular, to avoid syntax errors in the execution of the SQL statement, the execution interface performs syntax checking on the custom SQL statement before executing the custom SQL statement, and returns the result of the SQL syntax check to the user, ensuring the smooth execution of the SQL statement.
[0042] The above only describes the preferred embodiments of the present application and is not used to limit the present application. For those skilled in the art, the present application can have various modifications and changes. Any modification, equivalent replacement, improvement, etc. within the spirit and principles of the present application shall be included in the protection scope of the present application.
Claims
1. A middleware for reading and writing SQLite database, characterized by, The system interface comprises a pre-initialization interface and a release interface; the pre-initialization interface is used to establish a mapping relationship between built-in field data types of the SQLite database and field data type processing functions; the release interface is used to release the mapping relationship when the system object is destroyed; The user interface comprises an initialization interface, a reading interface and a writing interface; The initialization interface is used to establish a corresponding relationship table between table names in the SQLite database and corresponding operation objects; the reading interface is used to complete data reading based on the mapping relationship and the corresponding relationship table; and the writing interface is used to complete data writing based on the mapping relationship and the corresponding relationship table. The execution interface is further used to check the syntax of the SQL statement.
2. The middleware for reading and writing SQLite databases of claim 1, wherein, The execution interface is further used to check the syntax of the SQL statement.
3. The middleware for reading and writing SQLite databases of claim 2, wherein, The pre-initialization interface establishes a mapping relationship between built-in field data types of the SQLite database and field data type processing functions; 4. A method of reading and writing SQLite databases, characterized by, The release interface is used to release the mapping relationship when the system object is destroyed; The initialization interface establishes a corresponding relationship table between table names in the SQLite database and corresponding operation objects; The reading interface completes data reading based on the mapping relationship and the corresponding relationship table; The writing interface completes data writing based on the mapping relationship and the corresponding relationship table. The pre-initialization interface establishes a mapping relationship between built-in field data types of the SQLite database and field data type processing functions, comprising: Step S101: initializing a SQLite database engine driver and saving a SQLite database connection object; 5. The method of reading and writing SQLite databases of claim 4, wherein, Step S102: creating built-in field data type processing functions of the SQLite database; Step S103: establishing a mapping relationship between built-in field data types of the SQLite database and the field data type processing functions in step S102 and saving the mapping relationship. The initialization interface establishes a corresponding relationship table between table names in the SQLite database and corresponding operation objects, comprising: Step S301: passing the initialization interface parameters to the database link object in the initialization interface to open the SQLite database file to be parsed; the initialization interface parameters are the complete path name of the SQLite database file to be parsed passed by the user; 6. The method of reading and writing SQLite databases of claim 4, wherein, Step S302: checking whether the SQLite database file is successfully opened; if the SQLite database file is successfully opened, step S303 is executed, otherwise step S304 is executed; Step S303: after obtaining the names of all tables in the SQLite database, a corresponding relationship table between table names in the SQLite database and corresponding operation objects is established and saved, the interface return value code is replaced with an opening success identification code, and step S305 is executed; Step S304: the interface return value code is replaced with an opening failure identification code, and step S305 is executed; Step S305: the interface return value code is passed to the user through the interface return value. The reading interface completes data reading based on the mapping relationship and the corresponding relationship table, comprising: 7. The method of reading and writing SQLite databases of claim 4, wherein, Step S401: the user transmits parameters to the reading interface, including the table name to be read and the container variable for saving table data; Step S402: check whether the table name exists in the correspondence table, if not, execute step S414; if yes, execute step S403; Step S403: use the correspondence table to obtain the operation object corresponding to the SQLite database table to be read currently; Step S404: execute the SQL table structure query statement automatically constructed by the system through the operation object in step S403, obtain and save the table structure, including all column names in the table, the data types of all columns in the SQLite database and the total number of columns; Step S405: automatically construct and generate a SQL query statement according to the obtained table column names; Step S406: transmit the SQL query statement to the operation object in step S403 to obtain table data; Step S407: determine whether the number of rows of the obtained table data in step S406 is 0, if yes, execute step S415, otherwise, execute step S408; Step S408: determine the relationship between the current data parsing row index and the number of rows of the table data, if the current data parsing row index is greater than or equal to the number of rows of the table data, execute step S416, otherwise, execute step S409; Step S409: if the current data parsing column index is greater than or equal to the total number of columns obtained in step S404, execute step S410, otherwise, execute step S411; Step S410: increase the current data parsing row index by one and execute step S408; Step S411: obtain the data type of the current parsing column according to the data types of all columns obtained in step S404, obtain the field data type processing function corresponding to the data type according to the mapping relationship, execute the field data type processing function, and obtain the data value corresponding to the column; Step S412: save the data value in step S411 to the container variable for saving table data in step S401; Step S413: increase the current data parsing column index by one and execute step S409; Step S414: replace the interface return value code with an error code indicating that the table name does not exist, and execute step S417; Step S415: replace the interface return value code with a code indicating that the number of rows of the table data is 0, and execute step S417; Step S416: replace the interface return value code with a successful parsing code, and execute step S417; Step S417: transmit the interface return value code to the user through the interface return value.
8. The method of reading and writing SQLite databases of claim 4, wherein, The writing interface completes data writing based on the mapping relationship and the correspondence table, including: Step S501: the user transmits the writing table name and the database table data container variable to be written; Step S502: determine whether the writing table name is in the correspondence table in step S303, if not, execute step S513, otherwise, execute step S503; Step S503: obtain the operation object corresponding to the SQLite database table to be written currently according to the correspondence table; Step S504: The system automatically constructs a SQL delete database table data statement, and delivers the SQL delete database table data statement to the operation object in step S503 and executes it; Step S505: Through the operation object in step S503, the SQL table structure query statement automatically constructed by the system is executed, and the query table structure is saved, including the total number of columns, the data type of the column, and the mapping relationship between the column index and the data type of the column and the field data type processing function; Step S506: The to-be-written data is parsed line by line; Step S507: Whether the current parsing row index is greater than or equal to the total number of rows of the to-be-written data, if yes, step S514 is executed, otherwise step S508 is executed; Step S508: The to-be-written data is parsed column by column to form a SQL insert statement, and the SQL insert statement accumulated to a set amount is executed at a time to complete data writing; Step S509: Whether the current parsing column index is greater than the total number of columns in step S503, if yes, step S510 is executed, otherwise step S512 is executed; Step S510: The SQL insert statement in step S508 is delivered to the operation object in step S503 for execution; Step S511: The current parsing row index is incremented by one, and step S507 is executed; Step S512: According to the current parsing column index, the data type corresponding to the current column is obtained from step S505, the SQL code of the field data type processing function corresponding to the current column is constructed into the SQL insert statement in step S508, and step S509 is executed; Step S513: The interface return value code is replaced with an error code indicating that the write table name does not exist, and step S515 is executed; Step S514: The interface return value code is replaced with a code indicating successful data writing, and step S515 is executed; Step S515: The interface return value code is transmitted to the user through the interface return value.
9. The method of reading and writing SQLite databases of claim 4, wherein, Further comprising: The execution interface executes a custom SQL statement.
10. The method of reading and writing SQLite databases of claim 9, wherein, Before the execution interface executes the custom SQL statement, a syntax check of the custom SQL statement is completed.
Citation Information
Patent Citations
Data insertion method and apparatus
CN106933828A
Database operation method, device and equipment and storage medium
CN109726217A
Data detection method and device, computer equipment and storage medium
CN111581217A
Data table operation method and device, computer equipment and storage medium
CN118012873A
Updating sqlite database
US20180189371A1