Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

You can utilize 3 approaches to store extension data to the database.

...


As first two are straight forward, we will cover #3 in more details. 
Dataset aproach offers quick and worry free method to handle data without dealing with SQL and creating specific database tables. Data can be handled via easy dataset class methods.
Good example for dataset usage will be occasionally edited information for products, categories, customers and orders data extension, polls, questioners, etc.

Note

It is not recommended to use dataset for large sets and transactional type of data, since performance might be affected. Eventhough, we tested performance with 500000 rows, and no slowdown noticed, it is still not desired to use this storage for high traffic read and write.

What is Dataset?

Say you need to develop a poll extension and need to store records of poll questions and answers. Normally, you would create and add 2 or more tables to the databases to handle data for the poll. With the dataset, we created an abstraction layer to the database, that allows you to skip database creation and go directly to handling data.
Dataset class will handle all the data storing and management for you with interface of methods provided. It is very easy. You name new dataset (traditionally table) or use existing dataset . Dataset can be created during extension installation from XML file provided in the extension package. It can be also removed with extension uninstall. No direct access to SQL or database is needed. If restriction access required to the dataset, it needs to be handled pragmatically based on AbanteCart permissions. If you decide to use traditional database tables in extension, you will need to create SQL scripts with install, uninstall and disable extension management process.

...

Code Block
languagephp
themeDJango
$my_data -> setDatasetProperties(	
 array( 	
"some_property_name"=>”some_value”>"some_value", 			
"some_property_name"=>"some_value”value") );


Note

property’s name and value have limit size at 255 characters. Method setDatasetProperties completely changes values of properties, without updating.

Properties can be accessed with getDatasetProperties() method. This method returns an array with all the properties:

...

Code Block
languagephp
themeDJango
// define columns for questions
$poll_qs->defineColumns (
   		 array ( "name"=>"language_code",
   			 	"type"=>"varchar"),
   		 array ( "name"=>"question",
   			 	"type"=>"text"),
      		 };

Dataset’s columns definition contain list of value’s descriptions (fields). Every dataset consist of columns or fieldset. Now dataset concept supports following column types: 
integer
float
varchar
text
boolean
timestamp


Note

if you need to identify rows in your dataset by id, you need to create a column and make sure in your code to provide this value unique. If you later call getRows with your unique field and value, you will always get one unique row.


Code Block
languagephp
themeDJango
//set properties for the dataset
$poll_qs->setColumnProperties ( 
array ( "column_name" => "language_code",
   				 "property_name" => "length",
   				 "property_value" => "2" ),		
array ( "column_name" => "question",
   				 "property_name" => "translation_key",
   				 "property_value" => "question_txt" ),		 
   			 );


Column properties are used to keep global information for the columns for the given dataset . This properties can be used to identify data type and constrains for the column. Validation code can use these properties before saving data.

In some cases, column properties can be used to store data and act as 1 row table. If you have only 1 row of data and it is not changing you can just use columns properties to store data and avoid extra step to use rows.
Columns properties are not required, but helpful.
Actual data for the datasets is stored in rows that are similar to rows in traditional database or spreadsheet. Every row have columns (fields) that are set in the defineColumns method described above.

Let first see how we can add a row to example dataset:

Code Block
languagephp
themeDJango
$poll_qs->addRows (  array(
	array(   language_code => “en”"en", question => “What"What color do you like?" ),
	array(   language_code => “en”"en", question => “What"What shape do you like?" )  
) );

If all rows are inserted successful the return will be total number of rows added that shouldbe same as imputed array count.

...

Code Block
languagephp
themeDJango
$rows = poll_qs->searchRows ( array(   name=> “language"language_code”code",  operator => "=",  value => “en”"en"   )  ); 	

or

Code Block
languagephp
themeDJango
$rows = poll_qs->searchRows ( array(   name=> “question”"question",  operator => “LIKE”"LIKE",  value => “color”"color"   )  ); 

where “condition” may be one of list:
“=”
”>”
”<”
LIKE

To delete the row from the dataset you can simply call method deleteRows

Code Block
languagephp
themeDJango
$my_data->deleteRows( array( "column_name"=>string, "operator"=>string, "value"=>string )  );

If success, method will return total number of rows deleted.

To drop dataset you can use simple command:

Code Block
languagephp
themeDJango
$my_data->dropDataset();


Warning

This method will completely delete data and settings in the dataset. Make sure you know what you do.

To make things simple to batch load there is a method to load data set via XML. You can create and populate data set with one function loadXML and simple XML node structure

...