def export_sql(self): file_name = os.getcwd() + "\\export_sql\\category.sql" with open(file_name, mode="w", encoding="utf-8") as wf: wf.write("SET IDENTITY_INSERT dbo.tbl_Category ON;\n") wf.write("\n") wf.write("DELETE FROM dbo.tbl_Category;\n") wf.write("\n") index = 0 for category in self.categories: index += 1 sql_text = "" sql_text += "INSERT INTO dbo.tbl_Category(" sql_text += " ID" sql_text += ", CategoryName" sql_text += ", CategoryDescription" sql_text += ", CategoryLevel" sql_text += ", ParentID" sql_text += ", IsHidden" sql_text += ", CreatedDate" sql_text += ", CreatedBy" sql_text += ", ModifiedDate" sql_text += ", ModifiedBy" sql_text += ") VALUES(" sql_text += " " + CommonSql.f_str_value(category.id) sql_text += ", " + CommonSql.f_str_value( category.category_name) sql_text += ", " + CommonSql.f_str_value( category.category_description) sql_text += ", " + CommonSql.f_str_value( category.category_level) sql_text += ", " + CommonSql.f_str_value(category.parent_id) sql_text += ", " + CommonSql.f_str_value(category.is_hidden) sql_text += ", " + CommonSql.f_str_value( category.create_date) sql_text += ", " + CommonSql.f_str_value(category.create_by) sql_text += ", " + CommonSql.f_str_value( category.modified_date) sql_text += ", " + CommonSql.f_str_value( category.modified_by) sql_text += ");\n" wf.write(sql_text) if index > 100: wf.write("GO\n") index = 0 wf.write("SET IDENTITY_INSERT dbo.tbl_Category OFF;\n")
def export_sql(self): file_name = os.getcwd() + "\\export_sql\\product_image.sql" with open(file_name, mode="w+", encoding="utf-8") as wf: wf.write("SET IDENTITY_INSERT dbo.tbl_ProductImage ON;\n") wf.write("\n") wf.write("DELETE FROM dbo.tbl_ProductImage;\n") wf.write("\n") index = 0 for product_image in self.product_images: index += 1 sql_text = "" sql_text += "INSERT INTO dbo.tbl_ProductImage(" sql_text += " ID" sql_text += ", ProductID" sql_text += ", ProductImage" sql_text += ", IsHidden" sql_text += ", CreatedDate" sql_text += ", CreatedBy" sql_text += ", ModifiedDate" sql_text += ", ModifiedBy" sql_text += ") VALUES(" sql_text += " " + CommonSql.f_str_value(product_image.id) sql_text += ", " + CommonSql.f_str_value( product_image.product_id) sql_text += ", " + CommonSql.f_str_value( product_image.product_image) sql_text += ", " + CommonSql.f_str_value( product_image.is_hidden) sql_text += ", " + CommonSql.f_str_value( product_image.created_date) sql_text += ", " + CommonSql.f_str_value( product_image.created_by) sql_text += ", " + CommonSql.f_str_value( product_image.modified_date) sql_text += ", " + CommonSql.f_str_value( product_image.modified_by) sql_text += ");\n" wf.write(sql_text) if index > 100: wf.write("GO\n") index = 0 wf.write("SET IDENTITY_INSERT dbo.tbl_ProductImage OFF;\n")
def export_sql(self): file_name = os.getcwd() + "\\export_sql\\product_variable.sql" with open(file_name, mode="w+", encoding="utf-8") as wf: wf.write("SET IDENTITY_INSERT dbo.tbl_ProductVariable ON;\n") wf.write("\n") wf.write("DELETE FROM dbo.tbl_ProductVariable;\n") wf.write("\n") index = 0 for product_variable in self.product_variables: index += 1 sql_text = "" sql_text += "INSERT INTO dbo.tbl_ProductVariable(" sql_text += " ID" sql_text += ", ProductID" sql_text += ", ParentSKU" sql_text += ", SKU" sql_text += ", Stock" sql_text += ", StockStatus" sql_text += ", Regular_Price" sql_text += ", CostOfGood" sql_text += ", Image" sql_text += ", ManageStock" sql_text += ", IsHidden" sql_text += ", CreatedDate" sql_text += ", CreatedBy" sql_text += ", ModifiedDate" sql_text += ", ModifiedBy" sql_text += ", color" sql_text += ", size" sql_text += ", RetailPrice" sql_text += ", MinimumInventoryLevel" sql_text += ", MaximumInventoryLevel" sql_text += ", SupplierID" sql_text += ", SupplierName" sql_text += ") VALUES(" sql_text += " " + CommonSql.f_str_value(product_variable.id) sql_text += ", " + CommonSql.f_str_value(product_variable.product_id) sql_text += ", " + CommonSql.f_str_value(product_variable.parent_sku) sql_text += ", " + CommonSql.f_str_value(product_variable.sku) sql_text += ", " + CommonSql.f_str_value(product_variable.stock) sql_text += ", " + CommonSql.f_str_value(product_variable.stock_status) sql_text += ", " + CommonSql.f_str_value(product_variable.regular_price) sql_text += ", " + CommonSql.f_str_value(product_variable.cost_of_good) sql_text += ", " + CommonSql.f_str_value(product_variable.image) sql_text += ", " + CommonSql.f_str_value(product_variable.manage_stock) sql_text += ", " + CommonSql.f_str_value(product_variable.is_hidden) sql_text += ", " + CommonSql.f_str_value(product_variable.created_date) sql_text += ", " + CommonSql.f_str_value(product_variable.created_by) sql_text += ", " + CommonSql.f_str_value(product_variable.modified_date) sql_text += ", " + CommonSql.f_str_value(product_variable.modified_by) sql_text += ", " + CommonSql.f_str_value(product_variable.color) sql_text += ", " + CommonSql.f_str_value(product_variable.size) sql_text += ", " + CommonSql.f_str_value(product_variable.retail_price) sql_text += ", " + CommonSql.f_str_value(product_variable.minimum_inventory_level) sql_text += ", " + CommonSql.f_str_value(product_variable.maximum_inventory_level) sql_text += ", " + CommonSql.f_str_value(product_variable.supplier_id) sql_text += ", " + CommonSql.f_str_value(product_variable.supplier_name) sql_text += ");\n" wf.write(sql_text) if index > 100: wf.write("GO\n") index = 0 wf.write("SET IDENTITY_INSERT dbo.tbl_ProductVariable OFF;\n")
def export_sql(self): file_name = os.getcwd() + "\\export_sql\\variable_value.sql" with open(file_name, mode="w", encoding="utf-8") as wf: wf.write("SET IDENTITY_INSERT dbo.tbl_VariableValue ON;\n") wf.write("\n") wf.write("DELETE FROM dbo.tbl_VariableValue;\n") wf.write("\n") index = 0 for variable_value in self.variable_values: index += 1 sql_text = "" sql_text += "INSERT INTO dbo.tbl_VariableValue(" sql_text += " ID" sql_text += ", VariableID" sql_text += ", VariableName" sql_text += ", VariableValue" sql_text += ", IsHidden" sql_text += ", CreatedDate" sql_text += ", CreatedBy" sql_text += ", ModifiedDate" sql_text += ", ModifiedBy" sql_text += ", VariableValueText" sql_text += ", SKUText" sql_text += ") VALUES(" sql_text += " " + CommonSql.f_str_value(variable_value.id) sql_text += ", " + CommonSql.f_str_value( variable_value.variable_id) sql_text += ", " + CommonSql.f_str_value( variable_value.variable_name) sql_text += ", " + CommonSql.f_str_value( variable_value.variable_value) sql_text += ", " + CommonSql.f_str_value( variable_value.is_hidden) sql_text += ", " + CommonSql.f_str_value( variable_value.create_date) sql_text += ", " + CommonSql.f_str_value( variable_value.create_by) sql_text += ", " + CommonSql.f_str_value( variable_value.modified_date) sql_text += ", " + CommonSql.f_str_value( variable_value.modified_by) sql_text += ", " + CommonSql.f_str_value( variable_value.variable_value_text) sql_text += ", " + CommonSql.f_str_value( variable_value.sku_text) sql_text += ");\n" wf.write(sql_text) if index > 100: wf.write("GO\n") index = 0 wf.write("SET IDENTITY_INSERT dbo.tbl_VariableValue OFF;\n")
def export_sql(self): file_name = os.getcwd() + "\\export_sql\\in_out_product_variable.sql" with open(file_name, mode="w+", encoding="utf-8") as wf: wf.write("SET IDENTITY_INSERT dbo.tbl_StockManager ON;\n") wf.write("\n") wf.write("DELETE FROM dbo.tbl_StockManager;\n") wf.write("\n") index = 0 for product in self.in_out_product_variable: index += 1 sql_text = "" sql_text += "INSERT INTO dbo.tbl_StockManager(" sql_text += " ID" sql_text += ", AgentID" sql_text += ", ProductID" sql_text += ", ProductVariableID" # sql_text += ", ProductVariableName" # sql_text += ", ProductVariableValue" sql_text += ", Quantity" sql_text += ", QuantityCurrent" sql_text += ", Type" # sql_text += ", IsHidden" sql_text += ", CreatedDate" sql_text += ", CreatedBy" sql_text += ", ModifiedDate" sql_text += ", ModifiedBy" # sql_text += ", ProductType" sql_text += ", NoteID" sql_text += ", OrderID" # sql_text += ", SessionInOutID" sql_text += ", Status" # sql_text += ", ProductName" sql_text += ", SKU" # sql_text += ", ProductImage" # sql_text += ", ProductVariable" sql_text += ", MoveProID" sql_text += ", ParentID" sql_text += ") VALUES(" sql_text += " " + CommonSql.f_str_value(product.id) sql_text += ", " + CommonSql.f_str_value(product.agent_id) sql_text += ", " + CommonSql.f_str_value(product.product_id) sql_text += ", " + CommonSql.f_str_value( product.product_variable_id) # sql_text += ", " + CommonSql.f_str_value(product.product_variable_name) # sql_text += ", " + CommonSql.f_str_value(product.product_variable_value) sql_text += ", " + CommonSql.f_str_value(product.quantity) sql_text += ", " + CommonSql.f_str_value( product.quantity_current) sql_text += ", " + CommonSql.f_str_value(product.type) # sql_text += ", " + CommonSql.f_str_value(product.is_hidden) sql_text += ", " + CommonSql.f_str_value( product.created_date) sql_text += ", " + CommonSql.f_str_value(product.created_by) sql_text += ", " + CommonSql.f_str_value( product.modified_date) sql_text += ", " + CommonSql.f_str_value( product.modified_by) # sql_text += ", " + CommonSql.f_str_value(product.product_type) sql_text += ", " + CommonSql.f_str_value(product.note) sql_text += ", " + CommonSql.f_str_value(product.order_id) # sql_text += ", " + CommonSql.f_str_value(product.session_in_out_id) sql_text += ", " + CommonSql.f_str_value(product.status) # sql_text += ", " + CommonSql.f_str_value(product.product_name) sql_text += ", " + CommonSql.f_str_value(product.sku) # sql_text += ", " + CommonSql.f_str_value(product.product_image) # sql_text += ", " + CommonSql.f_str_value(product.product_variable) sql_text += ", " + CommonSql.f_str_value( product.move_pro_id) sql_text += ", " + CommonSql.f_str_value(product.parent_id) sql_text += ");\n" wf.write(sql_text) if index > 100: wf.write("GO\n") index = 0 wf.write("SET IDENTITY_INSERT dbo.tbl_InOutProductVariable OFF;\n")
def export_sql(self): file_name = os.getcwd() + "\\export_sql\\product.sql" with open(file_name, mode="w", encoding="utf-8") as wf: wf.write("SET IDENTITY_INSERT dbo.tbl_Product ON;\n") wf.write("\n") wf.write("DELETE FROM dbo.tbl_Product;\n") wf.write("\n") index = 0 for product in self.get_product_list(): index += 1 if product.product_title is not None: product.product_title = product.product_title.replace( "'", "''") if product.product_content is not None: product.product_content = product.product_content.replace( "\n", "").replace("'", "''") sql_text = "" sql_text += "INSERT INTO dbo.tbl_Product(" sql_text += " ID" sql_text += ", CategoryID" sql_text += ", ProductOldID" sql_text += ", ProductTitle" sql_text += ", ProductContent" sql_text += ", ProductSKU" sql_text += ", ProductStock" sql_text += ", StockStatus" sql_text += ", ManageStock" sql_text += ", Regular_Price" sql_text += ", CostOfGood" sql_text += ", Retail_Price" sql_text += ", ProductImage" sql_text += ", ProductType" sql_text += ", IsHidden" sql_text += ", CreatedDate" sql_text += ", CreatedBy" sql_text += ", ModifiedDate" sql_text += ", ModifiedBy" sql_text += ", Materials" sql_text += ", MinimumInventoryLevel" sql_text += ", MaximumInventoryLevel" sql_text += ", SupplierID" sql_text += ", SupplierName" sql_text += ", ProductStyle" sql_text += ") VALUES(" sql_text += " " + CommonSql.f_str_value(product.id) sql_text += ", " + CommonSql.f_str_value( product.category_id) sql_text += ", " + CommonSql.f_str_value( product.product_old_id) sql_text += ", " + CommonSql.f_str_value( product.product_title) sql_text += ", " + CommonSql.f_str_value( product.product_content) sql_text += ", " + CommonSql.f_str_value( product.product_sku) sql_text += ", " + CommonSql.f_str_value( product.product_stock) sql_text += ", " + CommonSql.f_str_value( product.stock_status) sql_text += ", " + CommonSql.f_str_value( product.manage_stock) sql_text += ", " + CommonSql.f_str_value( product.regular_price) sql_text += ", " + CommonSql.f_str_value( product.cost_of_good) sql_text += ", " + CommonSql.f_str_value( product.retail_price) sql_text += ", " + CommonSql.f_str_value( product.product_image) sql_text += ", " + CommonSql.f_str_value( product.product_type) sql_text += ", " + CommonSql.f_str_value(product.is_hidden) sql_text += ", " + CommonSql.f_str_value( product.created_date) sql_text += ", " + CommonSql.f_str_value(product.created_by) sql_text += ", " + CommonSql.f_str_value( product.modified_date) sql_text += ", " + CommonSql.f_str_value( product.modified_by) sql_text += ", " + CommonSql.f_str_value(product.materials) sql_text += ", " + CommonSql.f_str_value( product.minimum_inventory_level) sql_text += ", " + CommonSql.f_str_value( product.maximum_inventory_level) sql_text += ", " + CommonSql.f_str_value( product.supplier_id) sql_text += ", " + CommonSql.f_str_value( product.supplier_name) sql_text += ", " + CommonSql.f_str_value( product.product_style) sql_text += ");\n" wf.write(sql_text) if index > 100: wf.write("GO\n") index = 0 wf.write("SET IDENTITY_INSERT dbo.tbl_Product OFF;\n")