/ LJCPHPCodeDoc / LJCDataManagerLib / LJCSQLBuilder / CreateSelect


Parameters
$tableName - The table name.
$schemaColumns - The table schema definition columns.
$keyColumns - The where clause key columns.
$propertyNames - The included column property names.
$joins - The Collection of Join objects.

Returns

The Select SQL statement.

Syntax

PHP
public static function CreateSelect(string $tableName
, LJCDbColumns $schemaColumns, ?LJCDbColumns $keyColumns
, array $propertyNames = null, ?LJCJoins $joins = null) : string

Creates a Select SQL statement.

Example

PHP
 $webCommonPath = "c:/inetpub/wwwroot/LJCPHPCommon";
 require_once "$webCommonPath/LJCDataManagerLib.php";
 require_once "$webCommonPath/LJCDBAccessLib.php";
 
 $schemaColumns = new LJCDbColumns();
 $schemaColumns->Add("ID", null, "int");
 $schemaColumns->Add("Name");
 
 $keyColumns = new LJCDbColumns();
 $keyColumns->Add("ID", value:1);
 
 array $propertyNames = [];
 $propertyNames[] = "ID";
 $propertyNames[] = "Name";
 
 $joins = new LJCJoins();
 $join = $joins->Add("JoinTableName");
 $join->JoinOns->Add("FromColumnName", "ToColumnName");
 $join->Columns->Add("JoinColumnName", "PropertyName", "ResultName");
 
 $sql = LJCSQLBuilder::CreateSelect("TableName", $schemaColumns
   , $keyColumns, $propertyNames, $joins);
 
 // $sql =
 // select
 //   TableName.ID,
 //   TableName.Name
 //   JoinTableName.JoinColumnName as ResultName
 // from TableName;
 // left join JoinTableName
 //   on ((TableName.FromColumnName = JoinTableName.ToColumnName))
 // where TableName.ID = 1

Copyright © Lester J. Clark and Contributors.
Licensed under the MIT License.