In this article you will learn about how to add a database functions based on datatype.
A datatype shows you what kind of value a column contain . The various datatypes like numeric, text, date, time, date-time and so on are generally used to represent the type of data. Whenever you want to perform any operations on the data then there are list of database functions available based on the datatype.
Whenever you want to perform any operation on the column using any database function then based on datatype you will select a function and apply it. Suppose if could not find the function in the list then, what to do ?
Helical Insight gives you flexibility to add a new database function. Added database function at the backend level get updated in the database functions list. For Example : adding “substring” function of Text Datatype for MySQL Database.
Generally, Helical Insight supports multiple database function based on 4 datatypes which are date, date-time, numeric and text.
View of Function List
Above image is showing the list of Database function whereas the database used here is MySQL.
If you want to add a new database function “substring” of Text datatype for MySQL Database then follow the steps given below :
Step1 : Open the “mysql.xml” file from following file or folder repository path:
"/hdidev/System/Admin/SqlFunctions"
Step2 : Add the xml code for the required function based on datatype
XML Code :
<function group="text"> <key>sql.text.substring</key> <value>substring</value> <signature><![CDATA[substring(${text}, ${start_position}, ${length})]]></signature> <parameters> <parameter column="true" name="text"/> <parameter defaultValue="1" name="start_position"/> <parameter defaultValue="4" name="length"/> </parameters> <description>It extracts a substring from a string.</description> </function>
Tag Description :
- <function>: This tag encloses the database function. The function category is classified using group attribute. They can be classified into “text”, “numeric”, “date”, “dateTime”
- <key>: The key name should be unique.
- <value>: This tag is used to display text in UI as function name
- <signature>: This tag displays actual syntax of the function where the function parameter are replaced by the expression. This expression gets replaced with actual column during query generation process.
- <parameters>: This tag holds the parameter list required for the function.
- <parameter>: Using this tag we can define default value using defaultValue attribute and the name of the parameter.
eg : <parameter
defaultValue=”4″ //
name=”length”
/> - <description>: Using this tag we can add the function usage description.
eg: defining function definition
Step 3 : After adding the code, save the xml file. To view the updated function list go to adhoc editor > drag and drop column > click column > go to more option > advance > on clicking text datatype > updated function list appears
As function list is updated for MySQL Database, similarly you can do it for other database by modifying database specific xml file.
For more info, reach out to us at demo@helicalinsight.com