function cassandra_query($sql)
{
    require_once 'phpcassa/connection.php';
    require_once 'phpcassa/columnfamily.php';
    $servers[0]['host'] = '127.0.0.1';
    $servers[0]['port'] = '9160';
    $conn = new Connection('Keyspace1', $servers);
    $sql_stmt = explode(" ", $sql);
    $cf = $sql_stmt[3];
    $uname = explode("=", $sql_stmt[5]);
    $passwd = explode("=", $sql_stmt[7]);
    echo $cf . " " . str_replace("'", "", $uname[1]) . " " . str_replace("'", "", $passwd[1]) . " " . $uname[0] . " " . $passwd[0];
    $column_family = new ColumnFamily($conn, $cf);
    echo $cf . " " . str_replace("'", "", $uname[1]) . " " . str_replace("'", "", $passwd[1]) . " " . $uname[0] . " " . $passwd[0];
    $index_exp = CassandraUtil::create_index_expression($uname[0], str_replace("'", "", $uname[1]));
    $index_clause = CassandraUtil::create_index_clause(array($index_exp));
    $rows = $column_family->get_indexed_slices($index_clause);
    foreach ($rows as $key => $columns) {
        if ($columns[$passwd[0]] == str_replace("'", "", $passwd[1])) {
            //			echo $columns;
            return $columns;
        } else {
            return NULL;
        }
    }
}
Exemplo n.º 2
0
 function getEventsPageTagCloud($connection, $se)
 {
     $rowsFound = false;
     $sql = new ColumnFamily($connection, 'SOCIALEVENTTAG_SOCIALEVENT');
     $cloudquery = new ColumnFamily($connection, 'SOCIALEVENTTAG');
     $index_exp = CassandraUtil::create_index_expression('socialeventid', $se);
     $index_clause = CassandraUtil::create_index_clause(array($index_exp));
     $result = $sql->get_indexed_slices($index_clause);
     if (!empty($result)) {
         foreach ($result as $key => $value) {
             if ($value['socialeventtagid'] != NULL) {
                 $cloudresult = $cloudquery->get($value['socialeventtagid']);
                 if ($cloudresult['refcount'] > 0) {
                     $rowsFound = true;
                     $tags[$cloudresult['tag']] = $cloudresult['refcount'];
                 }
             }
         }
     }
     unset($cloudresult);
     if ($rowsFound) {
         // change these font sizes if you will
         $max_size = 250;
         // max font size in %
         $min_size = 100;
         // min font size in %
         // get the largest and smallest array values
         $max_count = max(array_values($tags));
         $min_count = min(array_values($tags));
         // find the range of values
         $spread = $max_count - $min_count;
         if (0 == $spread) {
             // we don't want to divide by zero
             $spread = 1;
         }
         // determine the font-size increment
         // this is the increase per tag count (times used)
         $step = ($max_size - $min_size) / $spread;
         // loop through our tag array
         foreach ($tags as $key => $value) {
             $size = $min_size + ($value - $min_count) * $step;
             // uncomment if you want sizes in whole %:
             $size = ceil($size);
             $eventTagCloud = $eventTagCloud . " " . '<a href="taggedEvents.php?tag=' . $key . '" style="font-size:' . $size . '%" title="' . $value . ' events tagged with ' . $key . '" >' . $key . '</a> ';
         }
     }
     return $eventTagCloud;
 }
