Search these areas:
Help
Support Forums
Product Info



-Introduction
-DataWeb: What's New
-Creating an Application
-The DataWeb Designer
-Application Management
-Data Tables
-Data Tables
-Views
-Templates
-Components
-Data Analysis
-Members
-Security
-Importing
-Exporting
-FTP
-JavaScript
-Object Model
-Full-Text Search
-Domain and Email Hosting
-HotBlock Modules
-Account Management
-Glossary
-New Responsive UI Module





DataWeb Help
Support Forums
Tutorial
Script Library
Knowledge Base

Home > Support

Script Library

  Simple Property Manager
 
  chubbard posted this script:
  These two scripts enable simple property persitance with name-value pairs.  They rely on a table named Settings with two fields, PropName (text) and PropData (text).  They are run with staff permissions because users generally don't have direct access to the Settings table. 

// Sets a property in the settings table, creates it if doesn't already exist
//
public asStaff function setProp(InPropName, InPropData)

{
  var rs = table.select("Settings", "*", {PropName:InPropName});
  if (rs.next() == true)
    {
    table.update("Settings", {PropData:InPropData}, rs.RowID);
    } else {
    table.insert("Settings", {PropName:InPropName, PropData:InPropData});
    }
}


// Gets the value of a property from the settings table
// returns null if property doesn't exist
//
public asStaff function getProp(InPropName)
{
  var rs = table.select("Settings", "*", {PropName:InPropName});
  if (rs.next() == true)
    {   
    return rs.PropData;
    } else  {
    return null;
    }
}

Example:
// initialize a PageCounter property to 0
setProp("PageCounter", "0");

// in a view, increment and display the new page counter

var util = classes.import("myscripts.ws");  // import the script library with the prop mgr
util.setProp("PageCounter", (number(getProp("PageCounter")) + 1)); 
response.write("Page Views: " + util.getProp("PageCounter"));
 
  on 2001-03-28 05:45:35, chubbard responded:
  This is cool - one of those tools you didn't realize you needed until you saw it.  I'm off to remove a bunch of hard coded constants from my web...  
Affiliate | Partner | Terms of Use | Privacy Policy | Contact Us | Pricing | Bring DataWeb In-House    
DataWeb, 720 North 10th Street, A #145, Renton, Washington 98057 *425-583-5970* Fax 484-770-4706* Email Us