How to access a database from Yate's Javascript module

From Yate Documentation
(Difference between revisions)
Jump to: navigation, search
(Created page with "=== DB Example=== This example uses Javascript to retrieve information from DB // '''Get DB Object''' var m = new Message("database"); // '''Specify connection to use'''...")
 

Revision as of 12:08, 19 March 2013

DB Example

This example uses Javascript to retrieve information from DB

// Get DB Object
var m = new Message("database");
// Specify connection to use
m.account = "yateadmin";
// Define Query
m.query = "SELECT * FROM lines WHERE location IS NOT NULL ORDER BY line LIMIT 5";
// Run the Query
if (m.dispatch()) {
    if (m.rows > 0) {
        Engine.output("Got " + m.rows + " records of " + m.columns + " fields");
        Engine.output("result[0,0] = " + m.getResult(0,0));
        var res = m.getColumn("location");
        for (var i = 0; i < res.length; i++) {
            Engine.output("location[" + i + "] = " + res[i]);
        }
    }
}
else {
    Engine.output("Query failed");
}
Personal tools
Namespaces

Variants
Actions
Preface
Configuration
Administrators
Developers