データの生成を行います。

@param	string	$table_name	生成先テーブル名
@param	array	$values		値
@param	array	$options	オプション
966144
public function create ($table_name, array $values = [], array $options = []) {
		if (isset($options['create_filter']) && is_callable($options['create_filter'])) {
			$values = $options['create_filter']($values);
		}

		$columns = $this->getColumns($table_name);

		$column_name_list = array_keys($values[0]);
		$query = sprintf(
			'INSERT INTO %s (%s%s%s) VALUES (%s)',
			$table_name,
			static::IDENTIFIER,
			implode(static::IDENTIFIER.', '.static::IDENTIFIER, $column_name_list),
			static::IDENTIFIER,
			implode(', ', array_fill(0, count($column_name_list), '?'))
		);

		$ret = [];

//@TODO mode setting
		$log_flag = false;
		$execute_time = microtime(true);
		try {
			$stmt = $this->prepare($query);
			foreach ($values as $value) {
				$i = 1;
				foreach ($value as $column_name => $column_value) {
					$stmt->bindValue($i++, $column_value, $columns[$column_name]['pdo_param']);
				}
				if (!$stmt->execute()) {
					//@TODO mode setting
					if ($log_flag) {
						$execute_end_time = microtime(true);

						$parsed_execute_time = explode('.', $execute_time);

						$debug_dump_params = '';
						if ($log_flag) {
							ob_start();
							$stmt->debugDumpParams();
							$debug_dump_params = ob_get_clean();
						}

						$query_string = $stmt->queryString;

						$message = sprintf('[%s.%-4d] execute_time:%s query_string:%s dump:%s', date('Y-m-d H:i:s', $parsed_execute_time[0]), $parsed_execute_time[1], $execute_end_time - $execute_time, $query_string, $debug_dump_params);
						//				StaticLog::WriteLog('sql_log', $message);
						print $message;
					}
				}
				$ret[] = $this->lastInsertId();
			}
		} catch (\PDOException $pdo_e) {
			$execute_end_time = microtime(true);

			$parsed_execute_time = explode('.', $execute_time);

			$error_info = $stmt->errorInfo();

			//@TODO mode setting
			$debug_dump_params = '';
			if ($log_flag) {
				ob_start();
				$stmt->debugDumpParams();
				$debug_dump_params = ob_get_clean();
			}
			$query_string = $stmt->queryString;

			$message = sprintf(
					'[%s.%-4d] execute_time:%s SQLSTATE:%s code:%s message:%s query_string:%s dump:%s',
					date('Y-m-d H:i:s', $parsed_execute_time[0]),
					$parsed_execute_time[1],
					$execute_end_time - $execute_time,
					$error_info[0],
					$error_info[1],
					$error_info[2],
					$query_string,
					$debug_dump_params
			);
//print $message;
			StaticLog::WriteLog('sql_error', $message);

			throw $pdo_e;
		}

		return $ret;
	}
13436
public static function ExistTable (array $options, $table_name, $forced_obtain = false) {
		$tables = static::GetConnection($options)->getTables($forced_obtain);
		return isset($tables[$table_name]);
	}
313778
public static function GetColumns(array $options, $table_name, $forced_obtain = false) {
		return static::GetConnection($options)->getColumns($table_name, $forced_obtain);
	}
674088
public function table($table_name)
    {
        $table_name = trim($table_name);

        if (is_null($table_name)) {
            $this->throwFailsCommand('Specify the seeder table name', 'help seed');
        }

        if (!file_exists($this->setting->getSeederDirectory()."/{$table_name}_seeder.php")) {
            echo Color::red("Seeder $table_name not exists.");

            exit(1);
        }

        $this->make([
            $this->setting->getSeederDirectory()."/{$table_name}_seeder.php"
        ]);
    }
384936
public static function StaticMethodCache ($method_name, $arguments = [], $options = []) {
		//======================================================
		//初期化
		//======================================================
		//実行中のクラス名の特定
		$current_class = static::class;

		//引数の正規化
		$arguments === null ? $arguments = [] : $arguments = (array) $arguments;

		//クラス名＋メソッド名によるキャッシュキー
		$static_cache_key = hash('sha256', serialize([$current_class, $method_name]));

		//引数によるキャッシュキー
		$arg_cache_key = hash('sha256', serialize($arguments));

		//もしもoptionsが文字列の場合、iniファイルによる設定と推定する
		!is_string($options) ?: $options = ['ini' => $options];

		//実装時設定と併用するため、optionでの指定も可能にする
		if (isset($options['ini'])) {
			$ini_path = $options['ini'];
			clearstatcache(true, $ini_path);
			if (!file_exists($ini_path)) {
				throw CoreException::RaiseSystemError('設定ファイルが見つかりません。ini path:%s', [$ini_path]);
			}
			$optinos = IniFile::GetConfig($ini_path, ['type', 'limit', 'cache_dir', 'cache_dir_permission']);
		}

		//キャッシュタイプの特定
		isset($options['type']) ?: $options['type'] = 'on_request';
		$type_key = $options['type'];

		//キャッシュライフタイムの確定
		$limit = isset($options['limit']) ? $options['limit'] : 30;
		$limit = (int) ($limit * 1000000);

		//キャッシュクリアモードの確定
		$clear = isset($options['clear']) && $options['clear'];

		//強制再取得モードの確定
		$obtain = isset($options['obtain']) && $options['obtain'];

		//======================================================
		//実処理
		//======================================================
		//キャッシュクリアが有効な場合、または強制再取得モードの場合、オンリクエストキャッシュを破棄する。（全タイプ共通）
		if (($clear || $obtain) && isset(static::$_StaticMethodCacheTrait_CacheList[$static_cache_key][$arg_cache_key])) {
			unset(static::$_StaticMethodCacheTrait_CacheList[$static_cache_key][$arg_cache_key]);
		}

		//強制再取得モードではなく、キャッシュが既に存在していて、キャッシュライフタイムが制限を超えていない場合、キャッシュを返す
		if ($obtain === false && isset(static::$_StaticMethodCacheTrait_CacheList[$static_cache_key][$arg_cache_key][$type_key]['create_microtime']) && static::$_StaticMethodCacheTrait_CacheList[$static_cache_key][$arg_cache_key][$type_key]['create_microtime'] + $limit > microtime(true)) {
			return static::$_StaticMethodCacheTrait_CacheList[$static_cache_key][$arg_cache_key][$type_key]['cache'];
		}

		//タイプ別の処理
		$cache_method_name = sprintf('StaticMethodCacheBy%s', str_replace(' ', '', ucwords(str_replace('_', ' ', $type_key))));
		return static::$cache_method_name($current_class, $method_name, $arguments, $static_cache_key, $arg_cache_key, $type_key, $limit, $options);
	}
115565
public function update($table, $data, $keys, $options = []) {
		return $this->object->update($table, $data, $keys, $options);
	}
343035
public function createTable($name, callable $callback, $ifNotExists = true, $options = [])
    {
        $options = $this->prepareBCOptions($options);

        return $this->getTable($name)->create($callback, $ifNotExists, $options);
    }
660928
public function select(String $name = NULL, Array $options = [], $selected = NULL, Array $_attributes = [], Bool $multiple = false)
    {
        $this->isTableOrQueryData($options);

        $this->setOptionAttribute($options);

        $this->isExcludeAttribute($options);

        $this->isIncludeAttribute($options);

        $this->isOrderAttribute($options);

        $this->setSelectedAttribute($selected, $options);

        $this->setMultipleAttribute($multiple, $_attributes);

        $this->setNameAttributeWithReference($name, $_attributes);

        if( ! empty($_attributes['name']) )
        {
            $this->_postback($_attributes['name'], $selected);

            # 5.8.2.8[added]
            $this->getVMethodMessages();

            # 5.4.2[added]
            $this->_validate($_attributes['name'], $_attributes['name']);
            
            # 5.4.2[added]|5.4.5|5.4.6[edited]
            $selected = $this->_getrow('select', $selected, $_attributes);
        }

        $this->commonMethodsForInputElements('select');

        $this->getPermAttribute($perm);

        $this->createSelectElement($options, $selected, $_attributes, $return);

        $this->createBootstrapFormInputElementByType('select', $return, $_attributes, $return);

        $this->_unsetselect();

        $this->outputElement .= $this->_perm($perm, $return);

        return $this;
    }
