Get insert sql statement.

@param $function
@param $ar
@param $arguments

@return string
559773
private function getInsertQuery($function, $ar, $arguments)
    {
        $keys = array_keys($arguments);

        return $function.' INTO `'.$ar->getDatabase().'`.`'.$ar->getTableName().
        '` ('.implode(', ', $keys).')'.
        ' VALUES(:'.implode(', :', $keys).')';
    }
1239632
function _query($sql,$inputarr=false)
	{
	GLOBAL $php_errormsg;
		if (isset($php_errormsg)) $php_errormsg = '';
		$this->_error = '';

		if ($inputarr) {
			if (is_array($sql)) {
				$stmtid = $sql[1];
			} else {
				$stmtid = odbc_prepare($this->_connectionID,$sql);

				if ($stmtid == false) {
					$this->_errorMsg = isset($php_errormsg) ? $php_errormsg : '';
					return false;
				}
			}

			if (! odbc_execute($stmtid,$inputarr)) {
				//@odbc_free_result($stmtid);
				if ($this->_haserrorfunctions) {
					$this->_errorMsg = odbc_errormsg();
					$this->_errorCode = odbc_error();
				}
				return false;
			}

		} else if (is_array($sql)) {
			$stmtid = $sql[1];
			if (!odbc_execute($stmtid)) {
				//@odbc_free_result($stmtid);
				if ($this->_haserrorfunctions) {
					$this->_errorMsg = odbc_errormsg();
					$this->_errorCode = odbc_error();
				}
				return false;
			}
		} else
			$stmtid = odbc_exec($this->_connectionID,$sql);

		$this->_lastAffectedRows = 0;
		if ($stmtid) {
			if (@odbc_num_fields($stmtid) == 0) {
				$this->_lastAffectedRows = odbc_num_rows($stmtid);
				$stmtid = true;
			} else {
				$this->_lastAffectedRows = 0;
				odbc_binmode($stmtid,$this->binmode);
				odbc_longreadlen($stmtid,$this->maxblobsize);
			}

			if ($this->_haserrorfunctions) {
				$this->_errorMsg = '';
				$this->_errorCode = 0;
			} else
				$this->_errorMsg = isset($php_errormsg) ? $php_errormsg : '';
		} else {
			if ($this->_haserrorfunctions) {
				$this->_errorMsg = odbc_errormsg();
				$this->_errorCode = odbc_error();
			} else
				$this->_errorMsg = isset($php_errormsg) ? $php_errormsg : '';
		}
		return $stmtid;
	}
1362010
function _query($sql,$inputarr=false)
	{
	GLOBAL $php_errormsg;
		if (isset($php_errormsg)) $php_errormsg = '';
		$this->_error = '';

		if ($inputarr) {
			if (is_array($sql)) {
				$stmtid = $sql[1];
			} else {
				$stmtid = db2_prepare($this->_connectionID,$sql);

				if ($stmtid == false) {
					$this->_errorMsg = isset($php_errormsg) ? $php_errormsg : '';
					return false;
				}
			}

			if (! db2_execute($stmtid,$inputarr)) {
				if ($this->_haserrorfunctions) {
					$this->_errorMsg = db2_stmt_errormsg();
					$this->_errorCode = db2_stmt_error();
				}
				return false;
			}

		} else if (is_array($sql)) {
			$stmtid = $sql[1];
			if (!db2_execute($stmtid)) {
				if ($this->_haserrorfunctions) {
					$this->_errorMsg = db2_stmt_errormsg();
					$this->_errorCode = db2_stmt_error();
				}
				return false;
			}
		} else
			$stmtid = @db2_exec($this->_connectionID,$sql);

		$this->_lastAffectedRows = 0;
		if ($stmtid) {
			if (@db2_num_fields($stmtid) == 0) {
				$this->_lastAffectedRows = db2_num_rows($stmtid);
				$stmtid = true;
			} else {
				$this->_lastAffectedRows = 0;
			}

			if ($this->_haserrorfunctions) {
				$this->_errorMsg = '';
				$this->_errorCode = 0;
			} else
				$this->_errorMsg = isset($php_errormsg) ? $php_errormsg : '';
		} else {
			if ($this->_haserrorfunctions) {
				$this->_errorMsg = db2_stmt_errormsg();
				$this->_errorCode = db2_stmt_error();
			} else
				$this->_errorMsg = isset($php_errormsg) ? $php_errormsg : '';

		}
		return $stmtid;
	}
1076278
public function executeAsTransaction($query, $arg_sets, $which_connection='')
    {
        $which_connection = $which_connection === '' ? $this->default_db : $which_connection;
        $ret = true;
        $statement = $this->prepare($query, $which_connection);
        $this->startTransaction($which_connection);
        $this->lockTimeout(5, $which_connection);
        foreach ($arg_sets as $args) {
            if (!$this->execute($statement, $args, $which_connection)) {
                $ret = false;
                break;
            }
        }
        if ($ret === true) {
            $this->commitTransaction($which_connection);
        } else {
            $this->rollbackTransaction($which_connection);
        }

        return $ret;
    }
