예제 #1
0
파일: set.php 프로젝트: rupertchen/cmatic
         foreach ($record as $fieldApiName => $value) {
             if ($fieldApiName == 'id') {
                 $recordId = strval($value);
                 continue;
             }
             $tmpField = CmaticSchema::getFieldDbColumn($typeApiName, $fieldApiName);
             if (is_null($tmpField)) {
                 throw new CmaticApiException(sprintf('Record %d: Unrecognized field on type: %s.%s', $index, $typeApiName, $fieldApiName));
             }
             if (is_null($value)) {
                 $tmpValue = 'NULL';
             } else {
                 if (is_int($value) || is_float($value)) {
                     $tmpValue = $value;
                 } else {
                     $tmpValue = '\'' . TextUtils::cleanTextForSql($value) . '\'';
                 }
             }
             if (is_null($tmpValue)) {
                 throw new CmaticApiException(sprintf('Record %d: Invalid value for %s.%s: $s', $index, $typeApiName, $fieldApiName, $value));
             }
             $setClause[] = sprintf('%s = %s', $tmpField, $tmpValue);
         }
         // TODO: Move last_mod into triggers?
         $conn->query(sprintf('update %s set last_mod = now(), %s where %s=%s', $typeDbTable, implode(',', $setClause), CmaticSchema::getFieldDbColumn($typeApiName, 'id'), $recordId));
     }
 } else {
     if ($op == 'delete') {
         // Disable deletes it's too scary to allow
         // TODO: There needs to be some checks to make sure not just anything can be deleted.
         // Specifically, we should NEVER be able to delete scoring rows if they have scores.
예제 #2
0
 private function _formatValue($v)
 {
     if (is_int($v)) {
         return $v;
     } else {
         if (is_float($v)) {
             return $v;
         } else {
             return sprintf("'%s'", TextUtils::cleanTextForSql($v));
         }
     }
 }