130805
public static function Save ($values = [], $options = []) {
		if (!static::InTransaction()) {
			throw CoreException::RaiseSystemError('トランザクションが展開されていません。');
		}
		$options += $options + static::GetDefaultOptions();
		return DBI::Save(static::GetName(), static::DefaultSaveFilter($values), $options);
	}
273579
public static function GetNotNullColumns (array $options, $table_name, $forced_obtain = false) {
		return static::GetConnection($options)->getNotNullColumns($table_name, $forced_obtain);
	}
934614
public function render(TableView $table, array $options = [])
    {
        $options = array_merge($this->defaults, $options);

        $template = $options['template'];
        if ($template instanceof \Twig_TemplateWrapper) {
            $this->template = $template;
        } else {
            $this->template = $this->environment->load($template);
        }

        return $this->template->renderBlock('table', ['table' => $table, 'options' => $options]);
    }
981967
public function delete($table, $options = array())
    {
        $query_string = 'DELETE FROM `' . $this->pref . $table . '`' . $this->opt($options);

        try {
            $stmt = $this->doQuery($query_string);
            return $stmt->rowCount();
        } catch (\Exception $e) {
            print_r($e->getMessage());
            return false;
        }
    }
1192433
public function transAlterTable($table, $options, $advanced_options)
    {
        $this->transInitTable($table);
        $this->schemaUpdateTransaction[$table]['alteredOptions'] = $options;
        $this->schemaUpdateTransaction[$table]['advancedOptions'] = $advanced_options;
    }
