-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStmHelper.php
More file actions
68 lines (63 loc) · 1.72 KB
/
StmHelper.php
File metadata and controls
68 lines (63 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
/**
* Class which incapsulates common statements and must be used as
* base class for project DbHelper.
* This cmass must be moved to ADO subsystem.
*/
class StmHelper
{
/**
* Gets SQL statement for selecting item by primary key.
*
* @param DBObject $proto
* @param integer $id
* @return SQLStatementSelect
*/
public static function stmSelectByPrimaryKey($proto, $id )
{
$stm = new SQLStatementSelect( $proto );
$stm->addExpression( new ExprEQ($proto->getPrimaryKeyTag(), $id ));
return $stm;
}
/**
* Gets SQL statement for selecting item by primary key.
*
* @param DBObject $proto
* @param integer $id
* @return SQLStatementDelete
*/
public static function stmDeleteByPrimaryKey($proto, $id )
{
$stm = new SQLStatementDelete( $proto );
$stm->setExpression( new ExprEQ($proto->getPrimaryKeyTag(), $id ));
return $stm;
}
/**
* Gets statamenrt for updating or inserting object to database.
*
* @param DBObject $object object instance for storing.
* @return SQLStatementInsert|SQLStatementUpdate|null
*/
public static function stmSmartUpdate( $object )
{
if ( $object->isNew() ) {
$stm = new SQLStatementInsert( $object );
}
else {
if ( !$object->isChanged()) return null;
$stm = new SQLStatementUpdate($object );
}
return $stm;
}
/**
* Add count field to statement.
*
* @param SQLStatementSelect $stm
* @return SQLStatementSelect
*/
static function stmAddCount(SQLStatementSelect $stm)
{
$stm->addColumn( SQLFunction::count( $stm->object->getPrimaryKeyTag(), "count" ) );
return $stm;
}
}