Exemplo n.º 3
0
    $month = substr($eventdate, 5, 2);
    $day = substr($eventdate, 8, 2);
    $hour = substr($eventdate, 11, 2);
    $minute = substr($eventdate, 14, 2);
    $street1 = $row['street1'];
    $street2 = $row['street2'];
    $city = $row['city'];
    $state = $row['state'];
    $zip = $row['zip'];
    $country = $row['country'];
    unset($result);
    //    $q1="select tag from SOCIALEVENTTAG as st, SOCIALEVENTTAG_SOCIALEVENT as sst where sst.socialeventid='$se' and sst.socialeventtagid=st.socialeventtagid order by tag ASC";
    //    $result1 = $connection->query($q1);
    $sql = new ColumnFamily($conn, 'SOCIALEVENTTAG_SOCIALEVENT');
    $index_exp = CassandraUtil::create_index_expression('socialeventid', $se);
    $index_clause = CassandraUtil::create_index_clause(array($index_exp));
    $result1 = $sql->get_indexed_slices($index_clause, $columns = array('socialeventtagid'));
    $q1 = new ColumnFamily($conn, 'SOCIALEVENTTAG');
    foreach ($result1 as $key1 => $col1) {
        $row = $q1->get($col1['socialeventtagid']);
        $tg = $row['tag'];
        $tags = $tags . " " . $tg;
    }
    unset($result1);
}
if (!is_null($se) && (is_null($_SESSION["uname"]) || !($_SESSION["uname"] == $submitter))) {
    $fillMessage = "<font color=red>You can only edit events you created.</font> ";
} else {
    ob_start();
    require "../views/addEvent.php";
    $fillContent = ob_get_clean();
 function read_with_indexes($keyspace, $column_family, $indexes, $columns = null, $range = null, $consistency)
 {
     Loader::load("vendor", "phpcassa/columnfamily.php");
     $expressions = array();
     foreach ($indexes as $filter) {
         $expressions[] = CassandraUtil::create_index_expression($filter["column"], $filter["value"], !isset($filter["comparison"]) ? cassandra_IndexOperator::EQ : $filter["comparison"]);
     }
     $columnfamily = new columnfamily($this->connection($keyspace), $column_family, true, true, $consistency, $consistency, 500);
     if (isset($range) && is_array($range)) {
         if ($range["start"] != 0) {
             throw new Exception("Sorry, only ranges starting at 0 are currently supported");
         }
         $clause = CassandraUtil::create_index_clause($expressions, $range["start"], $range["length"]);
     } else {
         $clause = CassandraUtil::create_index_clause($expressions, "", 1000000);
     }
     //only the first million objects?
     $iterator = $columnfamily->get_indexed_slices($clause, $columns, "", "", false, 500, null, $consistency);
     $iterator->rewind();
     $data = array();
     while ($iterator->valid()) {
         $key = $iterator->key();
         $value = $iterator->current();
         $data[$key] = $value;
         $iterator->next();
     }
     return $data;
 }
Exemplo n.º 5
0
 function getUpcomingEventsForUser($user, $connection, $flag, $offset)
 {
     if (!$flag) {
         //		$query = "select se.socialeventid,se.title From SOCIALEVENT as se,PERSON_SOCIALEVENT as ps where se.socialeventid=ps.socialeventid and se.eventtimestamp>=CURRENT_TIMESTAMP and ps.username='******' ORDER BY se.eventdate ASC limit 3";
         $sql = new ColumnFamily($connection, 'PERSON_SOCIALEVENT');
         $index_exp_uname = CassandraUtil::create_index_expression('username', $user);
         $index_clause = CassandraUtil::create_index_clause(array($index_exp_uname), 0, 3);
         $rows = $sql->get_indexed_slices($index_clause, $columns = array('socialeventid'));
         $query = new ColumnFamily($connection, 'SOCIALEVENT');
         foreach ($rows as $key => $columns) {
             $index_exp1 = CassandraUtil::create_index_expression('socialeventid', $columns['socialeventid'], cassandra_IndexOperator::EQ);
             $index_exp2 = CassandraUtil::create_index_expression('eventtimestamp', time(), cassandra_IndexOperator::GTE);
             $index_clause1 = CassandraUtil::create_index_clause(array($index_exp1, $index_exp2));
             $queryresult = $query->get_indexed_slices($index_clause1);
             $queryresult = $query->get_indexed_slices($index_clause1);
             foreach ($queryresult as $key1 => $value1) {
                 $result[$key1] = $value1;
             }
         }
         $count = 1;
     } else {
         if ($flag) {
             //		$query = "select se.socialeventid,se.title From SOCIALEVENT as se,PERSON_SOCIALEVENT as ps where se.socialeventid=ps.socialeventid and se.eventtimestamp>=CURRENT_TIMESTAMP and ps.username='******' ORDER BY se.eventdate ASC limit $offset,10";
             $sql = new ColumnFamily($connection, 'PERSON_SOCIALEVENT');
             $index_exp_uname = CassandraUtil::create_index_expression('username', $user);
             $index_clause = CassandraUtil::create_index_clause(array($index_exp_uname), $offset, 10);
             $rows = $sql->get_indexed_slices($index_clause, $columns = array('socialeventid'));
             $query = new ColumnFamily($connection, 'SOCIALEVENT');
             foreach ($rows as $key => $columns) {
                 $index_exp1 = CassandraUtil::create_index_expression('socialeventid', $columns['socialeventid'], cassandra_IndexOperator::EQ);
                 $index_exp2 = CassandraUtil::create_index_expression('eventtimestamp', time(), cassandra_IndexOperator::GTE);
                 $index_clause1 = CassandraUtil::create_index_clause(array($index_exp1, $index_exp2));
                 $queryresult = $query->get_indexed_slices($index_clause1);
                 $queryresult = $query->get_indexed_slices($index_clause1);
                 foreach ($queryresult as $key1 => $value1) {
                     $result[$key1] = $value1;
                 }
             }
             $count = 1 + $offset;
         }
     }
     foreach ($result as $key1 => $row) {
         $rowsFound = true;
         $title = $row['title'];
         $se = $row['socialeventid'];
         $upcomingEvents = $upcomingEvents . " " . '<a href="events.php?socialEventID=' . $se . '">' . $count . '. ' . $title . '</a><br/>';
         $count++;
     }
     unset($result);
     return $upcomingEvents;
 }
Exemplo n.º 6
0
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/**
 * PHP Template.
 * Author: Sheetal Patil. Sun Microsystems, Inc.
 *
 */
session_start();
require_once "../etc/config.php";
require_once '../etc/phpcassa_config.php';
$friends = Users_Controller::getInstance();
$person = $_REQUEST['person'];
$friend = $_REQUEST['friend'];
$revokeSql = new ColumnFamily($conn, 'PERSON_PERSON');
$index_exp_person = CassandraUtil::create_index_expression('Person_username', $friend);
$index_exp_friend = CassandraUtil::create_index_expression('friends_username', $person);
$index_clause = CassandraUtil::create_index_clause(array($index_exp_person, $index_exp_friend));
$result = $revokeSql->get_indexed_slices($index_clause);
foreach ($result as $key => $col) {
    $revokeSql->remove($col['id']);
}
$outgoingRequests = $friends->outgoingRequests($person, $conn);
echo "<font color=green>You have revoked your friendship request to " . $friend . "</font>\n";
echo $outgoingRequests;
?>

Exemplo n.º 7
0
    }
} else {
    /*    $query = "select count(*) as count From SOCIALEVENT as se,PERSON_SOCIALEVENT as ps where se.socialeventid=ps.socialeventid and se.eventtimestamp>=CURRENT_TIMESTAMP and ps.username='******'";
        $result = $connection->query($query);
        $row = $result->getArray();
    */
    $row['count'] = 0;
    $sql = new ColumnFamily($conn, 'PERSON_SOCIALEVENT');
    $index_exp_uname = CassandraUtil::create_index_expression('username', $un);
    $index_clause = CassandraUtil::create_index_clause(array($index_exp_uname));
    $rows = $sql->get_indexed_slices($index_clause, $columns = array('socialeventid'));
    $query = new ColumnFamily($conn, 'SOCIALEVENT');
    foreach ($rows as $key => $columns) {
        $index_exp1 = CassandraUtil::create_index_expression('socialeventid', $columns['socialeventid'], cassandra_IndexOperator::EQ);
        $index_exp2 = CassandraUtil::create_index_expression('eventtimestamp', time(), cassandra_IndexOperator::GTE);
        $index_clause1 = CassandraUtil::create_index_clause(array($index_exp1, $index_exp2));
        $result = $query->get_indexed_slices($index_clause1);
        foreach ($result as $key1 => $value1) {
            $row['count'] += 1;
        }
    }
    $count = $row['count'];
    unset($result);
    $numPages = ceil($count / 10);
    $_SESSION["numPages"] = $numPages;
    $prev_page = 1;
    $next_page = 2;
    $curr_page = 1;
    $offset = 0;
    session_unregister("currentpage");
}
             $operator = cassandra_IndexOperator::GT;
             break;
         case 'lte':
             $operator = cassandra_IndexOperator::LTE;
             break;
         case 'lt':
             $operator = cassandra_IndexOperator::LT;
             break;
         default:
             // Invalid operator
             break;
     }
     $arr_index_expression[] = CassandraUtil::create_index_expression($index_name, $column_value, $operator);
     $no_index_expression++;
 }
 $index_clause = CassandraUtil::create_index_clause($arr_index_expression, '', $nb_rows);
 $time_start = microtime(true);
 $result = $column_family->get_indexed_slices($index_clause);
 $time_end = microtime(true);
 $vw_row_vars['is_super_cf'] = $column_family->cfdef->column_type == 'Super';
 $vw_row_vars['is_counter_column'] = $column_family->cfdef->default_validation_class == 'org.apache.cassandra.db.marshal.CounterColumnType';
 $vw_vars['results_secondary_index'] = '';
 $vw_vars['results'] = '';
 $nb_results = 0;
 foreach ($result as $key => $value) {
     $vw_row_vars['key'] = $key;
     $vw_row_vars['value'] = $value;
     $vw_row_vars['keyspace_name'] = $keyspace_name;
     $vw_row_vars['columnfamily_name'] = $columnfamily_name;
     $vw_row_vars['show_actions_link'] = false;
     $vw_vars['results_secondary_index'] .= getHTML('columnfamily_browse_data_row.php', $vw_row_vars);
Exemplo n.º 9
0
 /**
  * Fetches a set of rows from this column family based on an index clause.
  *
  * @param string $indexColumn the name of the indexed column
  * @param mixed $indexValue the value of the column to retrieve
  * @param mixed[] $columns limit the columns or super columns fetched to this list
  * @param mixed $columnStart only fetch columns with name >= this
  * @param mixed $columnFinish only fetch columns with name <= this
  * @param bool $columnReversed fetch the columns in reverse order
  * @param int $columnCount limit the number of columns returned to this amount
  * @param mixed $superColumn return only columns in this super column
  * @param cassandra_ConsistencyLevel $readConsistencyLevel affects the guaranteed
  * 		 number of nodes that must respond before the operation returns
  *
  * @return mixed array(row_key => array(column_name => column_value))
  */
 public function getIndexedSlices($indexColumn, $indexValue, $columns = null, $columnStart = '', $columnFinish = '', $columnReversed = false, $columnCount = ColumnFamily::DEFAULT_COLUMN_COUNT, $superColumn = null, $readConsistencyLevel = null, $bufferSize = null)
 {
     if (empty($this->_columnFamily)) {
         $this->init();
     }
     $indexExp = CassandraUtil::create_index_expression($indexColumn, $indexValue);
     $indexClause = CassandraUtil::create_index_clause(array($indexExp));
     $row = $this->_columnFamily->get_indexed_slices($indexClause, $columns, $columnStart, $columnFinish, $columnReversed, $columnCount, $superColumn, $readConsistencyLevel, $bufferSize);
     foreach ($row as $key => $attributes) {
         $this->_rowKey = $key;
         $this->_attributes = $attributes;
         break;
     }
     if ($this->_rowKey === null) {
         return null;
     }
     return $this;
 }
Exemplo n.º 10
0
    if ($prev_page < 0) {
        $prev_page = 1;
    }
    if ($next_page > $numPages) {
        $next_page = $numPages;
    }
} else {
    /*    $query = "select count(*) as count from PERSON_PERSON ".
                 "where person_username='******' and is_accepted=1";
        $result = $connection->query($query);
        $row = $result->getArray();
    */
    $query = new ColumnFamily($conn, 'PERSON_PERSON');
    $index_exp_frnd = CassandraUtil::create_index_expression('Person_username', $user);
    $index_exp_acpt = CassandraUtil::create_index_expression('is_accepted', 1);
    $index_clause = CassandraUtil::create_index_clause(array($index_exp_frnd, $index_exp_acpt));
    $rows = $query->get_indexed_slices($index_clause, $columns = array('friends_username'));
    $row['count'] = 0;
    foreach ($rows as $key => $columns) {
        $row['count'] += 1;
    }
    $count = $row['count'];
    unset($result);
    $numPages = ceil($count / 10);
    $_SESSION["numPages"] = $numPages;
    $prev_page = 1;
    $next_page = 2;
    $curr_page = 1;
    $offset = 0;
    session_unregister("currentpage");
}
Exemplo n.º 11
0
 function outgoingRequests($username, $connection)
 {
     ob_start();
     $isql = new ColumnFamily($connection, 'PERSON_PERSON');
     $index_exp_frnd = CassandraUtil::create_index_expression('friends_username', $username);
     $index_exp_acpt = CassandraUtil::create_index_expression('is_accepted', 0);
     $index_clause = CassandraUtil::create_index_clause(array($index_exp_frnd, $index_exp_acpt));
     $rows = $isql->get_indexed_slices($index_clause, $columns = array('Person_username'));
     foreach ($rows as $key => $col) {
         $person_sql = new ColumnFamily($connection, 'PERSON');
         $index_exp_p = CassandraUtil::create_index_expression('username', $col['Person_username']);
         $index_clause_p = CassandraUtil::create_index_clause(array($index_exp_p));
         $result1 = $person_sql->get_indexed_slices($index_clause_p, $columns = array('firstname', 'lastname', 'username'));
         foreach ($result1 as $resultkey => $row1) {
             $personun = $row1['username'];
             $friendun = $username;
             $fn = $row1['firstname'];
             $ln = $row1['lastname'];
             require "../views/outgoingRequests.php";
         }
     }
     unset($result1);
     $outgoingRequests = ob_get_contents();
     ob_end_clean();
     return $outgoingRequests;
 }