464685
public function executeQuery ($query, array $conditions = [], array $values = [], array $options = []) {
		//==============================================
		//IN句構築
		//==============================================
		$in_list = [];
		foreach ($conditions as $condition) {
			$column_value = current((array) $condition);
			if (is_array($column_value)) {
				$in_list[] = implode(', ', array_fill(0, count($column_value), '?'));
			}
		}

		if (!empty($in_list)) {
			$query = vsprintf($query, $in_list);
		}

		//==============================================
		//ステートメント構築
		//==============================================
		$stmt = $this->prepare($query);

		//もしもフェッチモード指定があった場合は設定
		if (isset($options[\PDO::ATTR_DEFAULT_FETCH_MODE])) {
			switch ($options[\PDO::ATTR_DEFAULT_FETCH_MODE]) {
				case \PDO::FETCH_LAZY:
				case \PDO::FETCH_ASSOC:
				case \PDO::FETCH_NAMED:
				case \PDO::FETCH_NUM:
				case \PDO::FETCH_BOTH:
				case \PDO::FETCH_OBJ:
				case \PDO::FETCH_BOUND:
				case \PDO::FETCH_FUNC:
				case \PDO::FETCH_GROUP:
				case \PDO::FETCH_UNIQUE:
				case \PDO::FETCH_KEY_PAIR:
				case \PDO::FETCH_CLASSTYPE:
				case \PDO::FETCH_SERIALIZE:
				case \PDO::FETCH_PROPS_LATE:
				case \PDO::FETCH_ORI_NEXT:
				case \PDO::FETCH_ORI_PRIOR:
				case \PDO::FETCH_ORI_FIRST:
				case \PDO::FETCH_ORI_LAST:
				case \PDO::FETCH_ORI_ABS:
				case \PDO::FETCH_ORI_REL:
					$stmt->setFetchMode($options[\PDO::ATTR_DEFAULT_FETCH_MODE]);
					break;
				case \PDO::FETCH_COLUMN:
					$stmt->setFetchMode($options[\PDO::ATTR_DEFAULT_FETCH_MODE], isset($options['colno']) ? $options['colno'] : 0);
					break;
				case \PDO::FETCH_CLASS:
					$stmt->setFetchMode($options[\PDO::ATTR_DEFAULT_FETCH_MODE], isset($options['classname']) ? $options['classname'] : null, isset($options['ctorargs']) ? $options['ctorargs'] : null);
					break;
				case \PDO::FETCH_INTO:
					$stmt->setFetchMode($options[\PDO::ATTR_DEFAULT_FETCH_MODE], isset($options['object']) ? $options['object'] : null);
					break;
			}
		}

		//==============================================
		//パラメータバインディング開始
		//==============================================
		//位置情報
		$i = 1;
/*
		//テーブル名取得
		$table_name = $options['table_name'] ?? null;

		//カラム情報
		$columns = $this->getColumns($table_name);

		//\PDO::PARAM_*リスト
		$pdo_param_list = static::GetPdoParamList();
*/
		//Update時のValueから先行してバインディングする
		foreach ($values as $column_name => $value) {
//			$stmt->bindValue($i++, $value, $pdo_param_list[$columns[$column_name]['Type']]);
			$stmt->bindValue($i++, $value);
		}

		//WHERE句以降のバインディング
		foreach ($conditions as $idx => $condition) {
			$condition = (array) $condition;
			$column_name = key($condition);
			$column_value = current($condition);

			if (is_array($column_value)) {
				foreach ($column_value as $value) {
					$stmt->bindValue($i++, $value);
				}
			} else {
				$stmt->bindValue($i++, $column_value);
			}
		}

		//==============================================
		//クエリ実行
		//==============================================
		try {
//@TODO mode setting
			$log_flag = false;
			if ($log_flag) {
				$execute_time = microtime(true);
			}

			$stmt->execute();
//@TODO mode setting
			if ($log_flag) {
				$execute_end_time = microtime(true);

				$parsed_execute_time = explode('.', $execute_time);

				$debug_dump_params = '';
				if ($log_flag) {
					ob_start();
					$stmt->debugDumpParams();
					$debug_dump_params = ob_get_clean();
				}

				$query_string = $stmt->queryString;

				$message = sprintf('[%s.%-4d] execute_time:%s query_string:%s dump:%s', date('Y-m-d H:i:s', $parsed_execute_time[0]), $parsed_execute_time[1], $execute_end_time - $execute_time, $query_string, $debug_dump_params);
//				StaticLog::WriteLog('sql_log', $message);
				print $message;
			}
		} catch (\PDOException $pdo_e) {
			$execute_end_time = microtime(true);

			$parsed_execute_time = explode('.', $execute_time);

			$error_info = $stmt->errorInfo();

//@TODO mode setting
			$debug_dump_params = '';
			if ($log_flag) {
				ob_start();
				$stmt->debugDumpParams();
				$debug_dump_params = ob_get_clean();
			}
			$query_string = $stmt->queryString;

			$message = sprintf(
					'[%s.%-4d] execute_time:%s SQLSTATE:%s code:%s message:%s query_string:%s dump:%s',
					date('Y-m-d H:i:s', $parsed_execute_time[0]),
					$parsed_execute_time[1],
					$execute_end_time - $execute_time,
					$error_info[0],
					$error_info[1],
					$error_info[2],
					$query_string,
					$debug_dump_params
			);

			StaticLog::WriteLog('sql_error', $message);

			throw $pdo_e;
		}

		//==============================================
		//処理の終了：PDOStatementクラスはTraversableを実装しているため、そのまま返してもforeachで利用できる。
		//==============================================
		return $stmt;
	}
