Insert DB table data.

@param $service

@return bool
@throws \DreamFactory\Core\Exceptions\InternalServerErrorException
322019
protected function insertDbTableResources($service)
    {
        $data = $this->package->getResourceFromZip($service . '/_table' . '.json');
        if (!empty($data)) {
            foreach ($data as $table) {
                $tableName = array_get($table, 'name');
                $resource = '_table/' . $tableName;
                $records = array_get($table, 'record');
                $records = $this->cleanDuplicates($records, $service, $resource);

                if (!empty($records)) {
                    try {
                        foreach ($records as $i => $record) {
                            $this->fixCommonFields($record, false);
                            $this->unsetImportedRelations($record);
                            $records[$i] = $record;
                        }

                        $payload = ResourcesWrapper::wrapResources($records);
                        $result = ServiceManager::handleRequest(
                            $service,
                            Verbs::POST,
                            $resource,
                            ['continue' => true],
                            [],
                            $payload,
                            null,
                            true,
                            true
                        );
                        if ($result->getStatusCode() >= 300) {
                            throw ResponseFactory::createExceptionFromResponse($result);
                        }
                    } catch (\Exception $e) {
//                        if ($e->getCode() === HttpStatusCodes::HTTP_FORBIDDEN) {
//                            $this->log(
//                                'error',
//                                'Failed to insert ' .
//                                $service .
//                                '/' .
//                                $resource .
//                                '. ' .
//                                $this->getErrorDetails($e)
//                            );
//                        } else {
//                            throw new InternalServerErrorException('Failed to insert ' .
//                                $service .
//                                '/' .
//                                $resource .
//                                '. ' .
//                                $this->getErrorDetails($e)
//                            );
//                        }
                        $this->throwExceptions($e, 'Failed to insert ' . $service . '/' . $resource);
                    }
                }
            }

            return true;
        }

        return false;
    }
1261261
protected function _insert()
    {
        $result = parent::_insert();

        if ($result) {
            //also insert to multilang tables if it is separate
            foreach ($this->_getLanguageSetTables() as $table) {
                $sql = "insert into $table set " . $this->_getUpdateFieldsForTable($table, $this->getUseSkipSaveFields());

                $result = $result && (bool) $this->executeDatabaseQuery($sql);
            }
        }

        return $result;
    }
875174
public function setService($service)
    {
        Service::isValid($service);

        $this->service = $service;

        if ($service === Service::EP) {
            $this->set(Config::T200, 'T13');
            $this->set(Config::T206, $service);
        } elseif ($service === Service::SHD || $service === Service::FDF) {
            $this->set(Config::T200, $service);
            $this->set(Config::T750, Service::getLabel($service));
        }

        return $this;
    }
1009924
private function insertAppRecord(& $record, $ssId = null, $sc = null)
    {
        $record['storage_service_id'] = $ssId;
        $record['storage_container'] = $sc;
        $this->sanitizeAppRecord($record);

        try {
            $result = ServiceManager::handleRequest('system', Verbs::POST, 'app', ['fields' => '*'], [], [$record]);
            if ($result->getStatusCode() >= 300) {
                throw ResponseFactory::createExceptionFromResponse($result);
            }
        } catch (\Exception $ex) {
            throw new InternalServerErrorException("Could not create the application.\n{$ex->getMessage()}");
        }

        $result = $result->getContent();

        return ($this->resourceWrapped) ? $result[$this->resourceWrapper][0] : $result[0];
    }
528778
public function add_external_service($service) {
        global $DB;
        $service->timecreated = time();
        $serviceid = $DB->insert_record('external_services', $service);
        return $serviceid;
    }
476323
public function addByArray(array $services = [])
  {
    if (!empty($services)) {
      foreach ($services as $name => $methods) {
        if (!$this->has($name)) {
          $service = new Service();

          foreach ($methods as $method => $value) {
            if (method_exists($service, $method)) {
              $service->{$method}($value);
            } else {
                throw new ServiceMethodNotExists(sprintf(
                  "Method '%s' does not exists on the %s service.",
                  $method,
                  $name
                ));
              }
          }

          $this->services[$name] = $service;

          continue;
        }

        throw new ServiceAlreadyExists(sprintf(
          "Service '%s' already exists.",
          $name
        ));
      }
    }

    return $this;
  }
1197812
public function load( $service ){
          
             // is overwrite class specified 
            $class = array_key_exists($service, $this->webServices)
                    ? new $this->webServices[$service]
                    : $this;
            
            $class->build( $service );
            
            return $class;
      }
949701
public function add($id, $service, $replace = false)
    {
        if ($this->has($id) == true && $replace == false) {           
            throw new ServiceExistsException($id);
        }
        $this->services[$id] = $service;
    }
1202213
public function insert(array $data) {
		$data = $this->filterFields($data, $this->_allowed_insert_fields);
		$data['created_at'] = Factory::load('\datetime')->format('Y-m-d H:i:s');

		return $this->_db->insertSafe($this->_table, $data);
	}
703063
public function insert(array $data) {
        $statement = new InsertStatement($data);
        $statement->setStatementContext($this->statementContext);
        $sql = $statement->parse();

        $result = $this->connection->execute($sql, $this->statementContext->getParameters());

        $this->clear();

        if ($result === false) {
            return false;
        }

        return $this->connection->lastInsertId();
    }
1346732
public static function insert($data)
    {
        $self  = self::getInstance();
        $table = $self->table_name;

        if (isset($data[0])) {
            $make      = $self->makeMultipleInsert($table, $data);
            $statement = $make[0];
            $value     = $make[1];
        } else {
            $newData    = $self->makeInsertParameter($data);
            $column     = implode(",", array_keys($data));
            $paramValue = implode(",", array_keys($newData));
            $statement  = "INSERT INTO {$table} ({$column}) VALUES({$paramValue});";
            $value      = $newData;
        }

        $execute   = $self->exec($statement, $value);

        return $execute;
    }
656928
public function setService($id)
    {
        $id = filter_var($id, FILTER_SANITIZE_NUMBER_INT);
        if (empty($id)) {
            throw new InternalServerErrorException('No service id provided.');
        }

        if (empty($this->service = ServiceManager::getServiceNameById($id))) {
            throw new InternalServerErrorException('No alternate db service found with id ' . $id);
        }
    }
1040195
public function addService(DataTableHandlerInterface $service, string $id = null)
    {
        $service_id = $id ?? $service::ID;

        if ($service_id !== null) {
            $this->services[$service_id] = $service;
        }
    }
1289173
protected function insert()
    {
        if ($this->isDirty()) {
            $sql = 'INSERT INTO '.$this->getTableName().'  SET ';
            $data = [];
            $params = [];

            $pk_name = $this->getPkName();

            foreach ((new \ReflectionObject($this))->getProperties(\ReflectionProperty::IS_PUBLIC) as $property) {
                if ($this->{$property->getName()}) {
                    if ($this->{$property->getName()} instanceof Expression) {
                        $data[] = "`{$property->getName()}` = ".$this->{$property->getName()}->toSql();
                    } else {
                        $data[] = "`{$property->getName()}` = :{$property->getName()}";
                        $params[":{$property->getName()}"] = $this->{$property->getName()};
                    }
                }
            }

            $sql .= implode(',', $data);

            $stmt = $this->getDB()->prepare($sql);
            $stmt->execute($params);
            $last_insert_id = $this->getDB()->lastInsertId();

            if (is_array($pk_name)) {
                /*
                 * @TODO: Composite PK
                 */
            } else {
                $this->{$pk_name} = $last_insert_id;
            }

            $this->setDirty(false);
            $stmt->closeCursor();
            $this->_is_new = false;
        }

        return true;
    }
1212578
public function insert($repository, $data)
    {
        $context = $this->getCommandContext();

        $context->data = $data;
        $context->repository = $repository;

        if ($this->getCommandChain()->run('before.insert', $context) !== false) {
            $vals = array();

            $this->_adapter->getConnection()->autocommit(false);

            $resources = $repository->getResources();

            foreach ($data as $column => $val) {
                $column = $resources->getColumn($column);
                $key = $column->resource->getAlias();
                if (!isset($vals[$key])) {
                    $vals[$key] = array();
                }

                $vals[$key][$this->quoteName($column->name)] = $this->quoteValue($val);
            }

            $main_insert_id = null;

            foreach ($resources as $resource) {
                //check if therre now columns to be saved then probably a second empty
                //table so lets create an empty record
                $columns = isset($vals[$resource->getAlias()]) ? array_keys($vals[$resource->getAlias()])   : array();
                $values = isset($vals[$resource->getAlias()]) ? array_values($vals[$resource->getAlias()]) : array();

                if ($resource !== $resources->main()) {
                    $link = $resource->getLink();
                    $columns[] = $link->child;
                    $values[] = $main_insert_id;
                }

                $query = 'INSERT INTO '.$this->_adapter->getTablePrefix().$resource->getName()
                         .'('.implode(', ', $columns).') VALUES ('.implode(', ', $values).')';

                $this->execute($query);

                if ($resource === $resources->main()) {
                    $main_insert_id = $this->_adapter->getInsertId();
                }
            }

            $this->_adapter->getConnection()->commit();
            $this->_adapter->getConnection()->autocommit(true);

            $context->result = $main_insert_id;

            $this->getCommandChain()->run('after.insert', $context);
        }

        return $context->result;
    }
274046
public function addService($service)
    {
        if (in_array($service, $this->allServices)) {
            $this->services[] = $service;
        }

        return $this;
    }
1287800
public function insertRecord(array $data, $returnData = false)
    {
        $countedRecords = count($this->getRecords());
        $data[$this->primaryKey] = $countedRecords > 1 ? $countedRecords + 1 : 1;
        $this->database->getReference()
            ->getChild($this->table)
            ->getChild($countedRecords)
            ->set($data);

        if ($returnData) {
            return $this->getRecord($data[$this->primaryKey]);
        }

        return $this;
    }