Middleware and method for reading and writing SQLite databases

By providing middleware for reading and writing SQLite databases, it automatically creates a table showing the relationship between field data types and table names, solving the problem of manually modifying code when the SQLite database table structure changes. This simplifies operations, enhances adaptability, and improves development efficiency and code sharing.

CN121071024BActive Publication Date: 2026-02-17四川腾盾科技有限公司 +1
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202511631220.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-11-10
Publication Date
2026-02-17
Estimated Expiration
2045-11-10

AI Technical Summary

Technical Problem

When the table structure of a traditional SQLite database changes, the read and write code needs to be modified manually, which leads to a mismatch between the files and the code, increasing development complexity.

Method used

This provides a middleware for reading and writing SQLite databases. It establishes field data type mapping relationships through a pre-initialization interface, establishes a table that maps table names to operation objects through an initialization interface, and automatically completes data reading and writing based on these relationships through the read and write interfaces. The execution interface executes custom SQL statements.

Benefits of technology

It simplifies the SQLite database operation process, adapts to changes in table field structure, reduces development complexity, improves code flexibility and development efficiency, and supports code sharing and reuse.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121071024B_ABST
    Figure CN121071024B_ABST
Patent Text Reader

Abstract

The application relates to the field of SQLite databases, and provides a middleware and a method for reading and writing SQLite databases. The middleware comprises a system interface and a user interface. In the system interface, a pre-initialization interface is used to establish a mapping relationship between built-in field data types of SQLite databases and field data type processing functions; a release interface is used to release the mapping relationship; in the user interface, an initialization interface is used to establish a corresponding relationship table between table names in SQLite databases and corresponding operation objects; a reading interface is used to complete data reading based on the mapping relationship and the corresponding relationship table; and a writing interface is used to complete data writing based on the mapping relationship and the corresponding relationship table. The middleware provides a unified interface to complete reading and writing of table contents of SQLite databases, without the need of writing SQL statements, can overcome the problem of traditional manual code modification, and improves development efficiency.
Need to check novelty before this filing date? Find Prior Art

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 and the reading and writing code to be mismatched, 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 need to manually modify 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.

[0005] 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.

[0006] 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.

[0007] In a preferred embodiment, the user interface further comprises an execution interface; the execution interface is used to execute a custom SQL statement.

[0008] In a preferred embodiment, the execution interface is further used to check the syntax of the SQL statement.

[0009] In a second aspect, the present application provides a method for reading and writing SQLite database, comprising:

[0010] 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 through the release interface when the system object is destroyed.

[0011] The initialization interface establishes a corresponding relationship table between the table name in SQLite database and the corresponding operation object.

[0012] The reading interface completes data reading based on the mapping relationship and the correspondence table;

[0013] The writing interface completes data writing based on the mapping relationship and the correspondence table.

[0014] 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:

[0015] Step S101: initialize the SQLite database engine driver, and save the SQLite database connection object;

[0016] Step S102: create a built-in field data type processing function of the SQLite database;

[0017] Step S103: establish 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 save the mapping relationship.

[0018] 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:

[0019] Step S301: pass the initialization interface parameters to the database link object in the initialization interface, and 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;

[0020] Step S302: check whether the SQLite database file is successfully opened, if the SQLite database file is successfully opened, execute step S303, otherwise execute step S304;

[0021] Step S303: after obtaining the names of all tables in the SQLite database, establish and save the correspondence table between the table name in the SQLite database and the corresponding operation object, replace the interface return value code with the opening success identification code, and execute step S305;

[0022] Step S304: replace the interface return value code with the opening failure identification code, and execute step S305;

[0023] Step S305: pass the interface return value code to the user through the interface return value.

[0024] In a preferred embodiment, the reading interface completes data reading based on the mapping relationship and the correspondence table, comprising:

[0025] Step S401: the user passes parameters to the reading interface, including the table name to be read and the container variable for saving table data;

[0026] Step S402: check if the table name already exists in the corresponding relationship table, if not, execute step S414; if yes, execute step S403;

[0027] Step S403: use the corresponding relationship table to obtain the operation object corresponding to the SQLite database table to be read currently;

[0028] 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, all column data types in the corresponding SQLite database and the total number of columns;

[0029] Step S405: automatically construct and generate a SQL query statement according to the obtained table column names;

[0030] Step S406: pass the SQL query statement to the operation object in step S403 to obtain table data;

