예제 #1
0
 /**
  * Get the SQL string
  *
  * @param string $tableName
  * @param array &$params
  * @param string $returnFields
  * @return string
  */
 public function getSql($tableName, &$params, $returnFields = "*")
 {
     $params = array();
     $sql = "select @@returnFields from @@tableName ";
     $sqlFilter = $this->getFilter(IteratorFilter::SQL, $params);
     if ($sqlFilter != "") {
         $sql .= " where @@sqlFilter ";
     }
     $sql = SQLHelper::createSafeSQL($sql, array("@@returnFields" => $returnFields, "@@tableName" => $tableName, "@@sqlFilter" => $sqlFilter));
     return $sql;
 }
예제 #2
0
 public function getAllFields($tablename)
 {
     $cur = sqlrcur_alloc($this->_conn);
     $success = sqlrcur_sendQuery($cur, SQLHelper::createSafeSQL("select * from :table", array(":table" => $tablename)));
     sqlrcon_endSession($cur);
     if (!$success) {
         throw new DatasetException(sqlrcur_errorMessage($cur));
     }
     $fields = [];
     $colCount = sqlrcur_colCount($cur);
     for ($col = 0; $col < $colCount; $col++) {
         $fields[] = strtolower(sqlrcur_getColumnName($cur, $col));
     }
     sqlrcur_free($cur);
     return $fields;
 }
예제 #3
0
 public function getAllFields($tablename)
 {
     $fields = array();
     $rs = $this->_db->query(SQLHelper::createSafeSQL("select * from :table where 0=1", array(":table" => $tablename)));
     $fieldLength = $rs->columnCount();
     for ($i = 0; $i < $fieldLength; $i++) {
         $fld = $rs->getColumnMeta($i);
         $fields[] = strtolower($fld["name"]);
     }
     return $fields;
 }
예제 #4
0
 /**
  * @param bool $getAll
  * @return IteratorInterface
  */
 protected function GetIterator($getAll)
 {
     $fields = "";
     foreach ($this->_fields as $field) {
         if ($field->visibleInList || $field->key || !$getAll) {
             if ($fields != "") {
                 $fields .= ",";
             }
             $fields .= $this->getFieldDeliLeft() . $field->fieldName . $this->getFieldDeliRight();
         }
     }
     $sql = "select :fields from :table ";
     $param = array();
     if (!$getAll) {
         $sql .= "where :where ";
     }
     if ($this->_filter != "") {
         $sql .= ($getAll ? " where " : " and ") . " " . $this->getFilter();
     }
     if ($this->_sort != "" && $getAll) {
         $sql .= " order by :order ";
     }
     $sqlHelper = new SQLHelper($this->_dbData);
     $sql = $sqlHelper->createSafeSQL($sql, array(':fields' => $fields, ':table' => $this->_table, ':where' => $this->getWhereClause($param), ":order" => $this->getSort()));
     $this->DebugInfo($sql, $param);
     return $this->_dbData->getIterator($sql, $param);
 }
예제 #5
0
 /**
  * Process Vote. Note that the system ONLY process the vote if there is no another equal IP.
  *
  * @param int $width
  * @param int $height
  */
 public function processVote($width = 450, $height = 400)
 {
     if ($this->_context->get("xcrt") == "") {
         // Is The Post values needed to process vote exists?
         if ($this->_context->get("xmlnuke_poll") != "" && $this->_context->get("xmlnuke_polllang") != "" && $this->_context->get("xmlnuke_pollanswer") != "") {
             $this->_poll = $this->_context->get("xmlnuke_poll");
             $this->_lang = $this->_context->get("xmlnuke_polllang");
             $ok = true;
             // Check if IP already voted -> Freeze IP for 5 days.
             if ($this->_isdb) {
                 // Remove Old Entries
                 $dbdata = new DBDataset($this->_connection);
                 $sql = "delete from :table where register < now() - interval 5 day ";
                 $sql = \ByJG\AnyDataset\Database\SQLHelper::createSafeSQL($sql, array(':table' => $this->_tbllastip));
                 $dbdata->execSQL($sql);
                 // Check if exists
                 $sql = "select count(1) from :table where ip = [[ip]] and name = [[name]] ";
                 $sql = \ByJG\AnyDataset\Database\SQLHelper::createSafeSQL($sql, array(':table' => $this->_tbllastip));
                 $param = array("ip" => $this->_context->getClientIp(), "name" => $this->_poll);
                 $count = $dbdata->getScalar($sql, $param);
                 $ok = false;
                 if ($count == 0) {
                     $ok = true;
                     $sql = "insert into :table (ip, name, register) values ([[ip]], [[name]], now()) ";
                     $sql = \ByJG\AnyDataset\Database\SQLHelper::createSafeSQL($sql, array(':table' => $this->_tbllastip));
                     $param = array("ip" => $this->_context->getClientIp(), "name" => $this->_poll);
                     try {
                         $dbdata->execSQL($sql, $param);
                     } catch (\PDOException $ex) {
                         $ok = false;
                     }
                 }
             }
             // Is My IP Unique? If true I can process the vote.
             // Note if the poll name, lang and code are wrong the system does not do anything.
             if ($ok) {
                 // Get Data
                 $itf = new IteratorFilter();
                 $itf->addRelation("name", Relation::EQUAL, $this->_poll);
                 $itf->addRelation("lang", Relation::EQUAL, $this->_lang);
                 $itf->addRelation("code", Relation::EQUAL, $this->_context->get("xmlnuke_pollanswer"));
                 if ($this->_isdb) {
                     $dbdata = new DBDataset($this->_connection);
                     $param = array();
                     $sql = "update :table set votes = IFNULL(votes,0) + 1 where :filter ";
                     $sql = \ByJG\AnyDataset\Database\SQLHelper::createSafeSQL($sql, array(':table' => $this->_tblanswer, ':filter' => $itf->getFilter(IteratorFilter::SQL, $param)));
                     $dbdata->execSQL($sql, $param);
                 } else {
                     $this->getAnyData();
                     $itAnswer = $this->_anyAnswer->getIterator($itf);
                     if ($itAnswer->hasNext()) {
                         $sr = $itAnswer->moveNext();
                         $sr->setField("votes", intval($sr->getField("votes")) + 1);
                         $this->_anyAnswer->Save();
                     }
                 }
             }
             $this->_processed = true;
         }
     } else {
         $this->_processed = true;
     }
     $this->_width = $width;
     $this->_height = $height;
 }
예제 #6
0
 public function getAllFields($tablename)
 {
     $cur = $this->getOci8Cursor(SQLHelper::createSafeSQL("select * from :table", array(':table' => $tablename)));
     $ncols = oci_num_fields($cur);
     $fields = array();
     for ($i = 1; $i <= $ncols; $i++) {
         $fields[] = strtolower(oci_field_name($cur, $i));
     }
     oci_free_statement($cur);
     return $fields;
 }