Googleã¯ããŒã¿ã¹ãã¢ãšããŠFusion TablesãéžæããŸããã
èšäºã«èšèŒãããŠããå 容ïŒFusion Tablesã®æäœ
aïŒJavascript-ããŒã¿ã®ãµã³ããªã³ã°ã®ã¿ã
bïŒPHPïŒZend FrameworkïŒ-éžæãè¿œå ãæŽæ°ã
cïŒGoogleã®ãŠãŒã¶ãŒã€ã³ã¿ãŒãã§ã€ã¹-ããŒãã«ãšãã¥ãŒã®äœæã
èšäºã«ãªããã®ïŒ
aïŒè² è·ãã¹ãã
bïŒã¢ããªã±ãŒã·ã§ã³ã®è©³çŽ°ãªèª¬æ-PHP + Jsãããžã§ã¯ãã§Fusion Tablesã䜿çšããããšã«éç¹ã眮ãããŠããŸãã
æ ãè ã®Webããã°ã©ããŒã ãã圌ã®ãããžã§ã¯ãã§Googleãããã䜿çšããŸããã§ããã ãã©ã°ã€ã³ããã ãã§ãèŠãç®ãçŸãããç¬èªã®ãµãŒããŒãããŒããããããã¥ã¡ã³ãåããã䟿å©ãªïŒå°ãªããšãv.2ã®ïŒ API㧠ãå°ãªããšãäœéã§ã¯ãªãé«éã§ã-ãã©ã¹ããããŸãã ãã¶ãFTãããã ãããšæããŸããã 確ãã«ãç§ã¯ãã§ãã¯ããŸããã§ããã ãããŠããããçµæã§ãã
æè¿ãç§ã¯ããç¥ããããœãŒã·ã£ã«ãããã¯ãŒã¯çšã®ããçš®ã®ã¢ããªã±ãŒã·ã§ã³ããã¡ããã©å®éšãšããŠæžããšããã¢ã€ãã¢ãæãã€ããŸããã å°ãèããåŸãéžæè¢ã¯åçŽãªæ²ç€ºæ¿ã«èœã¡ãŸãã-äžèŠãªãã®ã誰ãã«æäŸã§ããå Žæã§ãã ããã§ã¯ã¢ããªã±ãŒã·ã§ã³ã«ã€ããŠèª¬æããŸãããã¢ãã¬ãŒãäžã¯ãªã³ã¯ãæäŸããŸããã æ®å¿µãªãããç§ã¯ãã©ãã·ã¥ã䜿çšããŠãwith youãããŠããã®ã§ãPHP + Jsã®æšæºçãªæã§æžããŸããã ãã®ã¢ããªã±ãŒã·ã§ã³ã§çããã®ã¯ãæšæºã®mySQLã®ä»£ããã«ãGoogleã®ãµãŒãã¹ã§ããFusion Tablesãã¹ãã¬ãŒãžãšããŠéžæãããããšã§ãã ãªãã§ïŒ éåžžã«ã·ã³ãã«-åçåã®ä¿èšŒã¯ãããŸããã æå ã«ç¡æã®ãµãŒããŒå®¹éã¯ãããŸãã-å€ããäžååã«æ§æãããéçºãµãŒããŒããããŸãã ç§ã¯åæ段éã§æè³ãããããããŸããã§ãã-æãåºãããŠãã ããïŒãããžã§ã¯ãã¯ãã ã®æ¥œãã¿ã®ããã«æžãããŸããã ãŸããGoogle Maps APIã«é¢ãã質åãžã®åçãæ¢ããŠãããšãã«ã Fusion Tablesã«é¢ããèšäºã«åºäŒããŸããã
ã¢ã¯ã»ã¹æš©ã«ã€ããŠå°ãã
ããŒãã«ããã®ãªã¯ãšã¹ãããŒã¿ã¯çŽæ¥javascriptã«ãªããŸãã ã€ãŸã ïŒå°ãªããšãèªã¿åãã®ããã«ïŒããŒãã«ãå ¬éããå¿ èŠããããŸãã jsãé£èªåããŠãããŒãã«ã«ãããã³ã°ããã人ãã¹ã¯ãªãããããŠãŒã¶ãŒåãšãã¹ã¯ãŒããååŸã§ããªãããã«ããæ¹æ³ãããããŸããã
ãããã£ãŠããã¹ãŠã®äººã«ããŒãã«ã«æžã蟌ãæš©å©ãäžããããšã¯æã¿ãŸããã ãããã£ãŠãããŒã¿ã¯ãµãŒããŒåŽã§ã®ã¿ããŒãã«ã«æžã蟌ãŸããŸãã ã€ãŸã ãŠãŒã¶ãŒãåºåãè¿œå ããjsããŠãŒã¶ãŒãå ¥åããããŒã¿ããµãŒããŒã«è»¢éããphpã¹ã¯ãªãããããããååŸããŠGoogle FTã«ãã°ã€ã³ããããŒã¿ãããŒãã«ã«æ¿å ¥ããŸãã
åã®æ®µèœã«å¯Ÿãããã¹ãŠã®éé£ã«äºåã«åæããŸãïŒ ç¹°ãè¿ããŸãããjsã§ãã°ã€ã³/ãã¹ã¯ãŒããé衚瀺ã«ããæ¹æ³ãããããŸããã
ããã§ã¯ãè¡ããŸãããïŒ
ã¹ããã1-ããŒãã«ã®äœæ
ããŒãã«ã¯ãFTãŠãŒã¶ãŒã€ã³ã¿ãŒãã§ã€ã¹ãä»ããŠäœæãããŸã ã ã€ã³ã¿ãŒãã§ã€ã¹ã¯çŽæçã§ãç¹å¥ãªç¥èã¯å¿ èŠãããŸããã 䞻芳çã«-MS Accessã幟åé£æ³ãããã
ããã§ãããŒãã«ã«è€æ°ã®è¡ãæ¿å ¥ã§ããŸãã éåžžãmySQLã䜿çšããå ŽåãphpMyAdminã䜿çšããŸã
ãã®ãããªã¯ã3ã€ã®ãã£ãŒã«ããæã€åçŽãªããŒãã«ãäœæããäŸã瀺ããŠããŸãã
ã¯ããããã«èšããŸããFTã§ã¯ãããŒãã«åã¯æ°åã§ãã ããšãã°ãäœæãããããŒãã«ã®å Žåã¯596524ã§ãããããŒã¿ãã¯åãªããšã€ãªã¢ã¹ã§ãããã¯ãšãªã§ã¯äœ¿çšã§ããŸããã
ããã«å®è¡ããŸããåçŽãªããŒãã«ã®å Žåãidãã£ãŒã«ãïŒãã©ã€ããªèªåã€ã³ã¯ãªã¡ã³ãããŒïŒãäœæããå¿ èŠã¯ãããŸãããåããŒãã«ã«ã¯ãé ããããROWIDãã£ãŒã«ãããããŸãã idã®äœæã¯ãè€æ°ã®ããŒãã«ã«ãŸããã£ãŠJOINãè¡ãäºå®ãããå Žåã«ã®ã¿æå³ããããŸãã ã©ããã£ãŠããã®ïŒ ããŒãã«ããŒãžã®ãããã¡ãã¥ãŒã«ã¯ã[çµå]ãã¿ã³ããããŸãã 衚瀺ããããã€ã¢ãã°ã§ã¯ããã¥ãŒïŒmySQLã®èŠ³ç¹ããã®ãã¥ãŒïŒã®ãããªãã®ãäœæã§ããŸãã
次ã«ãããŒãã«ãå ±æããå¿ èŠããããŸãã æ¿èªãªãã§jsããããŒã¿ãåä¿¡ããããã ããŒãã«ã¯ãã¹ãŠèªã¿åãå°çšã«ãªããŸãã èè ã®ã¿ãããŒã¿ãå€æŽ/è¿œå ã§ããŸãã
ããŒãã«ã®æºåãã§ããŸããã ããã«ãªã³ã¯ããããŸãã
ã¹ããã2-ããŒã¿ã®è¡šç€º-JavaScript
ç§ã®ã»ãšãã©ã®ãµãŒããŒã§ã¯ãhtmlããŒãžãšjsãã¡ã€ã«ãä¿åãããŠããŸãã ããŒãžãèªã¿èŸŒãŸãããšã衚瀺ãããããŒã¿ïŒåºåã®ãªã¹ãïŒãGoogleã®ãµãŒããŒããçŽæ¥ããŠã³ããŒããããŸãã
ããŒãã«ã®ããŒã¿ã¯ãèŠèŠåã¢ãžã¥ãŒã«ã䜿çšããŠè¡šç€ºãããŸãã ããããæ®åœ±ã
ãããè¡ãã«ã¯ãããããŒindex.html-www.google.com/jsapiã«javascriptãžã®ãªã³ã¯ãè¿œå ããdefault.jsãã¡ã€ã«ã«æ¬¡ã®è¡ãè¿œå ããŸãã
google.load('visualization', '1');
Javascript ã§ã® Google APIã¢ãžã¥ãŒã«ã®èªã¿èŸŒã¿ã®è©³çŽ°ã«ã€ããŠã¯ã ãã¡ããã芧ãã ãã ã
ããã«ãããŒãã«ãç §äŒããé¢æ°ïŒå¿çãã³ãã©ãŒïŒãæå®ããå¿ èŠããããŸãã
// var queryText = 'SELECT id, name FROM 596524;'; //url var reqUri = 'http://www.google.com/fusiontables/gvizdata?tq=' + encodeURIComponent(queryText); // visualization var query = new google.visualization.Query(reqUri); // - query.send(displayData);
UPDïŒ dkukushkinãææããããã«ãIEã䜿çšããŠããå ŽåïŒ9æ¥ãŸã§ïŒããµã³ãã«ã«ããªã«æåãå«ãŸããŠããå ŽåïŒããããã ãã§ã¯ãããŸããïŒïŒããŠãŒã¶ãŒã«ã¯ãïŒãã衚瀺ãããŸãã æåã®ä»£ããã«ã ãããã£ãŠãGoogle.vizualizationãåé€ããç¬èªã«ãªã¯ãšã¹ããè¡ããŸããjQueryãè³è³ããŠãã ãããæã§æãããXMLHttpRequestãæžãå¿ èŠã¯ãããŸããã
var queryText = 'SELECT id, name FROM 596524;'; $.ajax({ url:'http://tables.googlelabs.com/api/query?sql='+queryText+'&jsonCallback=?', type: 'GET', success:function(resp){ displayData(resp); }, dataType:'json' });
ãã®åŸããã°ã¯ãªããªãããã¹ãŠãããã«çŸãããªããŸããã ç§ã¯é·ãæŠããèšç»ããŠããŸããããããšãã°ãã®ãããªããããŒã䜿ã£ãŠäœæ¥ããŸããããã€ãŸãä»åã¯é©ããéåžžã¯ããªã«æåã衚瀺ããŸããã åä¿¡ããããŒã¿ã®åœ¢åŒã¯ãVizualizationã䜿çšãããšãã®åœ¢åŒãšãããã«ç°ãªããããdisplayDataé¢æ°ãå€æŽããå¿ èŠããããŸãã ããããäœãåé¡ã¯ãããŸãããéåžžã®JSONãªããžã§ã¯ããè¿ãããŸãããã®ãªããžã§ã¯ãã«ã¯ãåãšè¡ã®2ã€ã®é åãå«ãããŒãã«ãã©ã¡ãŒã¿ãŒããããŸãããã¹ãŠãã·ã³ãã«ã§æ確ã§ãã
åè¿°ã®ããã«ããããã®IDã¯ã¯ãšãªã®ããŒãã«åãšããŠäœ¿çšãããŸãïŒãšããã§ãèå³æ·±ãäºå®ãèŠãããšãã§ããŸã-2æ26æ¥ã«ID = 505 xxxã®ããŒãã«ãäœæããä»æ¥äœæãããããŒã¿ããŒãã«ã¯ID 596 524ãåãåããŸãã-ã91 FTã«1ãææªæºã§000åã®ããŒãã«ãè¿œå ãããŸããïŒã
ãããŠæåŸã«ãããŒãžåºåæ©èœ
function displayData(response) { // response //http://code.google.com/apis/visualization/documentation/reference.html#QueryResponse numRows = response.getDataTable().getNumberOfRows(); numCols = response.getDataTable().getNumberOfColumns(); // fusiontabledata = "<b>"; for(i = 0; i < numCols; i++) { fusiontabledata += response.getDataTable().getColumnLabel(i) + ","; } fusiontabledata += "</b><br />"; for(i = 0; i < numRows; i++) { for(j = 0; j < numCols; j++) { fusiontabledata += response.getDataTable().getValue(i, j) + ", "; } fusiontabledata += "<br />"; } // document.getElementById('echoer').innerHTML = fusiontabledata; }
JsFiddleã®äŸ
ä»ãè»èã®ããšã FTã¯SQLã¯ãšãªèšèªã䜿çšããŸãã 詳现ã¯ãã¡ã ã ãããïŒ ãã®èšèªã«ã¯ãããã€ãã®äºæããªãå¶éããããŸã-
å®éã®ãããžã§ã¯ãã§ã¯ãšãªã®ãã£ãã·ã¥ïŒãã©ãŠã¶ãããžã¥ã¢ã©ã€ãŒãŒã·ã§ã³ããŸãã¯FTèªäœã§ãã£ãã·ã¥ãããå Žæãæ£ç¢ºã«ç解ã§ããŸããã§ããïŒãåé¿ããã«ã¯ãã¯ãšãªæ¡ä»¶ã«ãANDåã234567ã«çãããªããã®ãããªãã®ãè¿œå ããŸãã ãMath.getRandomIntïŒïŒ ïŒã
ãã¡ããããªã¯ãšã¹ããéä¿¡ããŠã¬ã¹ãã³ã¹ãåŠçããã«ã¯ãç¬èªã®ã¯ã©ã¹ãäœæããå¿ èŠããããŸãã ããèŠããšãè€éãªããšã¯äœããããŸããã SELECT-GETèŠæ±ã«ãã£ãŠç¹å¥ãªã¢ãã¬ã¹ã«éä¿¡ããããµãŒããŒããã®å¿çã¯JSON圢åŒã§åä¿¡ãããŸãã ç§ã¯ã¡ããã©ãããããŸãã-ç§ã¯ããã«æçš¿ããã®ã¯æ¥ããããã§ããããªãç²éãªã³ãŒããåŸãŸããã ãããŠæåéãä»æ¥ãç§ã¯trurl123ããçŽ æŽããããããã¯ã«åºããããjsã§MVCãåŠã¶å¿ èŠããããããããéçºãæŸæ£ããå¿ èŠãããããšã«æ°ä»ããŸããã
ã¹ããã3-ããŒã¿ã®è¿œå -PHP + Zend Framework
ç§ãä»äºã®ãã®éšåãåãäžãããšãããã©ãã«ã®å åã¯ãããŸããã§ããã Zend Frameworkã«ã¯ã Googleã®ãµãŒãã¹ãæäœããããã®APIå šäœãå«ãŸããŠããŸã ã ãããããã¹ãŠãããã»ã©ãã©è²ã«ãªã£ãããã§ã¯ãããŸããã äžè¬çã«ãç§ã¯èªåã§FTãæäœããããã®ã¯ã©ã¹ãäœæããå¿ èŠããããZend_Gdata_BaseãããŒã¹ãšããŠã Drupalã®åäœäžèœãªãœãªã¥ãŒã·ã§ã³ã䜿çšããŸããã
ã¯ã©ã¹ãã¡ã€ã«ã¯ããããããŠã³ããŒãã§ããŸã ã æ®å¿µãªããããã®ãã¡ã€ã«ã¯Zendæšæºã«æºæ ããŠãããã3ã€ã®ã¯ã©ã¹ãå«ãŸããŠããŸãããææžåã¯äžååã§ãã ããããããã¯æ©èœããŸãã
ããã䜿çšããã«ã¯ããã¡ã€ã«èªäœãšZend / Gdata / ClientLogin.phpãæ¥ç¶ããå¿ èŠããããŸãã
äŸïŒ
// ( ) $client = Zend_Gdata_ClientLogin::getHttpClient('your_login_here@gmail.com', 'your_pass_here', 'fusiontables'); // $base = new Zend_Gdata_Fusion($client); // $sql = "SELECT ROWID FROM 596524 WHERE id = 1;"; $rowdata = $base->query($sql)->get_array(); print_r($rowdata); // - API $newRowId = $base->insertRow('596524',array( 'id' => time(), 'name' => 'trird row', 'added' => date('n/j/y'), ) ); // $base->updateRow( '596524', //ID array('name' => 'new first row'), // $rowdata[1][0] //ROWID );
æãå±ããšããã¡ã€ã«ãæãåºããŠZend Proposalã«ã¢ããããŒãããŸãã
ãã1ã€ã®ãã€ã³ãïŒINSERT / UPDATEã³ãã³ããå®è¡ããå¿ èŠããªãå Žåãããšãã°ããã§èª¬æããããã«ãZend_Baseã䜿çšã§ããŸãã å®éãä»æ§ã«ããã°ãGETãªã¯ãšã¹ããä»ããŠSELECTã®ã¿ãå®è¡ã§ããŸãïŒ http://code.google.com/intl/en/apis/fusiontables/docs/developers_guide.html#Updating "...è¡ãæŽæ°ããã«ã¯ãèªèšŒæžã¿ã®POSTãéä¿¡ããŸãèŠæ±...ã
以äžã§ãã
PSïŒãã¡ãããããŒã«ãµãŒãã¹ã§åæ¥ãããžã§ã¯ããç¶ããããšã¯æå³ããªãããšã¯ç解ããŠããŸãããã¢ããªã±ãŒã·ã§ã³ãåæ¥åãããå ŽåïŒã€ãŸããååãªãŠãŒã¶ãŒãããŠãåçãåŸãæ¹æ³ãèŠã€ããå ŽåïŒãããã«ç§»è¡ããŸãç¬èªã®ãµãŒããŒã ãããŠãçŸæç¹ã§ç§ã¯ïŒ
-åæè²»çšãããããªãéåžžã«çŸããé«éãªã¢ããªã±ãŒã·ã§ã³ã
-ç§ã¯ãã¹ãŠãåãããã«éããã¹ãã¬ã¹äžã§ãæ©èœãããšä¿¡ããŠããŸãã
PPSïŒã¯ããã³ãŒããã€ã©ã€ã¿ãŒããã¬ãã¥ãŒæã«ã®ã¿ãã°ãããããšãé¡ã£ãŠããŸã
åç §ïŒ
Fusion Tables API- http://code.google.com/intl/en/apis/fusiontables/docs/developers_guide.html
Fusion Tablesã®SQLæ§æ-http://code.google.com/intl/en/apis/fusiontables/docs/developers_reference.html
Fusion Tables UI- http://tables.googlelabs.com/
Zend Gdata- http: //framework.zend.com/manual/en/zend.gdata.html
FTã䜿çšããããã®PHPã¯ã©ã¹-http://barahlo.semero.com/description/Zend_Gdata_Fusion.zip
UPD2ïŒããã¯ãã ã®äŒæ¥ã§ãïŒ ä»å€ã¯ææ¡ãæŽæ°ã ãä»ã§ã¯ORã®é¡äŒŒç©ããããŸãïŒ ç§ã¯ãŸã èªåã§ãã¹ãããŠããŸãããããã¹ãŠãããŸãããããšãé¡ã£ãŠããŸãã