[0031] Step S407: determine if the number of rows of table data obtained in step S406 is 0, if yes, execute step S415, otherwise, execute step S408;

[0032] Step S408: determine the relationship between the current data parsing row index and the number of rows of table data, if the current data parsing row index is greater than or equal to the number of rows of table data, execute step S416, otherwise, execute step S409;

[0033] 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;

[0034] Step S410: increase the current data parsing row index by one and execute step S408;

[0035] 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 corresponding field data type processing function according to the mapping relationship, execute the field data type processing function, and obtain the data value corresponding to the column;

[0036] Step S412: save the data value in step S411 to the container variable for saving table data in step S401;

[0037] Step S413: current data parsing column index is added by one, and step S409 is executed;

[0038] Step S414: interface return value code is replaced by error code of nonexistence of table name, and step S417 is executed;

[0039] Step S415: interface return value code is replaced by code of table data row number being 0, and step S417 is executed;

[0040] Step S416: interface return value code is replaced by successful parsing code, and step S417 is executed;

[0041] Step S417: interface return value code is transmitted to user through interface return value.

[0042] In a preferred embodiment, the writing interface completes data writing based on the mapping relationship and the correspondence table, comprising:

[0043] Step S501: the user transmits a writing table name and a database table data container variable to be written;

[0044] Step S502: it is judged whether the writing table name is located in the correspondence table in step S303, if not, step S513 is executed, otherwise, step S503 is executed;

[0045] Step S503: according to the correspondence table, an operation object corresponding to the SQLite database table to be written is obtained;

[0046] Step S504: the system automatically constructs an SQL database table data deletion statement, and transmits the SQL database table data deletion statement to the operation object in step S503 and executes;

[0047] Step S505: the SQL table structure query statement automatically constructed by the system is executed through the operation object in step S503, and the query table structure is saved, comprising total column number, column data type, and mapping relationship between column index and column corresponding data type and field data type processing function;

[0048] Step S506: the data to be written is parsed line by line;

[0049] Step S507: whether the current parsing row index is greater than or equal to the total row number of the data to be written, if yes, step S514 is executed, otherwise, step S508 is executed;

[0050] Step S508: the data to be written is parsed column by column to form an SQL insertion statement, and the SQL insertion statement accumulated to a set amount is executed once to complete data writing;

[0051] Step S509: 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;

[0052] Step S510: the SQL insert statement in step S508 is passed to the operation object execution in step S503;

[0053] Step S511: the current parsing row index is incremented by one, and step S507 is executed;

[0054] 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;

[0055] Step S513: the interface return value code is replaced with an error code indicating that the table name does not exist, and step S515 is executed;

[0056] Step S514: the interface return value code is replaced with a successful data writing code, and step S515 is executed;

[0057] Step S515: the interface return value code is passed to the user through the interface return value.

[0058] In a preferred embodiment, the method for reading and writing SQLite databases further comprises:

[0059] The interface executes the custom SQL statement.

[0060] In a preferred embodiment, the interface executes the custom SQL statement before performing a syntax check on the custom SQL statement.

[0061] In summary, due to the adoption of the above technical solutions, the present application has the following advantages:

[0062] 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.

[0063] 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.

[0064] 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.

[0065] 4. Code sharing and reuse: The design of the middleware allows the SQLite database operation code to be shared and reused across different projects, saving developers time and effort and improving production efficiency.

[0066] 5. Convenience: The presence of the middleware provides developers with a traversal, making database operations simpler and more intuitive, reducing learning costs and improving development efficiency. BRIEF DESCRIPTION OF DRAWINGS

[0067] Figure 1 A schematic diagram of the middleware for reading and writing SQLite databases according to an embodiment of the present application.

[0068] Figure 2 A flowchart of the process of reading data by the reading interface according to an embodiment of the present application.

[0069] Figure 3 A flowchart of the process of writing data by the writing interface according to an embodiment of the present application. DETAILED DESCRIPTION

[0070] To make the objectives, technical solutions, and advantages of the embodiments of the present application clearer, the technical solutions in the embodiments of the present application will be described below in connection with the drawings of the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments of the present application. 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.

[0071] Therefore, the detailed description of the embodiments of the present application provided below in the drawings is not intended to limit the scope of the claimed present application, but only represents selected embodiments of the present application. All other embodiments obtained by those of ordinary skill in the art based on the embodiments in the present application without making creative efforts fall within the scope of protection of the present application.

