⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 objmod80.ssc

📁 PowerBuilder8.0开发分散式应用所帶的例程
💻 SSC
📖 第 1 页 / 共 5 页
字号:
<!--SCRIPT PSOBJMOD
    import( site.GetRootDocument().location + "/ObjMod80.ssc" );
    session.active = true;
    InitObjects(session);
-->
<!--SCRIPT // {{ SCRIPT()
/**************************************************************************
**		Copyright ?Sybase, Inc. 1998-1999
**						 All Rights reserved.
**
**	Sybase, Inc. ("Sybase") claims copyright in this
**	program and documentation as an unpublished work, versions of
**	which were first licensed on the date indicated in the foregoing
**	notice.  Claim of copyright does not imply waiver of Sybase's
**  other rights.
**
**************************************************************************
*/

/****************************
** PowerSite Object Model 
** for the Dynamo Server
*/

/****************************
** Utility functions
*/

// is the val one of the members of the array
function memberp(array, val) {
    if (array) {
    	for(var i=1;i<=array.length;i++) {
	    	if (array[i] == val) {
 		    	return true;
		    }
        }
	}
	return false;
}

function CreateArray(a,b,c,d,e,f) {
    // There does not seem to be a way to get at a variable argument list
    // length becomes out[0]
	var out;
    if (a) {
    	out.length = 1;
        out[1] = a;
    }
    if (b) {
    	out.length = 2;
        out[2] = b;
    }
    if (c) {
    	out.length = 3;
        out[3] = c;
    }
    if (d) {
    	out.length = 4;
        out[4] = d;
    }
    if (e) {
    	out.length = 5;
        out[5] = e;
    }
	return out;
}
    
// No distinction between a string and a string object in Dynamo
function String(x) {
  return x;
}

/* ****************
**  Definition of the PSDocumentClass 
**
*/

class PSDocumentClass()
{
  function Write(thing) {
    if (null == thing) {
		thing = "";
	}
    document.write(thing);
  };
  function WriteLn(thing) {
    if (null == thing) {
		thing = "";
	}
    document.writeln(thing);
  };

    function doc_Redirect(url)
    {
        document.redirect = url;
    }
    function doc_path()
    {
        var file = psDocument.GetEnv("PATH_INFO");
        var index = file.lastIndexOf("/");
        return file.substring(0,index);
    }
    
    function doc_file()
    {
        var file = psDocument.GetEnv("PATH_INFO");
        var index = file.lastIndexOf("/");
        return file.substring(index+1, file.length);
    }
    
    function doc_site()
    {
        var site = psDocument.GetEnv("SERVER_NAME");
       return site;
    }

  function GetParam( envparam ) {
    for (el in document.value) {
      if (el == envparam) {
        return document.value[envparam];
      }
    }
      return "undefined";
  };
  // this is more efficient and will return null if not found
  function GetParamEx( paramName ) {
  	// check if named parameter exists
	if (exists(document.value[paramName])) {
		// if so, return value
		return document.value[paramName];
	}
	// if not, return null
	return null;
  };

  function GetEnv(envvar) {
    if ('SCRIPT_NAME' == envvar) return document.name;
    return document.GetServerVariable(envvar);
  }

  this.Write = Write;
  this.WriteLn = WriteLn;
  this.Redirect = doc_Redirect;
  this.Path = doc_path;
  this.File = doc_file;
  this.Site = doc_site;
  this.GetEnv = GetEnv;
  this.GetParam = GetParam;
  this.GetParamEx = GetParamEx;
  
};

/* ****************
**  Definition of the PSCursorClass
**
*/

class PSCursorClass(resultSet)
{

  function cursor_Columns() {
    return this.query.GetColumnCount();
  }
  function cursor_GetRowCount()
  {
      var count = this.query.GetRowCount();
    return count;
  }
  function cursor_EOF() {
    return this.eofval;
  }
  function cursor_get(field) {
    var index;
    //  if ("number" == typeof( field)) {
    if ((field + 1) == 1 + field) {
      index = field + 1;
    } else {
      index = this.query.GetColumnIndex(field);
    }
    return this.query.GetValue(index);
  }
  function cursor_movenext() {
    this.eofval = !this.query.MoveNext();
    return this.eofval;
  }
  function cursor_moveprev() {
    this.eofval = !this.query.MovePrevious();
    return this.eofval;
  }
  function cursor_movelast() {
    this.eofval = !this.query.MoveLast();
    return this.eofval;
  }
  function cursor_movefirst() {
    this.eofval = !this.query.MoveFirst();
    return this.eofval;
  }
  function cursor_move(rec) {
      // Our model is zero-based
    this.eofval = !this.query.Move(rec+1);
    return this.eofval;
  }

  this.eofval = false;
  this.EOF = cursor_EOF;
  this.GetValue = cursor_get;  
  this.MoveNext = cursor_movenext;
  this.MovePrevious = cursor_moveprev;
  this.MoveLast = cursor_movelast;
  this.MoveFirst = cursor_movefirst;
  this.Move = cursor_move;
  this.GetRowCount = cursor_GetRowCount;

  this.query = resultSet;
  this.eofval = !this.query.MoveNext();
  this.GetColumnCount = cursor_Columns;
}

/* ****************
**  Definition of the PSCommandClass
**
** The command object is a wrapper around an sqlexpression.  The results of the query 
** can be accessed from the cursor object returned from the execute method
*/

