Driver testing method and system based on GBase8s database
By defining the driver management interface and building test strategies, JPype, pyodbc and ctypes modules are used to test database drivers, which solves the problems of redundant code and low efficiency in traditional methods, and achieves unified and efficient testing of different types of drivers. operate.
Patent Information
- Application Number
- CN202410911289.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-09
- Publication Date
- 2024-10-11
- Estimated Expiration
- 2044-07-09
AI Technical Summary
Traditional methods have redundant code and low efficiency when testing different types of database drivers. Testers need to write the same test cases for each type of driver and need to deal with the integration of SQL statements and programming languages, resulting in low testing efficiency. .
By defining the driver management interface, build testing strategies for JDBC, ODBC and GCI drivers, use JPype, pyodbc and ctypes modules for testing, build target adapter classes to uniformly operate different types of drivers, reduce coupling and improve code reuse sex.
It realizes unified testing of different types of drivers, reduces the coding burden of testers, improves testing efficiency, simplifies test case design, and reduces the coupling between modules.
Smart Images

Figure CN118467397B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of data processing, and in particular to a driver program testing method and system based on a GBase8s database. Background Art
[0002] A database driver is a software component that allows an application to communicate with a database. It implements a specific programming interface so that programmers can operate the database through a standard programming language. Testing the database driver is a critical step in ensuring that the application interacts correctly with the database.
[0003] When testing different drivers for the GBase8s database, the traditional testing method is for the tester to write test cases using the corresponding programming language code according to the type of driver being tested. This will lead to the following problems: There is redundancy between the test cases of different drivers, that is, for each type of driver, the corresponding programming language code must be used to write test cases with the same functions; while writing test cases, the tester must also take into account the integration of SQL statements with the programming language used by the driver being tested to complete the database interaction; when the types and versions of drivers that need to be tested increase, and the functions become more and more complex, the test efficiency is low, the workload of the tester will also increase greatly, and it is difficult to complete the test task within a limited time node. Summary of the invention
[0004] In view of this, an embodiment of the present invention provides a driver testing method and system based on a GBase8s database, which are used to improve the efficiency of driver testing based on a GBase8s database.
[0005] The present invention provides a driver program testing method based on a GBase8s database, comprising: initializing a test environment of the GBase8s database and defining a driver management interface; based on the driver management interface, constructing a test strategy for a JDBC driver program class to obtain a first test strategy; based on the driver management interface, constructing a test strategy for an ODBC driver program class to obtain a second test strategy; based on the driver management interface, constructing a test strategy for a GCI driver program class to obtain a third test strategy; constructing a target adapter class through the first test strategy, the second test strategy and the third test strategy, and mapping a target instance corresponding to the target adapter class as a parameter to the driver management interface; and controlling the driver program test of the GBase8s database through the target adapter class.
[0006] In the present invention, the methods that can be called by the driver management interface include: a driver registration method, a database connection acquisition method, an SQL statement execution method, and a result set processing method.
[0007] In the present invention, the step of constructing a test strategy for the JDBC driver class based on the driver management interface to obtain a first test strategy includes: installing and importing the JPype module in the test environment based on the driver management interface, and constructing a test strategy for the JDBC driver class to obtain a first test strategy, wherein the first test strategy is as follows; obtaining the JVM path through the JPype module, and starting the Java virtual machine through the JVM path; passing the JDBC driver class name through the JPype module, and loading the JDBC driver; extracting database parameters from the GBase8s database to obtain a database parameter set, wherein the database parameter set includes: database type, server address, port and database name; creating a database connection URL through the database parameter set, and creating a first database connection object through the database connection URL; creating a Statement object through the first database connection object, and executing an SQL statement through the Statement object; obtaining a first query result set, and processing the first query result set to obtain a first list data.
[0008] In the present invention, based on the driver management interface, a test strategy is constructed for the ODBC driver class to obtain a second test strategy step, including: based on the driver management interface, the pyodbc module is installed and imported in the test environment, and a test strategy is constructed for the ODBC driver class to obtain a second test strategy, wherein the second test strategy is as follows; based on the pyodbc module, a second database connection object is established through the driver management interface, and a cursor object is extracted from the second database connection object to obtain a cursor object; an SQL statement is executed through the cursor object to obtain a second query result set, and the second query result set is processed to obtain a second list data.
[0009] In the present invention, the step of constructing a test strategy for the GCI driver class based on the driver management interface to obtain a third test strategy includes: installing and importing a ctypes module in the test environment based on the driver management interface, and constructing a test strategy for the GCI driver class to obtain a third test strategy, wherein the third test strategy is as follows; loading the GCI driver in the test environment through the ctypes module, and establishing a connection with the GBase8s database through the GCI driver; executing an SQL statement through the GCI driver to obtain a third query result set, and processing the third query result set to obtain a third list data.
[0010] In the present invention, the step of constructing a target adapter through the first test strategy, the second test strategy and the third test strategy, and mapping the target instance corresponding to the target adapter class as a parameter to the driver management interface includes: defining the adapter class through the first test strategy, the second test strategy and the third test strategy to obtain the target adapter class; creating an adapter instance according to the adapter class to obtain a target instance; mapping the target instance corresponding to the target adapter class as a parameter to the driver management interface.
[0011] In the present invention, the step of defining the adapter class through the first test strategy, the second test strategy and the third test strategy to obtain the target adapter class includes: matching the adapter parameters of the first test strategy to obtain the first adapter parameters; matching the adapter parameters of the second test strategy to obtain the second adapter parameters; matching the adapter parameters of the third test strategy to obtain the third adapter parameters; extracting adaptation parameters of the first adapter parameters, the second adapter parameters and the third adapter parameters to obtain target adaptation parameters; defining the adapter class based on the target adaptation parameters to obtain the target adapter class.
[0012] The present invention also provides a driver testing system based on GBase8s database, comprising:
[0013] Initialization module, used to initialize the test environment of GBase8s database and define the driver management interface;
[0014] A first construction module is used to construct a test strategy for the JDBC driver class based on the driver management interface to obtain a first test strategy;
[0015] A second construction module is used to construct a test strategy for the ODBC driver class based on the driver management interface to obtain a second test strategy;
[0016] A third construction module is used to construct a test strategy for the GCI driver class based on the driver management interface to obtain a third test strategy;
[0017] A mapping module, used to construct a target adapter class through the first test strategy, the second test strategy and the third test strategy, and map a target instance corresponding to the target adapter class as a parameter to the driver management interface;
[0018] The control module is used to control the driver test of the GBase8s database through the target adapter.
[0019] In the technical solution provided by the present invention, objects of different types of driver classes are placed in a unified adapter class, and the adapted objects are indirectly called by accessing the methods in the adapter class, thereby achieving the purpose of operating different types of drivers. This not only improves the reusability and maintainability of the code, but also reduces the coupling between modules. The purpose of testing different types of drivers can be achieved by using one test case file; the coding ability requirements of testers are reduced, and testers do not need to learn one or more programming languages specifically to write test cases, nor do they need to use special programming language codes to write test cases for different types of drivers, so that testers can devote their test points to the functions of the database driver; the calling methods of different types of drivers are uniformly processed and encapsulated into a new interface, which facilitates the calling of testers and simplifies the design of test cases, greatly improving the test efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] In order to more clearly illustrate the specific implementation methods of the present invention or the technical solutions in the prior art, the drawings required for use in the specific implementation methods or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some implementation methods of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0021] Figure 1 The present invention is a flowchart of a driver testing method based on the GBase8s database in an embodiment of the present invention.
[0022] Figure 2 The figure is a schematic diagram of a driver program testing system based on GBase8s database in an embodiment of the present invention.
[0023] Reference numerals:
[0024] 201, initialization module; 202, first construction module; 203, second construction module; 204, third construction module; 205, mapping module; 206, control module. DETAILED DESCRIPTION
[0025] The technical solution of the present invention will be described clearly and completely below in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0026] In the description of the present invention, the terms “first”, “second” and “third” are used for descriptive purposes only and should not be understood as indicating or implying relative importance.
[0027] In addition, the technical features involved in the different embodiments of the present invention described below can be combined with each other as long as they do not conflict with each other.
[0028] For ease of understanding, the specific process of the embodiment of the present invention is described below. Figure 1 , Figure 1 8 is a flowchart of a driver testing method based on a GBase8s database according to an embodiment of the present invention. Figure 1 As shown, the following steps are included:
[0029] S101, initialize the test environment of GBase8s database and define the driver management interface;
[0030] The methods that can be called by the driver management interface include: a driver registration method, a database connection acquisition method, an SQL statement execution method, and a result set processing method.
[0031] First, define a general driver management interface DriverManager. This interface will serve as the interface expected by the client. It contains the methods that the client needs to call, including: registerDriver() for registering the driver, getConnection() for obtaining the database connection, execute() for executing SQL statements, and handleRes() for processing the result set.
[0032] S102: Based on the driver management interface, construct a test strategy for the JDBC driver class to obtain a first test strategy;
[0033] Specifically, based on the driver management interface, the JPype module is installed and imported in the test environment, and a test strategy is constructed for the JDBC driver class to obtain a first test strategy, wherein the first test strategy is as follows; the JVM path is obtained through the JPype module, and the Java virtual machine is started through the JVM path; the JDBC driver class name is passed in through the JPype module, and the JDBC driver is loaded; database parameters are extracted for the GBase8s database to obtain a database parameter set, wherein the database parameter set includes: database type, server address, port and database name; a database connection URL is created through the database parameter set, and a first database connection object is created through the database connection URL; a Statement object is created through the first database connection object, and an SQL statement is executed through the Statement object; a first query result set is obtained, and the first query result set is processed to obtain a first list data.
[0034] First, you need to install and import the jpype module. The feature of this module is that it can execute Java programs in the Python environment. Then use the getDefaultJVMPath() method of jpype to obtain the absolute path of jvm.dll in the current environment, and then pass the absolute path of the prepared jar package file to the addClassPath() method of jpype. This method will load this jar package into the current CLASSPATH. After loading, call the startJVM() method of jpype to start the Java virtual machine. When the Java virtual machine is successfully started, you can use the JClass() method of jpype to pass in the specified JDBC driver class name (for example: "com.gbasedbt.jdbc.Driver") to load the JDBC driver of the GBase8s database.
[0035] Before officially connecting to the GBase8s database, you also need to set the corresponding database connection URL in advance. This URL is a string that conforms to a specific format. It contains the type of database to be connected, the address of the database server, the port number that the database service listens on, the name of the database to be connected, and additional parameter information used to specify some other connection properties. For example, for a GBase8s database, the connection URL string usually follows the following format:
[0036] jdbc:gbasedbt-sqli: / / hostname:port / dbname:parameter1=value1;parameter2=value2.
[0037] After configuring the database connection URL, you need to pass it together with the user credentials for connecting to the database (user name and password for connecting to the database) to the jpype.java.sql.DriverManager.getConnection() method to create a database connection object conn, and then create a Statement object by calling the createStatement() method of this connection object conn, or create a prepareStatement object by calling the prepareStatement() method. Finally, use the execute() method of the Statement object or prepareStatement object to execute the SQL statement passed from the client, and use the getResultSet() method to obtain the query result set. After querying the result set, close the query result set, Statement object or prepareStatement object, and database connection object conn in turn. This is to ensure that database-related resources are released and prevent memory leaks and other potential problems. In summary, this method achieves the purpose of testing the JDBC driver.
[0038] S103, based on the driver management interface, construct a test strategy for the ODBC driver class to obtain a second test strategy;
[0039] Specifically, based on the driver management interface, the pyodbc module is installed and imported in the test environment, and a test strategy is constructed for the ODBC driver class to obtain a second test strategy, wherein the second test strategy is as follows; based on the pyodbc module, a second database connection object is established through the driver management interface, and a cursor object is extracted from the second database connection object to obtain a cursor object; an SQL statement is executed through the cursor object to obtain a second query result set, and the second query result set is processed to obtain a second list data.
[0040] First, you need to install and import the pyodbc module. The feature of this module is that it can connect and operate the database through ODBC in Python. Before officially connecting to the GBase8s database, you need to modify the / etc / odbc.ini configuration file and add the GBase 8s database connection information. The specific content includes the following three parts:
[0041] [ODBC Data Sources]: This section specifies the ODBC data source name DSN and driver description to be used. Each data source has a unique name for reference in the application;
[0042] [Driver]: This section provides detailed information about a specific driver, such as the driver's name, version number, etc.
[0043] [DSN]: This section defines the configuration information of the data source name, including the path of the ODBC driver Driver, the driver description Description, the database name Database, the user name LogonID, the password pwd, the instance name Servername, and the required environment variable information.
[0044] After all the above information is modified, use the isql command to check the ODBC configuration. After successfully completing the ODBC-related configuration, you can create a database connection object conn by passing in the set data source name through the connect() method of pyodbc. Then call the cursor() method of this database connection object conn to create a cursor object mycursor. The function of this cursor object is to process the result set row by row, which is very useful when processing a large amount of data because it can prevent all data from being loaded into the memory at one time, thereby reducing memory consumption. Finally, the SQL statement passed from the client is executed by using the execute() method of this cursor object, and the modified data is submitted to the database using the conn.commit() method, and the query result set is obtained using the mycursor.fetchall() method. After querying the result set, the cursor object and the database connection object conn should be closed in turn. This is done to release system resources in time and prevent resource leakage and other potential problems. In summary, this method achieves the purpose of testing the ODBC driver.
[0045] S104, constructing a test strategy for the GCI driver class based on the driver management interface to obtain a third test strategy;
[0046] Specifically, based on the driver management interface, the ctypes module is installed and imported in the test environment, and a test strategy is constructed for the GCI driver class to obtain a third test strategy, wherein the third test strategy is as follows; the GCI driver in the test environment is loaded through the ctypes module, and a connection is established with the GBase8s database through the GCI driver; an SQL statement is executed through the GCI driver to obtain a third query result set, and the third query result set is processed to obtain a third list data.
[0047] Different from the above two drivers, the GCI driver provides a set of interface subroutines (functions) for accessing the GBase8s database, which can be called in C language to operate the GBase8s database. In order to combine Python with C language, the Python built-in module ctypes is used here. The feature of this module is that it can directly call binary dynamic link libraries in the Python environment.
[0048] First, you need to write a header file named logon.h, in which you declare the two custom functions getConnection(char*, char*, char*); and execute(char*);. Then write a file named logon.c, which contains the specific implementation of these two functions:
[0049] getConnection(char*, char*, char*) function: The main function of this function is to create a database connection. It receives three parameters, namely database name, user name, and password.
[0050] In this function, first use the thread and object mode of the GCIEnvCreate() function to create and initialize the GCI environment handle envhp, then use the GCIHandleAlloc() function to allocate the server handle srvhp and the error handle errhp, then use the GCIServerAttach() function to create the server context handle svchp and associate it with the database name to be connected (the first input parameter), then use the GCIHandleAlloc() function to allocate the server context handle svchp, and use the GCIAttrSet() function to set the server context The server handle srvhp property of the handle svchp is used to allocate the user session handle usrhp using the GCIHandleAlloc() function, and then the GCIAttrSet() function is used to set the user name and password (the second and third input parameters) properties for the user session handle usrhp. Finally, the GCISessionBegin() function is used to establish a user session, and the GCIAttrSet() function is used to set the user session properties in the server context environment. At the same time, the GCIHandleAlloc() function is also needed to allocate the statement handle stmthp to prepare for the subsequent execution of SQL statements.
[0051] execute(char*) function: The main function of this function is to execute SQL statements. It only receives one parameter, which is the SQL string to be executed.
[0052] In this function, first use the GCIStmtPrepare() function to prepare the SQL statement to be executed, then use the GCIAttrGet() function to obtain the number of projection columns in the result set. If the number of projection columns is 0, then use the GCIStmtExecute() function to execute the specific SQL statement directly. Otherwise, if the number of projection columns is greater than 0, use the GCIParamGet() function to obtain the parameter information in the statement handle, use the GCIAttrGet() function to obtain the column name and column data size attributes, and then use the GCIDefineByPos() function to specify the storage space for each column in the query return result set by position, and finally use the GCIStmtExecute() function to execute the specific SQL statement, and use the GCIStmtFetch() function to obtain the query result set. After querying the result set, use the GCISessionEnd() function to end the current session, then use the GCIServerDetach() function to disconnect, and use the GCIHandleFree() function to release the five handles usrhp, srvhp, svchp, errhp, and envhp in turn. The purpose of doing this is to avoid memory leaks while ensuring data consistency.
[0053] Secondly, you need to write a CMakeLists.txt file, which is used to generate a build system and perform compilation more efficiently. In this file, the cmake_minimum_required() command is used to specify that the minimum version of CMake required by the project is 2.6, the project() command is used to define the name of the project, the include_directories() function is used to specify the directory where the GCI-related header files are located, the link_directories() function is used to specify the directory where the GCI-related library files are located, and the add_library() command is used to compile the logon.h and logon.c files into a dynamic link library named liblogon.so. The target_link_libraries() function is used to link the target named logon to the clntsh dynamic link library in the GCI driver on which it depends. After completing the above process in sequence, you can use the cmake command to build in the same directory as the CMakeLists.txt file, and execute the make command to compile.
[0054] Finally, you can use the ctypes.cdll.LoadLibrary() method to load the dynamic link library named liblogon.so generated in the previous step, and assign it to the variable mylib. Finally, mylib is used to call the getConnection() function and execute() function in the liblogon.so file to interact with the GBase8s database. In summary, this method achieves the purpose of testing the GCI driver.
[0055] S105, constructing a target adapter class through the first test strategy, the second test strategy and the third test strategy, and mapping a target instance corresponding to the target adapter class as a parameter to the driver management interface;
[0056] Specifically, the adapter class is defined through the first test strategy, the second test strategy and the third test strategy to obtain a target adapter class; an adapter instance is created according to the adapter class to obtain a target instance; and the target instance corresponding to the target adapter class is mapped as a parameter to the driver management interface.
[0057] Among them, the adapter class is defined by the first test strategy, the second test strategy and the third test strategy to obtain the target adapter class step, including: matching the adapter parameters of the first test strategy to obtain the first adapter parameters; matching the adapter parameters of the second test strategy to obtain the second adapter parameters; matching the adapter parameters of the third test strategy to obtain the third adapter parameters; extracting adaptation parameters of the first adapter parameters, the second adapter parameters and the third adapter parameters to obtain target adaptation parameters; defining the adapter class based on the target adaptation parameters to obtain the target adapter class.
[0058] S106. Control the driver test of the GBase8s database through the target adapter class.
[0059] It should be noted that, through a detailed analysis of the specific implementation methods of different types of drivers, it can be found that a basic process of using a driver to operate a database is: first load the registered driver under test, then create a database connection object, and then create a statement object to execute the SQL statement passed from the client, and finally process the results (for query operations, it is necessary to process the returned result set and extract the required data) and release resources.
[0060] Therefore, an adapter class DriverAdapter is created here, which adapts the implementation methods of different types of drivers into a unified driver management interface DriverManager, processes the implementation method of the corresponding type of driver through the tested driver type passed by the user, and returns the corresponding execution result.
[0061] In this adapter class, an instance of a specific driver class driverobj is included as the constructor parameter, and it is assigned to the driver attribute of the object. When a new instance of the adapter class DriverAdapter is created, this constructor is automatically called to complete the initialization of the object. In addition, it also includes the call of abstract methods in the driver management interface DriverManager. The specific calling method is as follows: use self.driver.registerDriver(driver_type) to call the registration driver method of the specified driver to load the driver; use self.driver.getConnection(driver_type) to call the database connection acquisition method of the specified driver to create a database connection object so that the driver can connect to the database normally; use self.driver.execute(driver_type) to call the SQL statement execution method of the specified driver to execute a specific SQL statement; use self.driver.handleRes(driver_type) to call the result set processing method of the specified driver to extract the required data.
[0062] When operating the corresponding driver, the client uses the unified adapter class DriverAdapter to operate objects of different types of driver classes. In other words, the client only needs to deal with the driver management interface DriverManager without worrying about the specific internal implementation details. This way of decoupling the client from the adapter class also makes it easier to expand other new types of drivers later.
[0063] By executing the above steps, objects of different types of driver classes are placed in a unified adapter class, and the adapted objects are indirectly called by accessing the methods in the adapter class, thereby achieving the purpose of operating different types of drivers. This not only improves the reusability and maintainability of the code, but also reduces the coupling between modules. The purpose of testing different types of drivers can be achieved by using one test case file; the coding ability requirements of testers are reduced, and testers do not need to learn one or more programming languages specifically to write test cases, nor do they need to use special programming language codes to write test cases for different types of drivers, so that testers can devote their test points to the functions of the database driver; the calling methods of different types of drivers are uniformly processed and encapsulated into a new interface, which facilitates the tester's calling while simplifying the design of test cases, greatly improving the test efficiency.
[0064] The embodiment of the present invention also provides a driver testing system based on GBase8s database, such as Figure 2 As shown, specifically including:
[0065] Initialization module 201 is used to initialize the test environment of the GBase8s database and define the driver management interface;
[0066] A first construction module 202 is used to construct a test strategy for the JDBC driver class based on the driver management interface to obtain a first test strategy;
[0067] The second construction module 203 is used to construct a test strategy for the ODBC driver class based on the driver management interface to obtain a second test strategy;
[0068] A third construction module 204 is used to construct a test strategy for the GCI driver class based on the driver management interface to obtain a third test strategy;
[0069] A mapping module 205, configured to construct a target adapter class through the first test strategy, the second test strategy and the third test strategy, and map a target instance corresponding to the target adapter class as a parameter to the driver management interface;
[0070] The control module 206 is used to control the driver test of the GBase8s database through the target adapter.
[0071] Through the collaborative work of the above modules, objects of different types of driver classes are placed in a unified adapter class, and the adapted objects are indirectly called by accessing the methods in the adapter class, thereby achieving the purpose of operating different types of drivers. This not only improves the reusability and maintainability of the code, but also reduces the coupling between modules. Using one test case file can achieve the purpose of testing different types of drivers; the coding ability requirements of testers are reduced. Testers do not need to learn one or more programming languages specifically to write test cases, nor do they need to use special programming language codes to write test cases for different types of drivers, so that testers can devote their test points to the functions of the database driver; the calling methods of different types of drivers are uniformly processed and encapsulated into a new interface, which facilitates the tester's calling while simplifying the design of test cases, greatly improving the test efficiency.
[0072] The above embodiments are only used to illustrate the technical solutions of the present invention rather than to limit the same. Although the present invention has been described in detail with reference to the embodiments, a person skilled in the art should understand that the specific implementation modes of the present invention can still be modified or replaced by equivalents, and any modification or equivalent replacement that does not depart from the spirit and scope of the present invention should be included in the scope of the claims of the present invention.
Claims
1. A driver testing method based on GBase8s database, characterized in that: include: Initialize the test environment of the GBase8s database and define a driver management interface; The driver management interface DriverManager contains methods that the client needs to call, including: registerDriver() for registering the driver, getConnection() for obtaining a database connection, execute() for executing SQL statements, and handleRes() for processing result sets. Based on the driver management interface, a test strategy is constructed for the JDBC driver class to obtain a first test strategy; Based on the driver management interface, a test strategy is constructed for the ODBC driver class to obtain a second test strategy; Based on the driver management interface, construct a test strategy for the GCI driver class to obtain a third test strategy; Constructing a target adapter class by using the first test strategy, the second test strategy and the third test strategy, and mapping a target instance corresponding to the target adapter class as a parameter to the driver management interface; The step of constructing a target adapter by using the first test strategy, the second test strategy and the third test strategy, and mapping the target instance corresponding to the target adapter class as a parameter to the driver management interface includes: Define the adapter class by using the first test strategy, the second test strategy and the third test strategy to obtain a target adapter class; Create an adapter instance according to the adapter class and obtain a target instance; Mapping the target instance corresponding to the target adapter class as a parameter to the driver management interface; The step of defining the adapter class by using the first test strategy, the second test strategy, and the third test strategy to obtain the target adapter class includes: Performing adapter parameter matching on the first test strategy to obtain first adapter parameters; Performing adapter parameter matching on the second test strategy to obtain second adapter parameters; Performing adapter parameter matching on the third test strategy to obtain third adapter parameters; Extracting adaptation parameters from the first adapter parameter, the second adapter parameter, and the third adapter parameter to obtain target adaptation parameters; Defining an adapter class based on the target adaptation parameter to obtain the target adapter class; Control the driver test of the GBase8s database through the target adapter class; The adapter class DriverAdapter adapts the implementation methods of different types of drivers into a unified driver management interface DriverManager, processes the implementation method of the corresponding type of driver through the tested driver type passed by the user, and returns the corresponding execution result; The adapter class contains an instance of a specific driver class, driverobj, as a constructor parameter, and assigns it to the driver attribute of the object. When a new instance of the adapter class DriverAdapter is created, the constructor is automatically called to complete the initialization of the object. It also contains the call of the abstract method in the driver management interface DriverManager. The specific calling method is as follows: use self.driver.registerDriver(driver_type) to call the registration driver method of the specified driver to load the driver; use self.driver.getConnection(driver_type) to call the database connection acquisition method of the specified driver to create a database connection object so that the driver can connect to the database normally; use self.driver.execute(driver_type) to call the SQL statement execution method of the specified driver to execute a specific SQL statement; use self.driver.handleRes(driver_type) to call the result set processing method of the specified driver to extract the required data; When operating the corresponding driver, use the unified adapter class DriverAdapter to operate objects of different types of driver classes; Put objects of different types of driver classes into a unified adapter class, and indirectly call the adapted objects by accessing methods in the adapter class.
2. The driver testing method based on GBase8s database according to claim 1, characterized in that: The methods that can be called by the driver management interface include: a driver registration method, a database connection acquisition method, an SQL statement execution method, and a result set processing method.
3. The driver testing method based on GBase8s database according to claim 1, characterized in that: The step of constructing a test strategy for the JDBC driver class based on the driver management interface to obtain a first test strategy step includes: Based on the driver management interface, the JPype module is installed and imported in the test environment, and a test strategy is constructed for the JDBC driver class to obtain a first test strategy, wherein the first test strategy is as follows; Obtaining the JVM path through the JPype module, and starting the Java virtual machine through the JVM path; Pass the JDBC driver class name through the JPype module and load the JDBC driver; Extracting database parameters from the GBase8s database to obtain a database parameter set, wherein the database parameter set includes: database type, server address, port, and database name; Create a database connection URL through the database parameter set, and create a first database connection object through the database connection URL; Creating a Statement object through the first database connection object, and executing a SQL statement through the Statement object; A first query result set is obtained, and the first query result set is processed to obtain first list data.
4. The driver testing method based on GBase8s database according to claim 3 is characterized in that: The step of constructing a test strategy for the ODBC driver class based on the driver management interface to obtain a second test strategy comprises: Based on the driver management interface, the pyodbc module is installed and imported in the test environment, and a test strategy is constructed for the ODBC driver class to obtain a second test strategy, wherein the second test strategy is as follows; Based on the pyodbc module, a second database connection object is established through the driver management interface, and a cursor object is extracted from the second database connection object to obtain a cursor object; The SQL statement is executed through the cursor object to obtain a second query result set, and the second query result set is processed to obtain second list data.
5. The driver testing method based on GBase8s database according to claim 4 is characterized in that: The step of constructing a test strategy for the GCI driver class based on the driver management interface to obtain a third test strategy comprises: Based on the driver management interface, the ctypes module is installed and imported in the test environment, and a test strategy is constructed for the GCI driver class to obtain a third test strategy, wherein the third test strategy is as follows; Loading the GCI driver in the test environment through the ctypes module, and establishing a connection with the GBase8s database through the GCI driver; The SQL statement is executed by the GCI driver to obtain a third query result set, and the third query result set is processed to obtain third list data.
6. A driver testing system based on GBase8s database, used to execute the driver testing method based on GBase8s database as claimed in any one of claims 1 to 5, characterized in that: include: Initialization module, used to initialize the test environment of GBase8s database and define a driver management interface; The driver management interface DriverManager contains methods that the client needs to call, including: registerDriver() for registering the driver, getConnection() for obtaining a database connection, execute() for executing SQL statements, and handleRes() for processing result sets. A first construction module is used to construct a test strategy for the JDBC driver class based on the driver management interface to obtain a first test strategy; A second construction module is used to construct a test strategy for the ODBC driver class based on the driver management interface to obtain a second test strategy; A third construction module is used to construct a test strategy for the GCI driver class based on the driver management interface to obtain a third test strategy; A mapping module, used to construct a target adapter class through the first test strategy, the second test strategy and the third test strategy, and map a target instance corresponding to the target adapter class as a parameter to the driver management interface; The step of constructing a target adapter by using the first test strategy, the second test strategy and the third test strategy, and mapping the target instance corresponding to the target adapter class as a parameter to the driver management interface includes: Define the adapter class by using the first test strategy, the second test strategy and the third test strategy to obtain a target adapter class; Create an adapter instance according to the adapter class to obtain a target instance; Mapping the target instance corresponding to the target adapter class as a parameter to the driver management interface; The step of defining the adapter class by using the first test strategy, the second test strategy, and the third test strategy to obtain the target adapter class includes: Performing adapter parameter matching on the first test strategy to obtain first adapter parameters; Performing adapter parameter matching on the second test strategy to obtain second adapter parameters; Performing adapter parameter matching on the third test strategy to obtain third adapter parameters; Extracting adaptation parameters from the first adapter parameter, the second adapter parameter, and the third adapter parameter to obtain target adaptation parameters; Defining an adapter class based on the target adaptation parameter to obtain the target adapter class; The adapter class DriverAdapter adapts the implementation methods of different types of drivers into a unified driver management interface DriverManager, processes the implementation method of the corresponding type of driver through the tested driver type passed by the user, and returns the corresponding execution result; The adapter class contains an instance of a specific driver class, driverobj, as a constructor parameter, and assigns it to the driver attribute of the object. When a new instance of the adapter class DriverAdapter is created, the constructor is automatically called to complete the initialization of the object. It also contains the call of the abstract method in the driver management interface DriverManager. The specific calling method is as follows: use self.driver.registerDriver(driver_type) to call the registration driver method of the specified driver to load the driver; use self.driver.getConnection(driver_type) to call the database connection acquisition method of the specified driver to create a database connection object so that the driver can connect to the database normally; use self.driver.execute(driver_type) to call the SQL statement execution method of the specified driver to execute a specific SQL statement; use self.driver.handleRes(driver_type) to call the result set processing method of the specified driver to extract the required data; A control module, used for controlling the driver test of the GBase8s database through the target adapter; When operating the corresponding driver, use the unified adapter class DriverAdapter to operate objects of different types of driver classes; Put objects of different types of driver classes into a unified adapter class, and indirectly call the adapted objects by accessing methods in the adapter class.
