Chapter 2
Database Functions
Introduction
The database functions, found in /lib/db.mv, allows you to perform common tasks such as finding records, reading and writing data. For more information about the structure of the database files referred to in this manual, see Miva Merchant Database Reference Manual.
Administration Functions
The administration functions work with the data in the AdminSessions database.
AdminSession_Delete
Deletes the administration session defined by session_id.
Parameters: session_id Unique identifier generated by the system for the session.AdminSession_Find_Session
Finds the administration session defined by session_id.
Parameters: session_id Unique identifier generated by the system for the session.AdminSession_Insert
Creates an administration session and saves it to the database.
AdminSession_Update
Updates an administration session.
Parameters: session_id Unique identifier generated by the system. user_id Unique identifier generated by the system. lastupdate A unique time identifier generated by the system.Attribute Functions
The attributes functions work with the data in the Attributes database.
Attribute_Delete
Deletes the product attribute defined by id.
Parameters: id Unique attribute identifier generated by the system to identify the attribute in the Attributes database.Attribute_Find_Code
Finds the product attribute defined by product_id and code.
Parameters: product_id Product Identifier for the attribute. code Attribute code entered by store administrator.Attribute_Find_ID
Moves the record pointer to the record in the Attribute database as defined by id.
Parameters: id Unique attribute identifier generated by the system.Attribute_FindFirst_Product
Finds the first record in the Attribute database that matches product_id.
Parameters: product_id Product Identifier for the attribute.Attribute_FindNext_Product
Finds the next record in the Attributes database.
Parameters: product_id Product Identifier for the attribute.Attribute_Insert
Creates an attribute record in the Attributes database for the product defined in product_id and returns the attribute identification (attribute_id).
Attribute_Update
Updates the data fields in the Attributes database for the attribute defined by "id."
Attribute_Update_Order
Repositions the attribute in a display list based on the order parameter.
Parameters: id Unique attribute identifier generated by the system. order Order of appearance of this attribute.Availability Group Functions
The availability groups functions work with the data in the AvailabilityGroups, AvailabilityGroupXCategory, AvailabilityGroupXCustomer, and AvailabilityGroupXProduct databases.
AvailabilityGroup_Category_FindNext_Assigned
Finds the next category record that is assigned to the availability group agrp_id.
Parameters: agrp_id Unique identifier generated by the system for the availability group. offset Record position in the database. search Search criteria chosen by user (assigned).AvailabilityGroup_Category_FindNext_Unassigned
Finds the next category record that is not assigned to the availability group agrp_id.
Parameters: agrp_id Unique identifier generated by the system for the availability group. offset Record position in the database. search Search criteria chosen by user (not assigned).AvailabilityGroup_Category_FindOffset_Assigned
Finds the offset of the next category record that is assigned to the availability group agrp_id.
Parameters: agrp_id Unique identifier generated by the system for the availability group. offset Record position in the database. search Search criteria chosen by user (assigned).AvailabilityGroup_Category_FindOffset_Unassigned
Finds the offset of the next category record that is not assigned to the availability group agrp_id.
Parameters: agrp_id Unique identifier generated by the system for the availability group. offset Record position in the database. search Search criteria chosen by user (not assigned).AvailabilityGroup_Customer_FindNext_Assigned
Finds the next customer record that is assigned to the availability group agrp_id.
Parameters: agrp_id Unique identifier generated by the system for the availability group. offset Record position in the database. search Search criteria chosen by user (assigned).AvailabilityGroup_Customer_FindNext_Unassigned
Finds the next customer record that is not assigned to the availability group agrp_id.
Parameters: agrp_id Unique identifier generated by the system for the availability group. offset Record position in the database. search Search criteria chosen by user (not assigned).AvailabilityGroup_Customer_FindOffset_Assigned
Finds the offset of the next customer record that is assigned to the availability group agrp_id.
Parameters: agrp_id Unique identifier generated by the system for the availability group. offset Record position in the database. search Search criteria chosen by user (assigned).AvailabilityGroup_Customer_FindOffset_Unassigned
Finds the offset of the next customer record that is not assigned to the availability group agrp_id.
Parameters: agrp_id Unique identifier generated by the system for the availability group. offset Record position in the database. search Search criteria chosen by user (not assigned).AvailabilityGroup_Delete
Deletes the availability group, as define by the parameter id, from the availability group database.
Parameters: id Unique identifier generated by the system to identify the availability group.AvailabilityGroup_Find_ID
Sets the database pointer to the availability group record defined by the parameter id.
Parameters: id Unique identifier generated by the system to identify the availability group.AvailabilityGroup_Find_Name
Finds the availability group record defined by the parameter name.
Parameters: name Availability group name.AvailabilityGroup_FindFirst
Finds the first availability group in the database.
AvailabilityGroup_FindFirst_Offset
Finds the offset defined by the parameter offset.
Parameters: offset Record position in the database.AvailabilityGroup_FindNext
Finds the next record in the availability group database.
AvailabilityGroup_Insert
Creates a new database record for an availability group as defined by name.
Parameters: name availability group name.AvailabilityGroup_Product_FindNext_Assigned
Finds the next product record that is assigned to the availability group agrp_id.
Parameters: agrp_id Unique identifier generated by the system to identify the availability group. offset Record position in the database. search Search criteria chosen by user (assigned).AvailabilityGroup_Product_FindNext_Unassigned
Finds the next product record that is not assigned to the availability group agrp_id.
Parameters: agrp_id Unique identifier generated by the system to identify the availability group. offset Record position in the database. search Search criteria chosen by user (not assigned).AvailabilityGroup_Product_FindOffset_Assigned
Finds the offset of the next product record that is assigned to the availability group agrp_id.
Parameters: agrp_id Unique identifier generated by the system to identify the availability group. offset Record position in the database. search Search criteria chosen by user (assigned).AvailabilityGroup_Product_FindOffset_Unassigned
Finds the offset of the next product record that is not assigned to the availability group agrp_id.
Parameters: agrp_id Unique identifier generated by the system to identify the availability group. offset Record position in the database. search Search criteria chosen by user (not assigned).AvailabilityGroup_Update
Updates the name of the availability group in the database.
Parameters: id Unique identifier generated by the system for the availability group. name Availability group nameAvailabilityGroupXCategory_Delete
Deletes the cat_id category from the agrp_id availability group database.
Parameters: agrp_id Unique identifier generated by the system to identify the availability group. cat_id Unique identifier generated by the system to identify the category.AvailabilityGroupXCategory_Find
Finds the cat_id category in the agrp_id availability group.
Parameters: agrp_id Unique identifier generated by the system to identify the availability group. cat_id Unique identifier generated by the system to identify the category.AvailabilityGroupXCategory_FindFirst_Category
Finds the first category in the agrp_id availability group.
Parameters: agrp_id Unique identifier generated by the system to identify the availability group.AvailabilityGroupXCategory_FindNext_Category
Finds the next category for the agrp_id availability group.
Parameters: agrp_id Unique identifier generated by the system to identify the availability group.AvailabilityGroupXCategory_Insert
Creates a record in the AvailabilityGroupXCategory database for cat_id and agrp_id.
Parameters: cat_id Unique identifier generated by the system to identify the category. agrp_id Unique identifier generated by the system to identify the availability group.AvailabilityGroupXCustomer_Delete
Deletes the record in the AvailabilityGroupXCategory database for cat_id and agrp_id.
Parameters: agrp_id Unique identifier generated by the system to identify the availability group. cust_id Unique identifier generated by the system to identify the customer.AvailabilityGroupXCustomer_Find
Finds cust_id and agrp_id in the availabilityGroupXCustomer database.
Parameters: agrp_id Unique identifier generated by the system to identify the availability group. cust_id Unique identifier generated by the system to identify the customer.AvailabilityGroupXCustomer_FindFirst_AvailabilityGroup
Finds the first record of the agrp_id availability group in the availabilityGroupXCustomer database.
Parameters: agrp_id Unique identifier generated by the system to identify the availability group.AvailabilityGroupXCustomer_FindNext_AvailabilityGroup
Finds the next agrp_id availability group in AvailabilityGroupXCustomer database.
Parameters: agrp_id Unique identifier generated by the system to identify the availability group.AvailabilityGroupXCustomer_Insert
Creates a record in the AvailabilityGroupXCustomer database for cust_id and agrp_id.
Parameters: agrp_id Unique identifier generated by the system to identify the availability group. cust_id Unique identifier generated by the system to identify the customer.AvailabilityGroupXProduct_Delete
Deletes the agrp_id/product_id record from the AvailabilityGroupXProduct database.
Parameters: agrp_id Unique identifier generated by the system to identify the availability group. product_id Unique identifier generated by the system to identify the product.AvailabilityGroupXProduct_Find
Sets the record pointer in the agrp_id/product_id record of the AvailabilityGroupXProduct database.
Parameters: agrp_id Unique identifier generated by the system to identify the availability group. product_id Unique identifier generated by the system to identify the product.AvailabilityGroupXProduct_Insert
Creates the agrp_id/product_id record in the availabilityGroupXProduct database.
Parameters: agrp_id Unique identifier generated by the system to identify the availability group. product_id Unique identifier generated by the system to identify the product.Basket Functions
The basket functions work with the data in the Baskets, BasketCharges, BasketList and BasketOptions databases.
Basket_Delete
Deletes the basket for the session_id passed to it.
Parameters: session_id Unique identifier generated by the system to identify a unique customer session and all of its components.Basket_Delete_AllLines
Deletes all basket items for the basket_id passed to it.
Parameters: basket_id Unique identifier generated by the system to identify a unique customer's basket for a unique session.Basket_Delete_Line
Deletes a basket item based for the line_id passed to it.
Parameters: line_id Unique identifier generated by the system to identify a specific line item in a specific basket.Basket_Find_Line
Finds the line_id in a basket.
Parameters: line_id Unique identifier generated by the system to identify a specific line item in a specific basket.Basket_FindFirst_ID
Finds the first item in the basket (id) in the Baskets database.
Parameters: id Identifier for the basket in the Baskets database.Basket_FindNext_ID
Finds the first item in the basket (id) in the Baskets database.
Parameters: id Identifier for the basket in the Baskets database.Basket_Insert
Creates a record in the Baskets database for a basket and returns the basket line_id.
Basket_Quantity
Returns the quantity of product_id in session_id.
Basket_Total
Returns the total dollar value of the items in the basket attached to session_id.
Parameters: session_id Unique identifier generated by the system to identify a unique customer session and all of its components.Basket_TotalQuantity
Returns the total number of all items in the basket attached to session_id.
Parameters: session_id Unique identifier generated by the system to identify a unique customer session and all of its components.Basket_Update_Quantity
Updates the quantity of the basket item line_id with the amount quantity.
Parameters: line_id Identifier for the line number of item within the basket. quantity Quantity (of this item) added to basket.Basket_Weight
Returns the total weight of all items in the basket associated with session_id.
Parameters: session_id Unique identifier generated by the system to identify a unique customer session and all of its components.BasketCharge_DeleteAll_Module
Deletes all charges in the basket defined by basket_id in module_id.
Parameters: basket_id Unique basket identifier generated by the system to identify the basket. module_id Unique module identifier generated by the system.BasketCharge_Insert
Creates a record for a charge to the basket.
BasketCharge_FindFirst_Charge
Finds the first charge in the basket defined by basket_id.
Parameters: basket_id Unique basket identifier generated by the system to identify the basket.BasketCharge_FindFirst_Module
Finds the first charge in the basket defined by basket_id in module_id.
Parameters: basket_id Unique basket identifier generated by the system to identify the basket. module_id Unique module identifier generated by the system.BasketCharge_FindFirst_Type
Finds the first item type in basket_id.
Parameters: basket_id Unique basket identifier generated by the system to identify the basket. type Classification of this charge.
(For example "shipping" or "tax." )BasketCharge_FindNext_Charge
Finds the next charge in the basket defined by basket_id.
Parameters: basket_id Unique basket identifier generated by the system to identify the basket.BasketCharge_FindNext_Module
Finds the next charge in the basket defined by basket_id in module_id.
Parameters: basket_id Unique basket identifier generated by the system to identify the basket. module_id Unique module identifier generated by the system.BasketCharge_FindNext_Type
Finds the next item type in basket_id.
Parameters: basket_id Unique basket identifier generated by the system to identify the basket. type Classification of this charge.
(For example "shipping" or "tax." )BasketCharges_Delete_Type
Deletes the item type in basket_id.
Parameters: basket_id Unique basket identifier generated by the system to identify the basket. type Classification of this charge.
(For example "shipping" or "tax." )BasketList_FindFirst
Finds the first record in the Basketlist database.
BasketList_FindNext
Finds the next record in the Basketlist database.
BasketList_FindSession
Finds the session_id in the Basketlist database.
Parameters: session_id Unique identifier generated by the system to identify the session.BasketList_Free_Order
Resets the values in session_id to zero and null.
Parameters: session_id Unique identifier generated by the system to identify the session.BasketList_MakeDirty
Checks that basket contents remains the same throughout the checkout process for session_id.
Parameters: session_id Unique identifier generated by the system to identify the session.BasketList_Insert
Creates a basket record for the session defined by session_id.
Parameters: session_id Unique identifier generated by the system to identify the session. lastupdate A unique time identifier generated by the system (used with Basket Timeout).BasketList_Save_Order_Info
Saves shipping and billing data for the basket identified by "session_id."
BasketList_Update_Customer
Updates the customer identification (cust_id) for the session (session_id).
Parameters: session_id Unique identifier generated by the system to identify the session. cust_id Unique identifier generated by the system to identify the customer.BasketList_Update_LastUpdate
Updates the lastupdate field of the basket (session_id).
Parameters: session_id Unique identifier generated by the system to identify the session. lastupdate A unique time identifier generated by the system (used with Basket Timeout).BasketList_Update_Payment
Updates the pay information for the basket assigned to session_id.
Parameters: session_id Unique identifier generated by the system to identify the session. pay_id Module identifier for payment module. pay_data Return value from the payment module.BasketList_Update_Shipping
Updates the shipping information for the basket assigned to the session_id.
BasketList_Update_Tax
Updates the sales tax amount for the basket assigned to the session_id.
Parameters: session_id Unique identifier generated by the system to identify the session. tax Sales tax amount.BasketOption_FindFirst_Line
Finds line_id in the Baskets database.
Parameters: line_id Identifier for the line number of the product within the basket.BasketOption_FindNext_Line
Finds the next line in the Baskets database.
Parameters: line_id Identifier for the line number of the product within the basket.BasketOption_Insert
Finds the first line (line_id) for a product in the BasketOptions database and writes a record containing the following parameters.
Batch Functions
The batch functions work with the data in the Batches database.
Batch_Create
Creates the name record in the Batches database.
Parameters: name Name of batch entered by Store Administrator.Batch_Delete
Deletes the id batch from the Batches database.
Parameters: id Unique identifier generated by the system to identify a batch.Batch_Find_ID
Parameters: id Unique identifier generated by the system to identify a batch.Batch_FindFirst
Finds the first line in the Batches database.
Batch_FindNext
Finds the next line in the Batches database.
Parameters: closed Identifies whether or not the batch has been processed.Category Functions
The category functions work with the data in the Categories and CategoryXProduct databases.
Category_Delete
Deletes the id category from the Categories database.
Parameters: id Unique category identifier generated by the system.Category_Find_Code
Finds the code category in the Categories database.
Parameters: code Category code assigned by store owner.Category_Find_ID
Parameters: id Unique category identifier generated by the system.Category_FindFirst
Finds the first category in the Categories database.
Category_FindFirst_Offset
Finds the offset record in the Categories database.
Parameters: offset Record position in the database.Category_FindOffset_Search
Sets record pointer at the first record to match words beyond the record offset.
Parameters: offset Record position in the database. words Search words entered by user.Category_FindFirst_Parent
Finds the category defined as parent_id in the Categories database.
Parameters: parent_id Unique parent category identifier generated by the system to identify the parent category.Category_FindID_Parent
Finds the category defined as id in the Categories database.
Parameters: id Unique category identifier generated by the system to identify the category.Category_FindNext
Finds the next record in the Categories database.
Parameters: parent_id Unique parent category identifier generated by the system to identify the parent category.Category_FindNext_All
Finds the next Categories database record, increments the offset value by one and returns the new offset value.
Parameters: offset Record position in the database. search Search criteria chosen by user (all).Category_FindNext_Parent
Finds the next record after parent_id.
Parameters: parent_id Unique parent category identifier generated by the system to identify the parent category.Category_FindOffset_All
Finds the offset record the Categories database.
Parameters: offset Record position in the database. search Search criteria entered by user (all).Category_Insert
Writes a new record to the Categories database.
Parameters: parent_id Unique parent category identifier generated by the system to identify the category. code Category code assigned by store owner. name Category name.Category_Product_FindNext_Assigned
Finds the next product assigned to cat_id.
Parameters: cat_id Category ID offset Record position in the database. search Search criteria entered by user (assigned).Category_Product_FindNext_Unassigned
Finds the next product not assigned to cat_id.
Parameters: cat_id Category ID offset Record position in the database. search Search criteria entered by user (not assigned).Category_Product_FindOffset_Assigned
Finds the offset of the next product record that is assigned to cat_id.
Parameters: cat_id Category ID offset Record position in the database. search Search criteria entered by user (assigned).Category_Product_FindOffset_Unassigned
Finds the offset of the next product record that is not assigned to cat_id.
Parameters: cat_id Category ID offset Record position in the database. search Search criteria entered by user (not assigned).Category_Sort
Sorts the Categories database by sort_field and by order (ascending or descending).
Parameters: sort_field Field to sort on entered by user. ascending "1" if ascending.Category_Update
Updates data fields in category record id.
Category_Update_Order
Updates the order of appearance of category id.
Parameters: id Unique category identifier generated by the system to identify category. order Order of appearance for category.CategoryXProduct_Delete
Deletes a record from the CategoryXProduct database.
Parameters: cat_id Category identifier. product_id Product identifier.CategoryXProduct_Find
Finds cat_id/product_id record in CategoryXProduct database.
Parameters: cat_id Category identifier. product_id Product identifier.CategoryXProduct_Insert
Creates cat_id/product_id record in CategoryXProduct database.
Parameters: cat_id Category identifier. product_id Product identifier.CategoryXProduct_Sort
Sorts the category_id in the CategoryXProduct database.
Parameters: category_id Category identifier. sort_field Field to sort on entered by user. ascending "1" if ascending.CategoryXProduct_Update_Order
Updates the order information n the CategoryXProduct database.
Parameters: cat_id Category identifier. product_id Product identifier. order Order identifier.Country Functions
The country functions work with the data in the Countries database.
Country_Find_Alpha
Finds the country record (alpha) in the country database.:
Parameters: alpha Alpha country code.Country_FindFirst
Finds first record in Countries database.
Country_FindNext
Finds next record in Countries database.
Country_Insert
Creates record in the Countries database for name.
Parameters: name Country name. alpha Alpha country code. numeric Numeric country code.Customer Functions
The customer functions work with the data in the Customers and CustomerEmail databases.
Customer_Category_Find_Code
Returns the category identification based on the cust_id and code passed to it.
Parameters: cust_id Unique identifier generated by the system to identify the customer. code Category code assigned by the store owner.Customer_Category_Find_ID
Determines if the customer (cust_id) can see a particular category (id).
Parameters: cust_id Unique identifier generated by the system to identify the customer. id Unique category identifier generated by the system.Customer_Category_FindFirst_Parent
Finds the first category that the customer (cust_id) can view that has the specific parent category (parent_id).
Parameters: cust_id Unique identifier generated by the system to identify the customer. parent_id Unique parent category identifier generated by the system.Customer_Category_FindID_Parent
Finds the specific category (id) that the customer (cust_id) can view.
Parameters: cust_id Unique identifier generated by the system to identify the customer. id Unique category identifier generated by the system.Customer_Category_FindNext_Parent
Finds the next category that the customer (cust_id) can view that has the specific parent category (parent_id).
Parameters: cust_id Unique identifier generated by the system to identify the customer. parent_id Unique parent category identifier generated by the system.Customer_Category_FindFirst_Product
Finds the first category that the customer (cust_id) can view that has the specific product (product_id).
Parameters: cust_id Unique identifier generated by the system to identify the customer. product_id Product identification assigned by store owner.Customer_Category_FindNext_Product
Finds the next category that the customer (cust_id) can view that has the specific product (product_id).
Parameters: cust_id Unique identifier generated by the system to identify the customer. product_id Product identification assigned by store owner.Customer_Delete
Deletes record (id) from the Customers database.
Parameters: id Unique customer identifier generated by the system.Customer_Find_ID
Finds the customer (id) record in the Customers database.
Parameters: id Unique customer identifier generated by the system.Customer_Find_Login
Finds the record in the Customers database that contains customer login name.
Parameters: login Customer login name.Customer_FindFirst
Finds the first customer in the Customers database.
Customer_FindFirst_Offset
Opens the Customer database and skips to the offset record.
Parameters: offset Record position in the database.Customer_FindNext
Finds the next record after offset in the Customers database.
Customer_FindNext_All
Finds the next record after offset in the Customer database.
Parameters: offset Record position in the database. search Not currently used.Customer_FindNext_Words
Finds the next record in the Customers database.
Parameters: words Not currently used.Customer_FindOffset_All
Finds the record defined by search after the offset in the Customers database.
Parameters: offset Record position in the database. search Search text entered by the user.Customer_Insert
Creates a customer record in the Customers database.