Off line data storage and upload scheme

For reprint, please indicate the source: http://blog.csdn.net/itas109  

 

QQ technology exchange group: 129518033

 

Solution download address:

http://download.csdn.net/detail/itas109/9859688

GitHub related projects:

https://github.com/itas109/OfflineDataStorge

 

introduction

 

Nowadays, with the wide spread of network, the development of all walks of life have a great dependence on the network. Instantaneous network disconnection may cause huge losses to some industries, such as banking, finance and other industries with large amount of data. Network disconnection or network transmission failure may cause some immediate key data loss, In order to ensure the reliability of real-time data generation, sending and storage in some industries, especially the security of real-time data uploaded by clients, it is very important to use a secure offline data storage and automatic retransmission mechanism

Off line data storage technology

SQLite is a lightweight database, is to comply with the acid relational database management system, it is contained in a relatively small C library. It’s a public domain project founded by D. Richard HIPP. Its design goal is embedded, and it has been used in many embedded products. It occupies very low resources. In embedded devices, it may only need a few hundred K of memory. It can support Windows/Linux/Unix and other mainstream operating systems, and can be combined with many programming languages, such as TCL, C #, PHP, Java, etc., as well as ODBC interface. It is also faster than MySQL and PostgreSQL, two open source world-famous database management systems.

Unlike the common client server paradigm, the SQLite engine is not an independent process with which a program communicates, but a major part of it by connecting to the program. So the main communication protocol is the direct API call in the programming language. This has a positive effect on total consumption, delay time and overall simplicity. The entire database (definition, table, index and data itself) is stored in a single file on the host.

Cppsqlite encapsulates the API of SQLite once, which makes it more convenient for developers to use SQLite.

Automatic retransmission

The timer is used to check SQLite database on time during programming. If there is any data, it will be sent back and uploaded automatically to avoid the loss of data after transmission failure

Data upload solution

The existing problems: the data type is not unified when uploading, the data is scattered, the corresponding processing information is given for different data, and the data specification is stored when using the database

Solution: the design of the database only needs to give the key fields. The data submitted at one time is packaged into a type and stored as a data field (i.e. JSON data). The data and corresponding methods are stored by JSON. After sending successfully, the data is parsed according to JSON, so that different data can be stored in the other end of the database according to the corresponding type

The design of the database is as follows

Field:

id: INT
Data: TEXT
UpdateTime:DATETIME

 

 

JSON format:

 

{
    "businesses": [
        {
            "logicFunction":"firstFunction",
            "parms": [
                {
                    "parm":"1"
                }
            ]
        },
        {
            "logicFunction":"secondFunction ",
            "parms": [
                             {
                    "parm": "2"
                },
                {
                    "parm": "3"
                }
            ]
        }
    ]
}

 

 

Businesses: business array. The default business order is the storage order of the array

Parms: parameter array

ParM: the specific parameter value must be consistent with the parameter of the function corresponding to logicfunction

Logicfunction: logical function, used to determine which function to execute after data analysis, and its parameter is the value of parms array

For example, in this example, the first function is executed first, and then the second function is executed. If both functions succeed at the same time, it means success. In this way, the problem of business-related data retransmission is solved.

 

 

Think the article is helpful to you, you can scan the QR code to donate to the blogger, thank you!

 

For reprint, please indicate the source: http://blog.csdn.net/itas109  

QQ technology exchange group: 129518033

 

 

 

Read More: