Miva Script

MivaScript

Miva Script is the server side scripting language of the Miva Merchant shopping cart, but it's uses go much further. It is especially well suited for web development having built in support for MySQL, MivaSQL and xBase3 databases.

A typical Miva Script application combines HTML tags, Miva Script tags and functions; is compiled and uploaded to a web server running the FREE Miva Merchant Empresa. You can also run your scripts on your local computer by running the FREE Miva Merchant Mia, making it very easy to start learning Miva Script right away. Oh and did we mention the Miva Script Compiler is also FREE.

Miva Script tags and functions correspond to typical programming language constructs. The database, mail, commerce and new graphics functionality provide a rich set of tools for application development.

Miva Script is fast. Because it is efficiently coded and compiled, your server side scripts will execute quicker and your web pages will display faster providing your users with a better experience.

Start learning Miva Script now!   Online Module Builder for Miva Merchant

Examples in Each Chapter

Each chapter contains examples that you can copy, paste and compile as you learn Miva Script.

Example

<html>
<body>
<b><MvEVAL EXPR="{ 'This is my first Miva Script' }"></b><br />
</body>
</html>

Whats New

5.38 Release Notes (1/09/2023)

Bugs Fixed

  • MS-987: Skipping to previous index record can cause a segfault when no more records exist
  • MS-986: Asynchronous tasks that call miva_async_sleep after they have timed out wake can run forever

Other Changes

  • MacOS binaries are now signed and notarized to prevent trusted execution / GateKeeper issues

5.37 Release Notes (11/18/2022)

Bugs Fixed

  • MS-984: OpenSSL_1_1_x loads functions from the wrong libraries causing failures on Windows
  • MS-975: XBase3 EOF variable is writeable in certain scenarios
  • MS-974: ISNULL does not work as expected with XBase variables
  • MS-971: Special variables need to define their primary value type when they are initially loaded
  • MS-970: XBaseDatabase totrec, recno, and deleted variables do not properly handle value conversion
  • MS-969: Remove unused Variable::Element method
  • MS-967: ConfigurationAggregateVariable does not overload all necessary functions
  • MS-964: Multiple special variables do not properly evaluate when compared
  • MS-963: ISNULL s.process_name returns 1 until the value is loaded
  • MS-962: ProcessNameVariable will return 0 / 0.00 if s.process_name is retrieved as an integer / double
  • MS-961: dBase and MivaSQL files are limited to 2^31 bytes
  • MS-959: File functions, both core and API, do not support 64-bit sizes and offsets
  • MS-957: Variable::value_integer/value_double should not convert the variable when the value is null
  • MS-954: s.dyn_time_remaining should return 0 when no time is remaining and a timeout is configured
  • MS-953: MvCALL: Invalid memory access when the URL is blank
  • MS-950: Add miva_json_encode builtin
  • MS-949: ImmutableVariable does not override Convert_Aggregate allowing the variable to be converted to another data type
  • MS-948: Allow POST-ed content errors to be logged to the error syslog
  • MS-945: MvCAPTURE uses memory inefficiently and is slow when handling large blocks of captured output
  • MS-944: timezone() is returning -0 for GMT
  • MS-943: Create new ternary operator type builtin function "ternary( , , )"
  • MS-941: Commands out of sync error when using MariaDB 10.x
  • MS-936: A large compiler compatibility flag number can create a buffer overflow
  • MS-935: Add support for a Ubuntu build system
  • MS-909: Array does not properly track entry count when using Set
  • MS-8: UPDATE with index fails to update all records
New Features
  • Added new "input" option for MvCONFIG_ERROR_SYSLOG. This will cause any input errors such as unknown POST-ed content type, POST-ed data is too long, etc... to record the error to the system log.
  • Timeouts caused by the processing of POST-ed data will now be recorded to the system log when the MvCONFIG_ERROR_SYSLOG contains the "timeout" option.

New Built-in Functions

ternary( condition, if_true, if_false ) Tests the condition to determine whether if_true or if_false should be returned. It should be noted that the if_true and if_false values will always be evaluated even when the condition is not met, but only the met condition will be returned.

Parameters:
  • condition: A value that will be tested
  • if_true: The value to return when the condition is true
  • if_false: The value to return when the condition is false
Return Value:
  • if_true value when condition is true, otherwise the if_false value

miva_json_encode( input var, flags ) Generates a valid JSON formatted blob based on the passed in data

Parameters:
  • input var: The data that should be encoded. Can be a value, structure, or array.
  • flags: A comma separated list of the following options:
  • - pretty: Formats the JSON blob with new lines, tabs, etc..
Return Value:
  • The generated JSON blob

New API Functions

int mvVariable_IsTrue( mvVariable ) Takes a variable and checks to see if it evaluates to a true value or not

Parameters:
  • mvVariable variable: The variable to evaluate
Return Value:
  • 1 if true, 0 otherwise

char * mvProgram_JSON_Encode( mvProgram program, mvVariable input, int flags, int *data_length, int *data_size ) Takes a variable and generates a valid JSON formatted blob

Parameters:
  • mvProgram program: The current MivaVM
  • mvVariable input: The data that should be encoded
  • int flags: Flags bitor-ed together; supports flags are MIVA_JSONENCODE_FLAG_PRETTY
  • int *data_length: Pointer to an integer that will contain the length of the returned data
  • int *data_size: Pointer to an integer that will contain the size of the memory buffer
Return Value:
  • Pointer to the generated JSON blob

Other Changes

  • This release introduces support for Ubuntu 20.x and Apple silicon systems
  • MacOS systems now uses os_log for its logging events. This replaces the previous syslog logging mechanism. The log events can now be viewed via the Console application or via the command line "log" program. All logs will be tagged with a subsystem of "com.miva.empresa". Example on viewing the logs: log show --predicate "subsystem =\"com.miva.empresa\""
  • dBase and MivaSQL files now supports files over 2GB

5.36 Release Notes

Bugs Fixed

  • MS-931: Add bzip2_compress / bzip2_decompress builtins
  • MS-929: Remove internal PostgreSQL constants
  • MS-928: FastCGI applications should have a unique value for each request that can be used for logging
  • MS-927: CentOS8 FastCGI fails to list directories
  • MS-924: Add miva_array_combine builtin
  • MS-923: SMTP DATA terminator can be output prior to the DATA command being issued
  • MS-922: Runtime errors can be output within MvSMTP server connection
  • MS-920: Transition all build systems to compiling mysql.so against MariaDB header files
  • MS-918: Prepared statements are not removed from the internal PostgreSQL library connector
  • MS-916: Copying a NullVariable to a Variable should explicitly set the have_string to 1 and preferred data type to VARDATATYPE_STRING
  • MS-912: Using a non-numeric LAST / COUNT value for MvFOR / MvFOREACH can cause an infinite loop
New Features

New Built-in Functions

miva_array_combine ( array var, compare_callback, combine_callback, flags, data var ) This function will combine multiple elements within an array into a single element depending on the design of the compare and callback functions

Parameters:
  • array: The array to iterate
  • compare_callback: The callback function that determines whether the 2 elements of the array should be combined
  • combine_callback: The callback function that defines the operation to perform on the 2 elements that are being combined
  • flags: Flags that dictate how the function behaves
  • data: Additional data passed to the compare and combine callback functions
Return Value:
  • The number of elements in the array
Flags:
  • sorted: The array will be processed as if the elements are sorted in ascending fashion, stopping the comparison of the current element once the next element does not match. If the flag is omitted, the function will do a brute force search across the elements, meaning every element will be checked against every other element in the array.
Example MivaScript code:

Compare_Callback( element1 var, element2 var, data var )

Parameters:
  • element1: An array element
  • element2: An array element
  • data: The data that was passed to miva_array_combine
Return Value:
  • - 1 if the elements should be combined, 0 otherwise

Combined_Callback( element1 var, element2 var, data var )

Parameters:
  • element1: An array element
  • element2: An array element
  • data: The data that was passed to miva_array_combine
Return Value:
  • The combined variable made up of element1 and element2

bzip2_compress ( data var, block_size, compressed var )

Compress the data using the bzip2 format

Parameters:
  • data: The data to be compressed
  • block_size: The block size to use for the compression (valid values are 1-9; 1 being faster and less efficient compression, 9 being slower and more efficient compression)
  • compressed: The data compressed in bzip2 format
Return Value:
  • 1 on success, 0 on failure

bzip2_decompress ( compressed var, decompressed )

Decompress the data using the bzip2 format

Parameters:
  • compressed: The compressed bzip2 data
  • decompressed: The compressed bzip2 data
Return Value:
  • 1 on success, 0 on failure

5.35 Major Changes

  • Added ability to mark a function as public / private to restrict whether the function can be called from an MvDO. Using this feature will prevent the entire file / function from being run on older versions of the engine. Added optional "ACCESS" attribute to the MvFUNCTION tag that supports the following values:
    • "public": The function can be called from an MvDO
    • "private": The function cannot be called from an MvDO
  • If the "ACCESS" attribute is omitted or left blank, the function will be made public
  • Added compiler flag, -A, which will make all functions that do not explicitly set a function's "ACCESS" attribute to "public" private by default
  • Added the ability to log slow requests to the system log via the MvCONFIG_SLOWREQUEST_SYSLOG configuration settings Mia now requires Windows 8 or higher
  • The template compiler now generates byte-code for entities instead of relying on the VM to parse named constants at runtime

5.34 Major Changes

  • The following libraries are now dynamically loaded and need to be registered as system libraries:
    • MySQL: A system library with code "MYSQLCLIENT" must be registered and point to the location of the MySQL client library
    • E.g. <SYSTEM-LIB CODE="MYSQLCLIENT" LIBRARY="/usr/local/mysql/lib/libmysqlclient.dylib">>
    • PostgreSQL: A system library with code "PQ" must be registered and point to the location of the PostgreSQL library
    • E.g. <SYSTEM-LIB CODE="PQ" LIBRARY="/usr/lib/libpq.dylib">
    • bzip2: A system library with code "BZ2" must be registered and point to the location of the bzip2 library
    • E.g. <SYSTEM-LIB CODE="BZ2" LIBRARY="/usr/lib/libbz2.dylib">
  • Added support for routing TCP requests through a SOCKS proxy server.
  • Added support for OpenSSL 1.1.x.
  • Added the ability to log slow requests to the system log via the MvCONFIG_SLOWREQUEST_SYSLOG configuration settings
  • Tag error messages such as g.MvOPENVIEW_Error, g.MvCALL_Error, and g.MvDO_Error no longer contain entity encoded values. The MivaScript developer is now responsible for encoding any and all necessary values before outputting the data.
  • The FastCGI application now loads the MvCONFIG_LIBRARY environment variable from its own environment. This requires the environment variable to be set prior to the FastCGI process being spawned.
  • The FastCGI application now uses the SCRIPT_NAME environment variable instead of the PATH_INFO environment variable when parsing and executing the desired file path.

Spring 2018 Site updated to 5.32. Added Redis: Redis allows building advanced caching mechanisms into Miva Script applications.

8/8/2017 Site updated to 5.26, 5.27 and 5.28. The MvCall Page has better descriptions of the methods, links to more information and a few new examples.

9/19/2016, All function category assignments were re-evaluated and corrections made. A new category called Encoding was added below the String category and Inspection was moved below Strings. Also array and structure functions were removed from system and placed under the Array category.

Releases 5.23 and 5.24 continue adding functionality to the language. Releases 5.20 and 5.21 added to the Storemorph template compiler language. Releases 5.17 and 5.18 were the most significant updates in several years.  The list below is not comprehensive. See the release notes in Resources for more detail.

Most significant is the inclusion of the gd library graphic functions.

  • V 5.36
  • miva_array_combine ( array var, compare_callback, combine_callback, flags, data var )
  • Compare_Callback( element1 var, element2 var, data var )
  • Combined_Callback( element1 var, element2 var, data var )
  • bzip2_compress ( data var, block_size, compressed var )
  • bzip2_decompress ( compressed var, decompressed )
  • V 5.35
  • miva_ip_version ( ip )
  • miva_ip_normalize( ip, normalized_ip var )
  • V 5.34
  • gethostbyname( hostname, ip var )
  • mysql_get_client_info()
  • redis_client_id( conn_id )
  • redis_connect_with_timeout( ip, port, timeout, conn_id var )
  • redis_connect_unix( path, conn_id var )
  • rsa_public_encrypt_oaep( rsa, plaintext, encrypted var )
  • rsa_private_decrypt_oaep( rsa, encrypted, plaintext var )
  • strcmp( left, right )
  • strcasecmp( left, right )
  • file_last_error()
  • V 5.33
  • miva_struct_member_callback( struct var, function, data var )
  • CustomCallback( struct var, member, data var )
  • V 5.32
  • file_set_time()
  • crypto_next_error()
  • crypto_clear_error()
  • crypto_evp_sign()
  • crypto_evp_verify()
  • evp_pkey_load_pubkey_x509()
  • crypto_last_error() updated.
  • trim(), ltrim(), rtrim() updated for arrays.
  • MvCALL: added content "application/json"
  • evp_pkey_load_mem() updated.
  • Redis: Added support for Redis
  • V 5.31
  • miva_joinstring()
  • miva_splitstring() fixed
    diagtool.mvc -- added MvCALL Test
  • V 5.30 Minor Fixes
  • V 5.29 Minor Fixes
  • V 5.28
  • evp_pkey_free()
  • min()
  • max()
  • file_overwrite()
  • MvCALL changes
  • miva_variable_type()
  • * MivaSQL Additions
    • SELECT COUNT( DISTINCT column )
    • UPDATE now support JOINs
    • DELETE now support JOINs
    • Added IFNULL function
    • Added RECNO virtual column
  • V 5.27
  • x509_load_mem()
  • x509_get_subject_name()
  • x509_get_issuer_name()
  • x509_get_extensions()
  • x509_digest()
  • x509_pubkey_digest()
  • crypto_evp_encrypt_auth()
  • pkcs7_load_mem()
  • pkcs7_get_certs()
  • pkcs7_get_signer_info()
  • pkcs7_verify()
  • pkcs7_free()
  • evp_pkey_load_mem()
  • evp_pkey_load_pubkey_mem()
  • evp_pkey_derive()
  • V 5.26 -- Fixed indexofl(), indexofli()
  • V 5.25 -- Minor fixes
  • V 5.24
  • miva_setprocessname()
  • miva_async_sleep()
  • miva_csv_encode()
  • miva_html_strip()
  • miva_cdata_encode()
  • file_touch()
  • miva_struct_merge_ref()
  • indexofl()
  • indexofli()
  • miva_array_filter()
  • miva_array_filter_ref()
  • miva_ieee754_normalize()
  • rsa_load_publickey_engine()
  • rsa_load_privatekey_engine()
  • crypto_rand_set_rand_engine()
  • MvASYNCHRONOUS new tag
  • MvCALL changes
  • MvINCLUDE changes
  • New API Functions
  • PostgreSQL connector available
  • FastCGI available
  • V 5.23
  • MacOS X Support
  • slugify()
  • miva_splitstring()
  • fssymlink()
  • sfsymlink()
  • New in StoreMorph
    &mvts:varname; slugify encoded
  • New API Functions
  • V 5.22 -- Minor fixes
  • V 5.21
  • encodejavascriptstring()
  • miva_json_decode()
  • miva_json_decode_last_error()
  • New in StoreMorph
    mvt:call
    mvt:callcontinue
    mvt:callstop
    mvt:do
    &mvtj:varname; json encoded
  • New API Functions
  • V 5.20
  • MvCALL uses HTTP/1.1
  • MivaSQL Added
    LENGTH() & BETWEEN
  • New in StoreMorph
    backslash in expressions
    mvt:foreachcontinue
    mvt:foreachstop
    mvt:whilecontinue
    mvt:whilestop
  • New API Functions
  • V 5.19 -- Minor fixes
  • V 5.18
  • diagtool.mvc executable -- debugging tool
  • new POST content type support
  • New in StoreMorph
    mvt:assign
    mvt:while
    mvt:eval
  • MvSMTP new parameters
  • MvASSEMBLY
  • crypto_hmac_md5()
  • miva_array_clear()
  • miva_array_delete()
  • miva_array_merge()
  • miva_array_copy()
  • miva_array_copy_ref()
  • miva_array_insert()
  • miva_array_insert_var()
  • miva_array_insert_ref()
  • miva_array_pop()
  • miva_array_pop_ref()
  • miva_array_shif()
  • miva_array_shift_ref()
  • miva_array_find()
  • miva_array_search()
  • miva_array_binarysearch()
  • V 5.17
  • New Operators. (++) and (--)
  • miva_sleep()
  • miva_hex_encode()
  • miva_hex_decode()
  • crypto_cipher_block_size()
  • crypto_cipher_key_length()
  • crypto_cipher_iv_length()
  • crypto_cipher_mode()
  • crypto_evp_encrypt()
  • crypto_evp_decrypt()
  • crypto_digest_block_size()
  • crypto_digest_size()
  • crypto_evp_digest()
  • crypto_evp_hmac()
  • crypto_xor()
  • crypto_pbkdf1()
  • crypto_pbkdf2()
  • rsa_generate_keypair_mem_cipher()
  • rsa_save_privatekey_mem_cipher()
  • V 5.16
  • mvcov executable -- script analysis tool
  • mvprof executable -- script profiling tool
  • V 5.15 -- Minor fixes
  • V 5.14 -- Major fixes
  • MvLOCALIZED
  • MvSMTP
  • MvFOR
  • MvCALL
  • MvDO
  • MvSMTP
  • MvDBCOMMAND
  • Multle Functions fixed
  • V 5.13
  • srandom( seed )
  • MvCall changes
  • V 5.12 -- Minor fixes
  • V 5.11 -- Minor fixes
    64 bit version available
  • V 5.10
  • substring_var()
  • len_var()
  • indexof()
  • indexofi()
  • file_read_bytes()
  • <MvFOREACH>
  • <MvFOR>
  • V 5.09
  • crypto_sha256()
  • crypto_hmac_sha256()
  • V 5.08
  • miva_openlog()
  • miva_closelog()
  • miva_setlogmask()
  • miva_writelog()
  • V 5.07
  • xml_parse_var()
  • xml_parse_set_colon_replacement()
  • miva_struct_members()
  • miva_array_sort()
  • miva_array_min()
  • miva_array_next()
  • miva_array_next()
  • miva_array_previous()
  • miva_template_compile_itemlist()
  • miva_template_compile_dump()

User Annotations:
Miva Merchant : mivascript at, pcinet d0t com
02/03/2011 16:12 p.m.
Users can comment and post examples of their scripts.
<b>Sample script: </b>