444124
public function getInsertQuery()
    {
        $sql = 'INSERT INTO ' . $this->getTable();
        $sql .= "\n" . $this->getColumns();
        $sql .= "\nVALUES " . $this->getValues();

        return $sql;
    }
677476
function aggregate( $function ) {

        if ( $this->parent_ ) {

            throw new \LogicException( 'Cannot aggregate referenced result' );

        }

        $statement = $this->db->select( $this->table, array(
            'expr' => $function,
            'where' => $this->where,
            'orderBy' => $this->orderBy,
            'limitCount' => $this->limitCount,
            'limitOffset' => $this->limitOffset,
            'params' => $this->whereParams
        ) );

        foreach ( $statement->fetch() as $return ) {

            return $return;

        }

    }
595507
private function _exec($sql, $arguments = array())
    {
        $sql = $this->replaceArgs($sql, $arguments);

        // executes the statement
        $result = $this->_conn->query($sql);
        if ($this->_conn->errno > 0) {
            throw new DbException(
                "Failed to execute the statement: " .
                "({$this->_conn->errno}) {$this->_conn->error}"
            );
        }

        return $result;
    }
716701
private function getResult($function, $args = [], $post = false )
    {
        $qargs = ($post ? '' : '?') . http_build_query( $args );

        $curl = curl_init( $this->spiget.$function.( !$post ? ( sizeof( $args ) > 0 ? $qargs : '' ) : '' ) );

        curl_setopt($curl, CURLOPT_USERAGENT, $this->userargent);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

        if ($post) curl_setopt($curl,CURLOPT_POST, 1);
        if ($post) curl_setopt($curl, CURLOPT_POSTFIELDS, $qargs);

        $result = curl_exec($curl);
        $http_response = curl_getinfo($curl)['http_code'];

        curl_close($curl);

        if ( $http_response == 200 )
        {
            return json_decode( $result, true );
        }
        elseif ( $this->throwExceptions )
        {
            throw new SpigetException( json_decode( $result, true )['error'], $http_response );
        }
        else
        {
            return null;
        }
    }
202947
function insertOrUpdate($arr, $upstr = null) {
        if (empty($arr)) return false;
        $comma = '';
        $setFields = '';
        foreach ($arr as $key => $value) {
            if (is_array($value)) {
                $setFields .= "{$comma} `{$key}`=" . current($value);
            }
            else {
                $params[] = $value;
                $setFields .= "$comma `$key`=?";
            }
            $comma = ',';
        }
        $upstr = empty($upstr) ? $setFields : $upstr;
        $sql = "INSERT INTO  `{$this->table}` SET {$setFields} ON DUPLICATE KEY UPDATE {$upstr}";
        $sql = str_replace('table.',$this->table.'.',$sql);
        return $this->db->sql($sql, $params,false);
    }
1294679
private function setAttributesForInsertOrUpdate($arguments, $method)
    {
        $query = $this->queryBuilder();

        if ($method == 'insert') {
            return $query->{$method}($arguments);
        }

        return $query->where($this->getKeyName(), '=', $this->index[$this->getKeyName()])
                     ->{$method}($arguments);
    }
491501
protected function getInsertSql($data)
    {
        $sql = '';
        foreach ($data as $v) {
            $v->geom = $v->worker_lat . " " . $v->worker_lng;
            $strfield = '';
            $strvalue = '';
            foreach ($v as $k => $vv) {
                $strfield .= $k . ',';
                if ($k == 'geom') {
                    $strvalue .= "ST_GeomFromText('POINT(" . addslashes($vv) . ")',4326),";
                } else {
                    $strvalue .= "'" . addslashes($vv) . "',";
                }
            }
            $this->num += 1;
            $strfield = rtrim($strfield, ',');
            $strvalue = rtrim($strvalue, ',');
            $sql .= "({$strvalue}),";
        }
        $sql = rtrim($sql, ',');
        $sql = "insert into " . config("database.pgsql_workers") . "({$strfield}) VALUES {$sql}";


        return $sql;

    }
4776
protected function sqlFunction(SQLFunction $function) {
		//connect to database
		$this->mapper->connect();
	
		//build query
		$query = $this->mapper->newQuery($this->entityProfile)
		->from($this->entityProfile->getEntityTable(), Schema::DEFAULT_ALIAS)
		->select($function->getFunctionInstance());
	
		//set query condition
		if ($this->hasOption('query.filter'))
			$query->where($this->getFilter());
	
		list($sql, $args) = $query->build();
		return $this->mapper->merge($this->clean(['map.type' => $function->getDefaultType()]))->execute($sql, $args);
	}
624638
public static String sqlinsert(List<?> parsedArgs) throws SQLException {
    if (parsedArgs.size() != 4) {
      throw new PSQLException(GT.tr("{0} function takes four and only four argument.", "insert"),
          PSQLState.SYNTAX_ERROR);
    }
    StringBuilder buf = new StringBuilder();
    buf.append("overlay(");
    buf.append(parsedArgs.get(0)).append(" placing ").append(parsedArgs.get(3));
    buf.append(" from ").append(parsedArgs.get(1)).append(" for ").append(parsedArgs.get(2));
    return buf.append(')').toString();
  }
172714
public function select($query, $args = array(), $returnArray = true)
    {
        if($this->pdo) {

            if (!defined('GL_INSTALL') || !GL_INSTALL) {
                $this->pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
            } else {
                $this->pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_WARNING);
            }
            $stmt = $this->pdo->prepare($query);
            $result = $stmt->execute($args);
            //$list = array();
            if ($result) {
                if ($returnArray) {
                    return $stmt->fetchAll(\PDO::FETCH_ASSOC);
                }
                return true;
            } else {
                //            if($this->getLastError())
                throw new \Exception($query . "\n" . $this->getLastError());
            }
        } else {
            throw new \Exception("Error executing query: $query\nIt seems that the connection was not opened!");

        }
    }
1095111
function SQL(strs) {
  for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
    args[_key - 1] = arguments[_key];
  }

  var values = [];
  var text = strs.reduce(function (prev, curr, i) {
    var arg = args[i - 1];
    if (arg instanceof InsertValue) {
      return prev + arg.value + curr;
    } else {
      values.push(arg);
      return prev + '$' + values.length + curr;
    }
  });

  return {
    text: text,
    values: values
  };
}
301396
function insert()
    {
        $item = array();
        $item['owner'] = arg('owner', 'int');
        $item['name'] = arg('name', '/[^a-z0-9_]/i');
        $item['title'] = arg('title', 'dbsafe');
        $item['caption'] = arg('caption', 'dbsafe');
        $item['description'] = arg('description', 'dbsafe');
        $item['hint'] = arg('hint', 'dbsafe');
        $item['keywords'] = arg('keywords', 'dbsafe');
        $item['template'] = arg('template', 'dbsafe');
        $item['type'] = arg('type', 'dbsafe');
        $item['active'] = arg('active', 'int');
        $item['visible'] = arg('visible', 'int');
        $item['access'] = arg('access', 'int');
        $item['position'] = arg('position', 'int');
        $item['options'] = arg('options');
        $item['created'] = $item['updated'] = gettime('Y-m-d H:i:s');

        $temp = Eresus_CMS::getLegacyKernel()->sections->get("(`name`='" . $item['name'] .
        "') AND (`owner`='" . $item['owner'] . "')");
        if (count($temp) == 0)
        {
            Eresus_CMS::getLegacyKernel()->sections->add($item);
            dbReorderItems('pages', "`owner`='".arg('owner', 'int')."'");
            HTTP::redirect(Eresus_Kernel::app()->getPage()->url(array('id'=>'')));
        }
        else
        {
            Eresus_Kernel::app()->getPage()->addErrorMessage(
                sprintf(errItemWithSameName, $item['name']));
            saveRequest();
            HTTP::redirect(Eresus_CMS::getLegacyKernel()->request['referer']);
        }
    }
39010
final public function insert(array $datas, bool $returning_id = false) {
      if (is_array($datas) && count($datas)) {
         if (!is_array(@$datas[0]))
            $datas = [$datas];

         $this->connection();
         $this->columns();

         $placeholders = [];
         $this->placeholder_data = [];

         foreach ($datas as $data) {
            $placeholder = [];
            foreach($this->columnsData as $column) {
               if(isset($data[$column])) {
                  $placeholder[$column] = "NULL";
                  if ( gettype($data[$column])==='boolean' )
                     $placeholder[$column] = $data[$column] ? 'TRUE' : 'FALSE';
                  elseif ( $data[$column]!=='' && $data[$column]!==NULL ) {
                     $placeholder[$column] = "?";
                     $this->placeholder_data[] = $data[$column];
                  }
               }
            }
            $placeholders[] = "(".implode(",", $placeholder).")";
         }

         $columns = "(".implode(",", array_keys($placeholder)).")";

         $placeholders = implode(",", $placeholders);


         $schema = '';
         $returning = '';
         if ($this->driver=='pgsql' && $this->schema) {
            if (!preg_match('/\./', $this->table)) {
               $schema = $this->schema ? $this->schema.'.' : '';	
            }
            $returning = $returning_id ? 'RETURNING '.$this->primaryKey : '';
         }

         $this->last_sql = $this->sql = "INSERT INTO {$schema}{$this->table} {$columns} VALUES {$placeholders} {$returning};";
         
         $this->fetch();

         $this->data = $this->rows;

         $this->reset();

         if ( $this->tableOrig!==NULL ) {
            $this->table = $this->tableOrig;
         }

         $error = $this->error();
         return $error['message'] ? FALSE : TRUE;
      }
      return FALSE;
   }