我的代码生成器生成的样本代码(PHP)
Code
<?php
class UserDataBase
{
public static function insert($instance)
{
$pdo = new PDO(AppVariable::getODBC(), AppVariable::getDataBaseUserID(), AppVariable::getDataBasePassword());
$statement = $pdo->prepare
("
DECLARE @return_value int
DECLARE @UserID int
EXEC @return_value = User_Insert
@AccountBalance = '".$instance->getAccountBalance()."',
@IsAdmin = '".$instance->getIsAdmin()."',
@UserName = '".$instance->getUserName()."',
@UserID = @UserID OUTPUT
SELECT @UserID as 'UserID'
SELECT 'ReturnValue' = @return_value
");
$statement->execute();
if($row = $statement->fetch())
{
if((int)$row["ReturnValue"]!=0)
{
throw new Exception("Errors happened when executing the stored procedure");
}
}
$statement->nextRowset();
if($row = $statement->fetch())
{
if((int)$row["ReturnValue"]!=0)
{
throw new Exception("Errors happened when executing the stored procedure");
}
$instance->setUserID($row["UserID"]);
}
$statement->nextRowset();
if($row = $statement->fetch())
{
if((int)$row["ReturnValue"]!=0)
{
throw new Exception("Errors happened when executing the stored procedure");
}
}
unset($statement);
unset($pdo);
}
public static function select($instance)
{
$pdo = new PDO(AppVariable::getODBC(), AppVariable::getDataBaseUserID(), AppVariable::getDataBasePassword());
$statement = $pdo->prepare
("
DECLARE @return_value int
EXEC @return_value = User_Select
@UserID = '".$instance->getUserID()."'
SELECT 'ReturnValue' = @return_value
");
$statement->execute();
if($row = $statement->fetch())
{
if((int)$row["ReturnValue"]!=0)
{
throw new Exception("Errors happened when executing the stored procedure");
}
$instance->setAccountBalance($row["AccountBalance"]);
$instance->setIsAdmin($row["IsAdmin"]);
$instance->setUserName($row["UserName"]);
}
$statement->nextRowset();
if($row = $statement->fetch())
{
if((int)$row["ReturnValue"]!=0)
{
throw new Exception("Errors happened when executing the stored procedure");
}
}
unset($statement);
unset($pdo);
}
public static function update($instance)
{
$pdo = new PDO(AppVariable::getODBC(), AppVariable::getDataBaseUserID(), AppVariable::getDataBasePassword());
$statement = $pdo->prepare
("
DECLARE @return_value int
EXEC @return_value = User_Update
@UserID = '".$instance->getUserID()."',
@AccountBalance = '".$instance->getAccountBalance()."',
@IsAdmin = '".$instance->getIsAdmin()."',
@UserName = '".$instance->getUserName()."'
SELECT 'ReturnValue' = @return_value
");
$statement->execute();
if($row = $statement->fetch())
{
if((int)$row["ReturnValue"]!=0)
{
throw new Exception("Errors happened when executing the stored procedure");
}
}
$statement->nextRowset();
if($row = $statement->fetch())
{
if((int)$row["ReturnValue"]!=0)
{
throw new Exception("Errors happened when executing the stored procedure");
}
}
unset($statement);
unset($pdo);
}
public static function delete($instance)
{
$pdo = new PDO(AppVariable::getODBC(), AppVariable::getDataBaseUserID(), AppVariable::getDataBasePassword());
$statement = $pdo->prepare
("
DECLARE @return_value int
EXEC @return_value = User_Delete
@UserID = '".$instance->getUserID()."'
SELECT 'ReturnValue' = @return_value
");
$statement->execute();
if($row = $statement->fetch())
{
if((int)$row["ReturnValue"]!=0)
{
throw new Exception("Errors happened when executing the stored procedure");
}
}
$statement->nextRowset();
if($row = $statement->fetch())
{
if((int)$row["ReturnValue"]!=0)
{
throw new Exception("Errors happened when executing the stored procedure");
}
}
unset($statement);
unset($pdo);
}
}
?>
<?php
class UserDataBase
{
public static function insert($instance)
{
$pdo = new PDO(AppVariable::getODBC(), AppVariable::getDataBaseUserID(), AppVariable::getDataBasePassword());
$statement = $pdo->prepare
("
DECLARE @return_value int
DECLARE @UserID int
EXEC @return_value = User_Insert
@AccountBalance = '".$instance->getAccountBalance()."',
@IsAdmin = '".$instance->getIsAdmin()."',
@UserName = '".$instance->getUserName()."',
@UserID = @UserID OUTPUT
SELECT @UserID as 'UserID'
SELECT 'ReturnValue' = @return_value
");
$statement->execute();
if($row = $statement->fetch())
{
if((int)$row["ReturnValue"]!=0)
{
throw new Exception("Errors happened when executing the stored procedure");
}
}
$statement->nextRowset();
if($row = $statement->fetch())
{
if((int)$row["ReturnValue"]!=0)
{
throw new Exception("Errors happened when executing the stored procedure");
}
$instance->setUserID($row["UserID"]);
}
$statement->nextRowset();
if($row = $statement->fetch())
{
if((int)$row["ReturnValue"]!=0)
{
throw new Exception("Errors happened when executing the stored procedure");
}
}
unset($statement);
unset($pdo);
}
public static function select($instance)
{
$pdo = new PDO(AppVariable::getODBC(), AppVariable::getDataBaseUserID(), AppVariable::getDataBasePassword());
$statement = $pdo->prepare
("
DECLARE @return_value int
EXEC @return_value = User_Select
@UserID = '".$instance->getUserID()."'
SELECT 'ReturnValue' = @return_value
");
$statement->execute();
if($row = $statement->fetch())
{
if((int)$row["ReturnValue"]!=0)
{
throw new Exception("Errors happened when executing the stored procedure");
}
$instance->setAccountBalance($row["AccountBalance"]);
$instance->setIsAdmin($row["IsAdmin"]);
$instance->setUserName($row["UserName"]);
}
$statement->nextRowset();
if($row = $statement->fetch())
{
if((int)$row["ReturnValue"]!=0)
{
throw new Exception("Errors happened when executing the stored procedure");
}
}
unset($statement);
unset($pdo);
}
public static function update($instance)
{
$pdo = new PDO(AppVariable::getODBC(), AppVariable::getDataBaseUserID(), AppVariable::getDataBasePassword());
$statement = $pdo->prepare
("
DECLARE @return_value int
EXEC @return_value = User_Update
@UserID = '".$instance->getUserID()."',
@AccountBalance = '".$instance->getAccountBalance()."',
@IsAdmin = '".$instance->getIsAdmin()."',
@UserName = '".$instance->getUserName()."'
SELECT 'ReturnValue' = @return_value
");
$statement->execute();
if($row = $statement->fetch())
{
if((int)$row["ReturnValue"]!=0)
{
throw new Exception("Errors happened when executing the stored procedure");
}
}
$statement->nextRowset();
if($row = $statement->fetch())
{
if((int)$row["ReturnValue"]!=0)
{
throw new Exception("Errors happened when executing the stored procedure");
}
}
unset($statement);
unset($pdo);
}
public static function delete($instance)
{
$pdo = new PDO(AppVariable::getODBC(), AppVariable::getDataBaseUserID(), AppVariable::getDataBasePassword());
$statement = $pdo->prepare
("
DECLARE @return_value int
EXEC @return_value = User_Delete
@UserID = '".$instance->getUserID()."'
SELECT 'ReturnValue' = @return_value
");
$statement->execute();
if($row = $statement->fetch())
{
if((int)$row["ReturnValue"]!=0)
{
throw new Exception("Errors happened when executing the stored procedure");
}
}
$statement->nextRowset();
if($row = $statement->fetch())
{
if((int)$row["ReturnValue"]!=0)
{
throw new Exception("Errors happened when executing the stored procedure");
}
}
unset($statement);
unset($pdo);
}
}
?>
Code
<?php
include('UserDataBase.php');
class UserBroker
{
public static function insert($instance)
{
// add business logic here
try
{
UserDataBase::insert($instance);
}
catch(Exception $e)
{
}
}
public static function select($instance)
{
// add business logic here
try
{
UserDataBase::select($instance);
}
catch(Exception $e)
{
}
}
public static function update($instance)
{
// add business logic here
try
{
UserDataBase::update($instance);
}
catch(Exception $e)
{
}
}
public static function delete($instance)
{
// add business logic here
try
{
UserDataBase::delete($instance);
}
catch(Exception $e)
{
}
}
}
?>
<?php
include('UserDataBase.php');
class UserBroker
{
public static function insert($instance)
{
// add business logic here
try
{
UserDataBase::insert($instance);
}
catch(Exception $e)
{
}
}
public static function select($instance)
{
// add business logic here
try
{
UserDataBase::select($instance);
}
catch(Exception $e)
{
}
}
public static function update($instance)
{
// add business logic here
try
{
UserDataBase::update($instance);
}
catch(Exception $e)
{
}
}
public static function delete($instance)
{
// add business logic here
try
{
UserDataBase::delete($instance);
}
catch(Exception $e)
{
}
}
}
?>
Code
<?php
class User
{
private $UserID;
private $AccountBalance;
private $IsAdmin;
private $UserName;
public function getUserID()
{
return $this->UserID;
}
public function setUserID($UserID)
{
$this->UserID = (int)$UserID;
}
public function getAccountBalance()
{
return $this->AccountBalance;
}
public function setAccountBalance($AccountBalance)
{
$this->AccountBalance = (double)$AccountBalance;
}
public function getIsAdmin()
{
return $this->IsAdmin;
}
public function setIsAdmin($IsAdmin)
{
$this->IsAdmin = (bool)$IsAdmin;
}
public function getUserName()
{
return $this->UserName;
}
public function setUserName($UserName)
{
$this->UserName = (string)$UserName;
}
}
?>
<?php
class User
{
private $UserID;
private $AccountBalance;
private $IsAdmin;
private $UserName;
public function getUserID()
{
return $this->UserID;
}
public function setUserID($UserID)
{
$this->UserID = (int)$UserID;
}
public function getAccountBalance()
{
return $this->AccountBalance;
}
public function setAccountBalance($AccountBalance)
{
$this->AccountBalance = (double)$AccountBalance;
}
public function getIsAdmin()
{
return $this->IsAdmin;
}
public function setIsAdmin($IsAdmin)
{
$this->IsAdmin = (bool)$IsAdmin;
}
public function getUserName()
{
return $this->UserName;
}
public function setUserName($UserName)
{
$this->UserName = (string)$UserName;
}
}
?>
Code
<?php
class AppVariable
{
public static function getDataBaseConnectionString()
{
return "xxxx";//add connection string here
}
public static function getODBC()
{
return "odbc:Test";//add odbc connection here
}
public static function getDataBaseName()
{
return "Test";//add database name here
}
public static function getDataBaseUserID()
{
return "Joey";//add user name here
}
public static function getDataBasePassword()
{
return "1234";//add password here
}
}
?>
<?php
class AppVariable
{
public static function getDataBaseConnectionString()
{
return "xxxx";//add connection string here
}
public static function getODBC()
{
return "odbc:Test";//add odbc connection here
}
public static function getDataBaseName()
{
return "Test";//add database name here
}
public static function getDataBaseUserID()
{
return "Joey";//add user name here
}
public static function getDataBasePassword()
{
return "1234";//add password here
}
}
?>