Exemplo n.º 12
0
 public function test_get_indexed_slices()
 {
     $indexed_cf = new ColumnFamily($this->client, 'Indexed1');
     $columns = array('birthdate' => 1);
     foreach (range(1, 3) as $i) {
         $indexed_cf->insert('key' . $i, $columns);
     }
     $expr = CassandraUtil::create_index_expression($column_name = 'birthdate', $value = 1);
     $clause = CassandraUtil::create_index_clause(array($expr));
     $result = $indexed_cf->get_indexed_slices($clause);
     self::assertEqual(count($result), 3);
     foreach (range(1, 3) as $i) {
         self::assertEqual($result['key' . $i], $columns);
     }
     $indexed_cf->truncate();
 }
Exemplo n.º 13
0
$listquery = "select username from PERSON_SOCIALEVENT ".
             "where socialeventid = '$se' and username = '******' ".
             "union select username from PERSON_SOCIALEVENT ".
             "where socialeventid = '$se' limit 20";
$listqueryresult = $connection->query($listquery);
*/
$listquery = new ColumnFamily($conn, 'PERSON_SOCIALEVENT');
$index_exp_event = CassandraUtil::create_index_expression('socialeventid', $se);
$index_exp_uname = CassandraUtil::create_index_expression('username', $username);
$index_clause = CassandraUtil::create_index_clause(array($index_exp_event, $index_exp_uname));
$result = $listquery->get_indexed_slices($index_clause);
$count = 0;
foreach ($result as $key => $column) {
    $count += 1;
}
$username = $_SESSION["uname"];
if ($count > 0) {
    $index_clause_list = CassandraUtil::create_index_clause(array($index_exp_event));
    $listqueryresult = $listquery->get_indexed_slices($index_clause_list);
    foreach ($listqueryresult as $key => $column) {
        $tmp_uname = $column['username'];
        $attendeeList = $attendeeList . " " . '<a href="users.php?username='******'">' . $tmp_uname . '</a><br />';
    }
}
unset($listqueryresult);
if ($txBegun) {
    $connection->commit();
}
$numofattendees = $_SESSION["numofattendees"] + 1;
$_SESSION["numofattendees"] = $numofattendees;
echo '<h2 class="smaller_heading">' . $numofattendees . ' Attendees:</h2><br/><input name="unattend" type="button" value="Unattend" onclick="deleteAttendee();"/><br/><div id="attendees">' . $attendeeList . '</div>';
Exemplo n.º 14
0
 public function test_get_indexed_slices()
 {
     $indexed_cf = new ColumnFamily($this->pool, 'Indexed1');
     $indexed_cf->truncate();
     $columns = array('birthdate' => 1);
     foreach (range(1, 3) as $i) {
         $indexed_cf->insert('key' . $i, $columns);
     }
     $expr = CassandraUtil::create_index_expression($column_name = 'birthdate', $value = 1);
     $clause = CassandraUtil::create_index_clause(array($expr), 10000);
     $result = $indexed_cf->get_indexed_slices($clause);
     $count = 0;
     foreach ($result as $key => $cols) {
         $count++;
         self::assertEqual($columns, $cols);
         self::assertEqual($key, "key{$count}");
     }
     self::assertEqual($count, 3);
     # Insert and remove a matching row at the beginning
     $indexed_cf->insert('key0', $columns);
     $indexed_cf->remove('key0');
     # Insert and remove a matching row at the end
     $indexed_cf->insert('key4', $columns);
     $indexed_cf->remove('key4');
     # Remove a matching row from the middle
     $indexed_cf->remove('key2');
     $result = $indexed_cf->get_indexed_slices($clause);
     $count = 0;
     foreach ($result as $key => $cols) {
         $count++;
         self::assertTrue($key == "key1" || $key == "key3");
     }
     self::assertEqual($count, 2);
     $indexed_cf->truncate();
     $keys = array();
     foreach (range(1, 1000) as $i) {
         $indexed_cf->insert("key{$i}", $columns);
         if ($i % 50 != 0) {
             $indexed_cf->remove("key{$i}");
         } else {
             $keys[] = "key{$i}";
         }
     }
     $count = 0;
     foreach ($result as $key => $cols) {
         $count++;
         self::assertTrue(in_array($key, $keys));
         unset($keys[$key]);
     }
     self::assertEqual($count, 20);
     $indexed_cf->truncate();
 }