예제 #1
0
 $selectQueries = array(array('tableName' => 'raffles', 'sql' => ""), array('tableName' => 'participants', 'sql' => ""), array('tableName' => 'winners', 'sql' => ""), array('tableName' => 'raffles', 'sql' => " WHERE raffleid='{$raffleids['0']}'"), array('tableName' => 'raffles', 'sql' => " WHERE raffleid!='{$raffleids['0']}'"));
 $fusionTablesService = new Google_Service_Fusiontables($client);
 $errors = array();
 $tableids = array();
 foreach ($tableSchema as $tableName => $columns) {
     $tableColumns = array();
     foreach ($columns as $columnName => $columnType) {
         $column = new Google_Service_Fusiontables_Column();
         $column->setName($columnName);
         $column->setType($columnType);
         $tableColumns[] = $column;
     }
     $table = new Google_Service_Fusiontables_Table();
     $table->setName($tableName);
     $table->setColumns($tableColumns);
     $table->setIsExportable('true');
     // create fusion tables, saving their ids
     try {
         $response = $fusionTablesService->table->insert($table);
         $tableids[$tableName] = $response->tableId;
     } catch (Google_Service_Exception $e) {
         $errors[] = $e->getErrors();
     }
     //error_log($e->getMessage());
 }
 $queryResults = array();
 try {
     // insert into tables
     foreach ($insertQueries as $query) {
         $fusionTablesService->query->sql("INSERT INTO " . $tableids[$query['tableName']] . $query['sql']);
     }
예제 #2
0
 /**
  * Creates the given Schema of fusion tables
  *
  * @param null $client
  * @param null|array $tableSchema tables and structures
  * @param null $debug
  * @throws Exception
  */
 public function createTables($client = null, $tableSchema = null, $debug = null)
 {
     if ($tableSchema === null) {
         $tableSchema = $this->tableSchema;
     }
     if ($debug === null) {
         $debug = $this->debug;
     }
     if ($client === null) {
         $client = $this->client;
     }
     if (!$client instanceof Google_Client) {
         throw new Exception('$client is not an instance of Google_Client.', 500);
     }
     $service = new Google_Service_Fusiontables($client);
     $tableIds = array();
     foreach ($tableSchema as $tableName => $columns) {
         $tableColumns = array();
         foreach ($columns as $columnName => $columnType) {
             $column = new Google_Service_Fusiontables_Column();
             $column->setName($columnName);
             $column->setType($columnType);
             $tableColumns[] = $column;
         }
         $table = new Google_Service_Fusiontables_Table();
         $table->setName($tableName);
         $table->setColumns($tableColumns);
         $table->setIsExportable('true');
         try {
             $response = $service->table->insert($table);
             $tableIds[$tableName] = $response->tableId;
             if ($debug) {
                 error_log(var_export($tableIds, true));
             }
         } catch (Exception $e) {
             error_log($e->getMessage());
         }
         $this->tableIds = $tableIds;
     }
 }