[0072] EMBODIMENTS

[0073] As shown in the drawings, the embodiments of the present application provide a middleware for reading and writing SQLite databases, including a system interface and a user interface; Figure 1 The system interface includes a pre-initialization interface and a release interface; the pre-initialization interface is used to establish a mapping relationship between the SQLite database built-in field data type and the field data type processing function; the release interface is used to release the mapping relationship when the system object is destroyed;

[0074]

[0075] ​The user interface comprises an initialization interface, a reading interface and a writing interface; the initialization interface is used to establish a corresponding relation table between table names in the SQLite database and operation objects corresponding to the table names; the reading interface is used to complete data reading based on the mapping relation and the corresponding relation table; and the writing interface is used to complete data writing based on the mapping relation and the corresponding relation table.

[0076] Therefore, the middleware in the application provides a unified interface, and the user can complete reading and writing of table contents of the SQLite database by calling the reading interface and the writing interface without writing SQL statements; the middleware can dynamically analyze table structure of the SQLite database and adapt to changes in table field structure, thereby overcoming the problem of manually modifying codes in the prior art and improving development efficiency.

[0077] Further, the user interface further comprises an execution interface; the execution interface is used to execute a custom SQL statement. Therefore, the application can also reserve the execution interface for executing the custom SQL statement according to needs. Preferably, the execution interface is further used to check the syntax of the SQL statement.

[0078] 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 is automatically called when a system object is created, and the release interface is 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 order, but must be called after the initialization interface.

[0079] The following is a method for reading and writing the SQLite database based on the middleware for reading and writing the SQLite database, and the working principle of the middleware for reading and writing the SQLite database is described in detail.

[0080] The method for reading and writing the SQLite database comprises:

[0081] The pre-initialization interface establishes a mapping relation between built-in field data types in the SQLite database and field data type processing functions; and the mapping relation is released by the release interface when an operation object is destroyed;

[0082] The initialization interface establishes a corresponding relation table between table names in the SQLite database and operation objects corresponding to the table names; the reading interface completes data reading based on the mapping relation and the corresponding relation table; and the writing interface completes data writing based on the mapping relation and the corresponding relation table.

[0083] In one implementation scheme, the pre-initialization interface establishes a mapping relation between built-in field data types in the SQLite database and field data type processing functions, comprising:

[0084] Step S101: initializing the SQLite database engine driver, saving the SQLite database connection object;

[0085] Step S102: creating the SQLite database built-in field data type processing function;

[0086] Step S103: establishing the mapping relationship between the SQLite database built-in field data type and the field data type processing function in step S102, saving the mapping relationship for facilitating the calling; in the embodiment of the present application, the SQLite database built-in field data type includes 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.

[0087] Thus, through the pre-initialization interface, when the SQLite database table cell field is parsed, the data value of the cell is obtained by calling the field data type processing function matched with the cell field data type according to the mapping relationship, and the data value of the cell is returned to provide the system other interface calling, so as to realize the parsing of the SQLite database table cell content.

[0088] In one implementation scheme, the mapping relationship is released through the release interface, including:

[0089] 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;

[0090] Step S202: closing the SQLite database connection.

[0091] Thus, through the release interface, when the operation object is about to be destroyed, the release interface is automatically called to return the memory applied in the pre-initialization interface to the operating system.

[0092] In one implementation scheme, the initialization interface establishes the corresponding relationship table between the table name in the SQLite database and the corresponding operation object, including:

[0093] Step S301: passing the initialization interface parameter to the database link object in the initialization interface, opening 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;

[0094] 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;

[0095] Step S303: After obtaining the names of all tables in the SQLite database, a correspondence table between the table names in the SQLite database and the operation objects corresponding thereto is established and saved, the interface return value code is replaced with an opening success identification code, and step S305 is executed.

[0096] Step S304: The interface return value code is replaced with an opening failure identification code, and step S305 is executed.

[0097] Step S305: The interface return value code is transmitted to the user through the interface return value.

[0098] Thus, all table names in the SQLite database are parsed through the initialization interface, thereby providing a basis for subsequent calling of the reading interface, the writing interface and the execution interface.