class PSCommandClass(query, conn)
{
    function Execute() {
		this.conn.ClearError();
        var dyncur = this.conn.dynConn.CreateQuery(this.sql);
    	if (null == dyncur) {
	    	this.AddError(new PSErrorClass(this.conn.dynConn.GetErrorCode(), this.conn.dynConn.GetErrorInfo()));
		    return null;
	    }
		if (0 != dyncur.GetErrorCode()) {
			this.conn.AddError(new PSErrorClass(dyncur.GetErrorCode(), dyncur.GetErrorInfo()));
			return null;
			}
		return new PSCursorClass(dyncur);
    }
    function SetSQL(query) {
        this.sql = query;
        return true;
    }
	this.sql = query;
    this.conn = conn;
    this.Execute = Execute;
    this.SetSQL = SetSQL;
}

/* ****************
**  Definition of the connection object
**
*/

class PSConnectionClass(name)
{
  function CreateCommand(sql) {
    return new PSCommandClass(sql, this);
  }
  function CreateCursor(sql) {
	this.ClearError();
	var dyncur = this.dynConn.CreateQuery(sql);
	if (null == dyncur) {
		this.AddError(new PSErrorClass(this.dynConn.GetErrorCode(), this.dynConn.GetErrorInfo()));
		return null;
	}
	if (0 != dyncur.GetErrorCode()) {
		this.AddError(new PSErrorClass(dyncur.GetErrorCode(), dyncur.GetErrorInfo()));
		return null;
	}
//    psDocument.Write("cur:" + dyncur+":cur")
    return new PSCursorClass(dyncur);
  }
  function GetError() {
      return this.errorObj;
  }
  function AddError(err) {
	err.nextError = this.errorObj;
	this.errorObj = err;
	return err;
  }
  function ClearError() {
	this.errorObj = null;
  }
// External Methods
  this.CreateCommand = CreateCommand;
  this.CreateCursor = CreateCursor;
  this.GetError = GetError;
  this.AddError = AddError;
  this.ClearError = ClearError;
  
  this.errorObj = null;
  this.dynConn = site.GetConnection(name);
//  document.write(this.dynConn);
  // defaults to the current connection
  if (null == this.dynConn) {
    this.dynConn = connection;
    this.AddError( new PSErrorClass( 1000, "Connection not found - using default"));
    return;
  }
  this.dynConn.simulateCursors = true;
}

class PSNewConnectionClass(ConnectionString, user, password) 
	extends PSConnectionClass("<default>")
{
    // Extract the Data set name from the connection string
	var dsn;
    var dsn_index = ConnectionString.indexOf("DSN=");
	if (-1 != dsn_index) {
		var dsn = ConnectionString.substring(dsn_index+4, ConnectionString.length);
		dsn_index = dsn.indexOf(";");
		if ( -1 != dsn_index) {
			dsn = dsn.substring(0,dsn_index);
			// psDocument.Write(dsn);
		}
	} else {
		dsn = "";
	}
    //    See if the Connection already exists
    var connName = "Temp" +dsn+user;
    this.dynConn = new Connection(connName,"Temporary Connection",dsn, user, password, "ODBC")

	if (null == this.dynConn) {
		this.AddError( new PSErrorClass( 8001, "Unable to Connect to DataSource"));
		return;
	}
    this.dynConn.simulateCursors = true;
}

/*******************
** Definition of the session object
*/
// Just try attaching the methods

function sess_Getvalue(prop) {
//    Doc.write("In:GetValue:" + prop);
    if exists(this[prop]) {
        return this[prop];
    }
    return null;
}
function sess_Setvalue(prop, value) {
//    Doc.write("In:SetValue:" + prop+ "="+ value);
     this[prop] = value;
     return value;
}

function sess_Abandon() {
    this.timeOut = 1;
    return;
}

/***********************
** Defnition of the PSServerClass
*/
class PSServerClass
{
    function CreateObject(name) {
        return "unimplemented";
    }
    function GetConnection(name) {
        return new PSConnectionClass(name);
    }
    function NewConnection(connStr, user, password) {
        return new PSNewConnectionClass( connStr, user, password);
    }
    function URLEncode(str) {
        return escape(str);
    }
    function Type() {
        var software = document.GetServerVariable("SERVER_SOFTWARE");
        var index = software.indexOf('/');
        return software.substring(0, index);
    }
    function Version() {
        var software = document.GetServerVariable("SERVER_SOFTWARE");
        var index = software.indexOf('/');
        return software.substring( index+1, software.length);
    }
	function ObjModType() {
		return "Dynamo";
	}
	function ObjModVersion() {
		return 1.0;
	}
	function ActiveExtension(oldExt) {
		return oldExt;
	}

    this.CreateObject = CreateObject;
    this.GetConnection = GetConnection;
    this.CreateConnection = NewConnection;
    this.URLEncode = URLEncode;
    this.Type = Type;
    this.Version = Version;
    this.ObjectModelType = ObjModType;
    this.ObjectModelVersion = ObjModVersion;
	this.ActiveExtension = ActiveExtension;
}

/***********************
** Defnition of the PSErrorClass
*/
class PSErrorClass(code, info)
{
	function GetCode() {
		return this.code;
	}
	function GetMessage() {
		return this.info;
	}
	function GetNextError() {
		return this.nextError;
	}
	this.code = code;
	this.info = info;
	this.nextError = null;

	this.GetCode = GetCode;
	this.GetMessage = GetMessage;
	this.GetNextError = GetNextError;
}

function psRemoveDots(inString) {
	var result;
	var index;

	result = inString;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -