
NOTICE: All information contained herein is, and remains
the property of TechnoCore.
The intellectual and technical concepts contained
herein are proprietary to TechnoCore and dissemination of this information or reproduction of this material
is strictly forbidden unless prior written permission is obtained
from TechnoCore.
The ObjImportApi class in ObjDataImportQuery.py is a powerful tool for importing data directly from a database using SQL queries. It is designed to fetch data in manageable chunks, making it suitable for handling large datasets without overwhelming system resources.
LIMIT and OFFSET clauses to the source query to handle pagination.__init__(self, DB=0)Initializes the ObjImportApi object.
DetectSeparator(self, Filename)This method is not applicable for database query imports and returns an empty string.
PrepFile(self, Filename)This method is not applicable for database query imports and returns the filename as is.
OpenFile(self, Filename)Initializes the data import process from a database query. It sets up the initial query with a LIMIT clause, fetches the first batch of rows, and extracts the column headers.
CloseFile(self)This method is a placeholder and does not perform any specific action, as there is no file to close.
ColumnList(self)Returns the list of column names derived from the database query result.
NextRow(self)Retrieves the next row from the result set. If the current batch of rows is exhausted, it fetches the next batch from the database by updating the LIMIT clause in the query.
# Create an instance of the importer
query_importer = ObjImportApi()
# Set the source query
query_importer._Sourcequery = "SELECT * FROM users"
# Initialize the import process
query_importer.OpenFile("") # Filename is not used
# Get the column list
columns = query_importer.ColumnList()
print("Columns:", columns)
# Iterate over the rows
while True:
row = query_importer.NextRow()
if not row:
break
print("Row data:", row)
# No need to close a file