[0099] In one implementation scheme, the principle of the reading interface for completing data reading based on the mapping relationship and the correspondence table is as follows: the user transmits a table name in the SQLite database and a variable container for saving table data, parses a table structure, obtains a number of rows and a number of columns of the SQLite database table, parses a data type of cell data content in the SQLite database table, obtains and calls a corresponding field data type processing function according to the mapping relationship table in the pre-initialization interface, parses the cell data, saves the parsing result in the variable container, continues to parse next cell data, and stops until the data in the table is parsed. Figure 2 The specific steps include the following steps:

[0100] Step S401: The user transmits parameters to the reading interface, including a table name to be read and a container variable for saving table data.

[0101] Step S402: It is checked whether the table name exists in the correspondence table of step S303, if not, step S414 is executed, and if yes, step S403 is executed.

[0102] Step S403: The operation object corresponding to the SQLite database table to be read is obtained by using the correspondence table.

[0103] Step S404: The SQL table structure query statement automatically constructed by the system is executed through the operation object in step S403, the table structure is obtained and saved, including all column names in the table, all column data types in the SQLite database and the total number of columns.

[0104] Step S405: The SQL query statement is automatically constructed and generated according to the obtained table column name.

[0105] Step S406: pass the SQL query statement to the operation object in step S403 to obtain table data;

[0106] 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;

[0107] 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;

[0108] 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;

[0109] Step S410: increase the current data parsing row index by one, and execute step S408;

[0110] Step S411: obtain the data type of the current parsing column according to the data types corresponding to all columns obtained in step S404, and obtain the field data type processing function corresponding thereto according to the mapping relationship in step S103, then execute the field data type processing function to obtain the data value corresponding to the column;

[0111] Step S412: save the data value in step S411 to the container variable for saving table data in step S401;

[0112] Step S413: increase the current data parsing column index by one, and execute step S409;

[0113] Step S414: replace the interface return value code with an error code indicating that the table name does not exist, and execute step S417;

[0114] 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;

[0115] Step S416: replace the interface return value code with a successful parsing code, and execute step S417;

[0116] Step S417: pass the interface return value code to the user through the interface return value.

[0117] 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.

[0118] In one implementation, the write interface completes data writing based on the mapping relationship and the correspondence table, which includes the following steps: Figure 3

[0119] Step S501: The user passes the write table name and the database table data container variable to be written;

[0120] Step S502: Determine whether the write table name is in the correspondence table in step S303. If not, execute step S513, otherwise execute step S503;

[0121] Step S503: According to the correspondence table in step S303, obtain the operation object corresponding to the SQLite database table to be written;

[0122] Step S504: The system automatically constructs a SQL delete database table data statement and passes it to the operation object in step S503 to execute;

[0123] Step S505: Execute the SQL table structure query statement automatically constructed by the system through the operation object in step S503, save the query table structure, including the total number of columns, 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;

[0124] Step S506: Analyze the data to be written line by line;

[0125] Step S507: Determine whether the current analysis row index is greater than or equal to the total number of rows of the data to be written. If yes, execute step S514, otherwise execute step S508;

[0126] Step S508: Analyze the data to be written column by column to form a SQL insert statement, execute the SQL insert statement accumulated to a certain amount at a time to complete data writing;

[0127] Step S509: Determine whether the current analysis column index is greater than the total number of columns in step S503. If yes, execute step S510, otherwise execute step S512;

[0128] Step S510: Pass the SQL insert statement in step S508 to the operation object in step S503 for execution;

[0129] ​Step S511: the current parsing row index is added by one, and step S507 is executed;

[0130] 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;

[0131] Step S513: the interface return value code is replaced by an error code indicating that the table name does not exist, and step S515 is executed;

[0132] Step S514: the interface return value code is replaced by a successful data writing code, and step S515 is executed;

[0133] Step S515: the interface return value code is transmitted to the user through the interface return value.

[0134] Thus, by calling the writing interface, the data in the table to be written in the SQLite database is deleted first, and then the data is written into the SQLite database row by row and column by column, and the writing operation of the data into the SQLite database is completed.

[0135] In an 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:

[0136] Step S601: the user transmits a custom SQL statement;

[0137] Step S602: the custom SQL statement is transmitted to an execution interface of an operation object of the SQLite database, and a return code of the execution interface is saved into an interface return value;

[0138] Step S603: the interface return value is returned to the user.

[0139] Thus, by calling the execution interface, the user transmits 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 checking to the user, thereby ensuring the smooth execution of the SQL statement.

[0140] The above merely provides 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 modifications, equivalent replacements, improvements, etc. made within the principles and technical scope of the present application shall fall into the 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