587223
public static function validateSingleColumn(string $column_name, array $column_options, $value, array $options = []) : array {
		$result = [
			'success' => false,
			'error' => [],
			'data' => null
		];
		// perform validation
		$result['data'] = self::processSingleColumnType($column_name, $column_options, $value, ['process_datetime' => true]);
		if (array_key_exists($column_name, $result['data'])) {
			// validations
			$error = false;
			// perform validation
			if ($column_options['type'] == 'boolean') {
				if (!empty($value) && ($value . '' != $result['data'][$column_name] . '')) {
					$result['error'][] = i18n(null, 'Wrong boolean value!');
					$error = true;
				}
			} else if (in_array($column_options['type'], ['date', 'time', 'datetime', 'timestamp'])) { // dates first
				if (!empty($value) && empty($result['data'][$column_name . '_strtotime_value'])) {
					$result['error'][] = i18n(null, 'Invalid date, time or datetime!');
					$error = true;
				}
			} else if ($column_options['php_type'] == 'integer') {
				if ($value . '' !== '' && !\Format::readIntval($value, ['valid_check' => 1])) {
					$result['error'][] = i18n(null, 'Wrong integer value!');
					$error = true;
				}
				// null processing
				if (!$error) {
					if (empty($result['data'][$column_name]) && !empty($column_options['null'])) {
						$result['data'][$column_name] = null;
					}
				}
			} else if ($column_options['php_type'] == 'bcnumeric') { // accounting numbers
				if ($value . '' !== '' && !\Format::readBcnumeric($value, ['valid_check' => 1])) {
					$result['error'][] = i18n(null, 'Wrong numeric value!');
					$error = true;
				}
				// precision & scale validations
				if (!$error) {
					// validate scale
					$digits = explode('.', $result['data'][$column_name] . '');
					if (!empty($column_options['scale'])) {
						if (!empty($digits[1]) && strlen($digits[1]) > $column_options['scale']) {
							$result['error'][] = i18n(null, 'Only [digits] fraction digits allowed!', ['replace' => ['[digits]' => i18n(null, $column_options['scale'])]]);
							$error = true;
						}
					}
					// validate precision
					if (!empty($column_options['precision'])) {
						$precision = $column_options['precision'] - $column_options['scale'] ?? 0;
						if (strlen($digits[0]) > $precision) {
							$result['error'][] = i18n(null, 'Only [digits] digits allowed!', ['replace' => ['[digits]' => i18n(null, $precision)]]);
							$error = true;
						}
					}
				}
			} else if ($column_options['php_type'] == 'float') { // regular floats
				if ($value . '' !== '' && !\Format::readFloatval($value, ['valid_check' => 1])) {
					$result['error'][] = i18n(null, 'Wrong float value!');
					$error = true;
				}
				// null processing
				if (!$error) {
					if (empty($result['data'][$column_name]) && !empty($column_options['null'])) {
						$result['data'][$column_name] = null;
					}
				}
			} else if ($column_options['php_type'] == 'string') {
				// we need to convert empty string to null
				if ($result['data'][$column_name] . '' === '' && !empty($column_options['null'])) {
					$result['data'][$column_name] = null;
				}
				// validate string length
				if ($result['data'][$column_name] . '' !== '') {
					// validate length
					if (!empty($column_options['type']) && $column_options['type'] == 'char' && strlen($result['data'][$column_name]) != $column_options['length']) {  // char
						$result['error'][] = i18n(null, 'The length must be [length] characters!', ['replace' => ['[length]' => i18n(null, $column_options['length'])]]);
						$error = true;
					} else if (!empty($column_options['length']) && strlen($result['data'][$column_name]) > $column_options['length']) { // varchar
						$result['error'][] = i18n(null, 'String is too long, should be no longer than [length]!', ['replace' => ['[length]' => i18n(null, $column_options['length'])]]);
						$error = true;
					}
				}
			}
			$result['data']['flag_error'] = $error;
		} else if (!empty($result['data'][$column_name . '_is_serial'])) {
			if ($value . '' !== '' && !empty($result['data'][$column_name . '_is_serial_error'])) {
				$result['error'][] = i18n(null, 'Wrong sequence value!');
				$result['data']['flag_error'] = true;
			}
		} else {
			$result['error'][] = i18n(null, \Object\Content\Messages::unknown_value);
			$result['data']['flag_error'] = true;
		}
		if (empty($result['error'])) $result['success'] = true;
		return $result;
	}
844065
public static function GetAutoIncrementColumns (array $options, $table_name, $forced_obtain = false) {
		return static::GetConnection($options)->getAutoIncrementColumns($table_name, $forced_obtain);
	}
1124735
public function addHeader(string $report_name, string $header_name, array $header_columns, array $options = []) {
		// set index
		$index = 0;
		foreach ($header_columns as $k => $v) {
			$header_columns[$k]['label_name'] = i18n(null, $v['label_name']);
			$header_columns[$k]['__index'] = $index;
			$index++;
		}
		// replace header
		$this->data[$report_name]['header'][$header_name] = $header_columns;
		$this->data[$report_name]['header_options'][$header_name] = $options;
	}