标签:
这个系列上一篇还是2012-08-01,而开始研究他应该在2011年了。时间过得很快,今年已经是2015年了。这个现在看技术含量已经不是很高了,甚至还有点瑕疵。不管怎么样,我还是先讲我原来的设计想法吧。
根据我当初的设计嵌入式,到数据库这一个阶段我用同一个存储过程设计了多个数据库写法,最先完善的用的是mysql,它主要工作就是将前端传递过来的数据进行处理分发,程序端不需要太多的逻辑(我当初的想法)直接作为一个传送带,将数据发送到数据库中。下面是我的mysql代码:
1 # MySQL-Front 5.0 (Build 1.0) 2 3 /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE */; 4 /*!40101 SET SQL_MODE=‘NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION‘ */; 5 /*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES */; 6 /*!40103 SET SQL_NOTES=‘ON‘ */; 7 8 9 # Host: 127.0.0.1 Database: mincount 10 # ------------------------------------------------------ 11 # Server version 5.0.27-community-nt-log 12 13 DROP DATABASE IF EXISTS `mincount`; 14 CREATE DATABASE `mincount` /*!40100 DEFAULT CHARACTER SET utf8 */; 15 USE `mincount`; 16 17 # 18 # Table structure for table min_tracker 19 # 20 21 CREATE TABLE `min_tracker` ( 22 `Id` int(11) NOT NULL auto_increment, 23 `tracker` text COMMENT ‘传入字符串‘, 24 `tacker_time` timestamp NULL default CURRENT_TIMESTAMP COMMENT ‘插入时间‘, 25 PRIMARY KEY (`Id`) 26 ) ENGINE=MyISAM AUTO_INCREMENT=278 DEFAULT CHARSET=utf8 COMMENT=‘传递参数表,可做数据备份使用‘; 27 28 # 29 # Table structure for table minc_ip 30 # 31 32 CREATE TABLE `minc_ip` ( 33 `Id` int(11) NOT NULL auto_increment, 34 `ip_start` int(10) unsigned default NULL, 35 `ip_end1` int(10) unsigned default NULL, 36 `address` varchar(50) default NULL, 37 `particular_address` varchar(255) default NULL, 38 PRIMARY KEY (`Id`), 39 KEY `新建索引` (`ip_start`,`ip_end1`) 40 ) ENGINE=MyISAM AUTO_INCREMENT=435443 DEFAULT CHARSET=utf8; 41 42 # 43 # Table structure for table minc_ip_string 44 # 45 46 CREATE TABLE `minc_ip_string` ( 47 `Id` int(11) NOT NULL auto_increment, 48 `ip_start` varchar(25) default NULL, 49 `ip_end` varchar(25) default NULL, 50 `address` varchar(50) default NULL, 51 `particular_address` varchar(255) default NULL, 52 PRIMARY KEY (`Id`), 53 KEY `新建索引` (`ip_start`,`ip_end`) 54 ) ENGINE=MyISAM AUTO_INCREMENT=435443 DEFAULT CHARSET=utf8; 55 56 # 57 # Table structure for table minc_log_action 58 # 59 60 CREATE TABLE `minc_log_action` ( 61 `idaction` int(10) unsigned NOT NULL auto_increment COMMENT ‘被访问网页id‘, 62 `name` text COMMENT ‘网页名称或url‘, 63 `hash` int(10) unsigned default NULL COMMENT ‘hash值‘, 64 `type` tinyint(3) unsigned default NULL COMMENT ‘是标题、url、下载、广告等类型‘, 65 PRIMARY KEY (`idaction`), 66 KEY `index_type_hash` (`type`,`hash`) 67 ) ENGINE=MyISAM AUTO_INCREMENT=21 DEFAULT CHARSET=utf8 COMMENT=‘存放网页资源‘; 68 69 # 70 # Table structure for table minc_log_link_visit_action 71 # 72 73 CREATE TABLE `minc_log_link_visit_action` ( 74 `idlink_va` int(11) NOT NULL auto_increment, 75 `idsite` int(10) unsigned default NULL COMMENT ‘用户所在网站id‘, 76 `idvisitor` binary(16) default NULL, 77 `server_time` datetime default NULL COMMENT ‘用户访问时服务器时间‘, 78 `idvisit` int(10) unsigned default NULL COMMENT ‘用户id(关联log_link_visit_action)‘, 79 `idaction_url` int(10) unsigned default NULL COMMENT ‘用户所点击网页的url(关联log_aciton)‘, 80 `idaction_url_ref` int(10) unsigned default NULL COMMENT ‘用户所点击网页上一个网页url(关联log_action)‘, 81 `idaction_name` int(10) unsigned default NULL COMMENT ‘用户所点击网页的标题(关联log_aciton)‘, 82 `idaction_name_ref` int(10) unsigned default NULL COMMENT ‘用户所点击网页上一个网页标题(关联log_action)‘, 83 `time_spent_ref_action` int(10) unsigned default NULL COMMENT ‘用户在本网页之前一个网页访问时间‘, 84 PRIMARY KEY (`idlink_va`), 85 KEY `index_idvisit` (`idvisit`), 86 KEY `index_idsite_servertime` (`idsite`,`server_time`) 87 ) ENGINE=MyISAM AUTO_INCREMENT=608 DEFAULT CHARSET=utf8 COMMENT=‘保存用户点击‘; 88 89 # 90 # Table structure for table minc_log_visit 91 # 92 93 CREATE TABLE `minc_log_visit` ( 94 `idvisit` int(10) unsigned NOT NULL auto_increment COMMENT ‘一次访问ID‘, 95 `idsite` int(10) unsigned default NULL COMMENT ‘访问站点ID‘, 96 `idvisitor` binary(16) default NULL, 97 `visitor_localtime` datetime default NULL COMMENT ‘访问者本地时间‘, 98 `visitor_returning` tinyint(1) NOT NULL, 99 `visitor_count_visits` smallint(5) unsigned default ‘1‘ COMMENT ‘当前访问访问总次数‘, 100 `visitor_days_since_last` smallint(5) unsigned NOT NULL, 101 `visitor_days_since_order` smallint(5) unsigned NOT NULL, 102 `visitor_days_since_first` smallint(5) unsigned NOT NULL, 103 `visit_first_action_time` datetime default NULL COMMENT ‘用户访问的开始时间‘, 104 `visit_last_action_time` datetime default NULL COMMENT ‘用户最后一次访问时间‘, 105 `visit_exit_idaction_url` int(11) unsigned default NULL COMMENT ‘用户离开网站网页url‘, 106 `visit_exit_idaction_name` int(11) unsigned default NULL COMMENT ‘用户离开网站网页标题‘, 107 `visit_entry_idaction_url` int(11) unsigned default NULL COMMENT ‘用户进入网站网页url‘, 108 `visit_entry_idaction_name` int(11) unsigned default NULL COMMENT ‘用户进入网站网页标题‘, 109 `visit_total_actions` smallint(5) unsigned default NULL COMMENT ‘用户此次访问总点击数‘, 110 `visit_total_time` smallint(5) unsigned default ‘0‘ COMMENT ‘用户访问总时间‘, 111 `visit_goal_converted` tinyint(1) NOT NULL, 112 `visit_goal_buyer` tinyint(1) NOT NULL, 113 `referer_type` tinyint(1) unsigned default NULL COMMENT ‘用户从外部进入网站网站类型‘, 114 `referer_name` varchar(70) default NULL COMMENT ‘用户从外部进入网站网页标题‘, 115 `referer_url` text NOT NULL COMMENT ‘用户从外部进入网站网页url‘, 116 `referer_keyword` varchar(255) default NULL, 117 `config_id` binary(8) NOT NULL, 118 `config_os` varchar(10) default NULL COMMENT ‘用户操作系统‘, 119 `config_browser_name` varchar(50) default NULL COMMENT ‘用户浏览器名称‘, 120 `config_browser_version` varchar(20) default NULL COMMENT ‘用户浏览器版本‘, 121 `config_resolution` varchar(9) NOT NULL, 122 `config_pdf` tinyint(1) default NULL COMMENT ‘用户浏览器是否支持pdf‘, 123 `config_flash` tinyint(1) default NULL COMMENT ‘用户浏览器是否支持flash‘, 124 `config_java` tinyint(1) default NULL COMMENT ‘用户浏览器是否支持java‘, 125 `config_director` tinyint(1) default NULL COMMENT ‘用户浏览器是否支持director‘, 126 `config_quicktime` tinyint(1) NOT NULL, 127 `config_realplayer` tinyint(1) default NULL COMMENT ‘用户浏览器是否支持realplayer‘, 128 `config_windowsmedia` tinyint(1) default NULL COMMENT ‘用户浏览器是否支持windowsmedia‘, 129 `config_gears` tinyint(1) NOT NULL, 130 `config_silverlight` tinyint(1) default NULL COMMENT ‘用户浏览器是否支持silverlight‘, 131 `config_cookie` tinyint(1) default NULL COMMENT ‘用户浏览器是否支持cookie‘, 132 `location_ip` varbinary(16) default NULL COMMENT ‘用户ip值‘, 133 `location_browser_lang` varchar(20) default NULL COMMENT ‘用户浏览器支持的语言‘, 134 `location_country` char(3) default NULL COMMENT ‘用户所在国家‘, 135 `location_continent` char(3) NOT NULL, 136 `location_provider` varchar(100) default NULL, 137 `location_addr` varchar(255) default ‘未知‘, 138 PRIMARY KEY (`idvisit`), 139 KEY `index_idsite_config_datetime` (`idsite`,`config_id`,`visit_last_action_time`), 140 KEY `index_idsite_datetime` (`idsite`,`visit_last_action_time`), 141 KEY `index_idsite_idvisitor` (`idsite`,`idvisitor`) 142 ) ENGINE=MyISAM AUTO_INCREMENT=67 DEFAULT CHARSET=utf8 COMMENT=‘保存用户信息‘; 143 144 # 145 # Table structure for table minc_site 146 # 147 148 CREATE TABLE `minc_site` ( 149 `id` int(11) unsigned NOT NULL auto_increment, 150 `idsite` int(10) unsigned NOT NULL default ‘1‘ COMMENT ‘站点id‘, 151 `name` varchar(90) default NULL COMMENT ‘站点名称‘, 152 `main_url` varchar(255) default NULL COMMENT ‘主要的url‘, 153 `ts_created` timestamp NULL default NULL, 154 `ecommerce` tinyint(3) default ‘0‘ COMMENT ‘电子商务‘, 155 `timezone` varchar(50) default NULL COMMENT ‘时间区‘, 156 `currency` char(3) default NULL COMMENT ‘流通‘, 157 `excluded_ips` text NOT NULL COMMENT ‘排除的ip‘, 158 `excluded_parameters` varchar(255) default NULL COMMENT ‘排除的参数‘, 159 `group` varchar(250) NOT NULL, 160 `feedburnerName` varchar(100) default NULL COMMENT ‘RSS托管服务网站名‘, 161 PRIMARY KEY (`id`) 162 ) ENGINE=MyISAM AUTO_INCREMENT=10 DEFAULT CHARSET=utf8 COMMENT=‘保存网站信息‘; 163 164 # 165 # Source for procedure mincount_core 166 # 167 168 CREATE PROCEDURE `mincount_core`( 169 in _tracker varchar(2000) /*传入参数-暂将传入参数上限设为1000,不知道text怎么会有问题*/ 170 ) 171 COMMENT ‘mincount数据分析存储核心‘ 172 BEGIN 173 /*1<-->1320201097<-->test<-->http://localhost/test/test.html<--><-->2130706433*/ 174 /***********************************1.传递参数变量定义************************************/ 175 declare _idsite int; /*1.网站id*/ 176 declare _localtime datetime; /*2.客户端时间*/ 177 declare _name text; /*3.网页标题*/ 178 declare _url text; /*4.网页url*/ 179 declare _referer_url text; /*5.前一访问url*/ 180 declare _location_ip varbinary(16); /*6.本地ip*/ 181 declare _referer_name varchar(70); /*7.前一访问主机名*/ 182 declare _idvisitor binary(16); /*8.cookie id*/ 183 declare _host varchar(50); /*9当前主机*/ 184 declare _sl tinyint; 185 declare _gears tinyint; 186 declare _java tinyint; 187 declare _flash tinyint; 188 declare _director tinyint; 189 declare _wma tinyint; 190 declare _realplayer tinyint; 191 declare _qt tinyint; 192 declare _pdf tinyint; 193 declare _cookie tinyint; 194 declare _res varchar(9); 195 declare _os varchar(10); /*操作系统*/ 196 declare _browsername varchar(50); /*浏览器名称*/ 197 declare _browserver varchar(10); /*浏览器版本*/ 198 declare _keyword varchar(255); /*关键字*/ 199 declare _browerlang varchar(20); /*浏览器语言*/ 200 declare _locationaddr varchar(255); /*用户地址*/ 201 declare _num tinyint; /*中间变量*/ 202 declare _splitchar varchar(10); /*分隔字符串*/ 203 /************************************2.变量定义********************************************/ 204 declare curr_visit_id int; /*当前访问id*/ 205 declare curr_time bigint; /*当前访问服务器时间(num)*/ 206 declare _curr_time datetime; /*当前访问服务器时间(datetime)*/ 207 declare last_visit_time bigint; /*上一次访问的服务器时间(num)*/ 208 declare _last_visit_time datetime; /*上一次访问的服务器时间(num)*/ 209 declare discrepancy_time int; /*两次访问时间的差值*/ 210 declare curr_name_id int; /*当前网页标题id()*/ 211 declare curr_url_id int; /*当前网页urlid*/ 212 declare last_name_id int; /*上一次访问网页标题id*/ 213 declare last_url_id int; /*上一次访问网页urlid*/ 214 declare curr_main_url varchar(255); /*当前网站url*/ 215 declare _visitor_returning tinyint; /*是否是重访问*/ 216 declare _visitor_count_visits smallint; /*当前cookie访问数*/ 217 declare _visitor_days_since_last smallint;/*当前cookie距离上一次访问天数*/ 218 declare __visitor_days_since_last smallint;/*上一个cookie距离上一次访问天数*/ 219 declare _visitor_days_since_first smallint;/*当前cookie距离第一次访问天数*/ 220 221 /*************************************3.变量定义完毕***************************************/ 222 /*将传入参数字符串插入min_tracker*/ 223 insert into min_tracker(tracker)values(_tracker); 224 /*设置分隔值*/ 225 set _splitchar=‘<-->‘; 226 /**********************************************解析参数*******************************************************************/ 227 /*在考虑参数怎么样分割?使用“<-->”? 参数定义顺序和字符串连接顺序是一样的*/ 228 229 /*1.取得第一个参数*/ 230 select substring_index(_tracker,_splitchar,1) into _idsite; 231 /*2.取得第二个参数*/ 232 select instr(_tracker,_splitchar) into _num; 233 select insert(_tracker,1,_num+3,‘‘) into _tracker; 234 select FROM_UNIXTIME(substring_index(_tracker,_splitchar,1)) into _localtime; 235 /*3.取得第三个参数*/ 236 select instr(_tracker,_splitchar) into _num; 237 select insert(_tracker,1,_num+3,‘‘) into _tracker; 238 select substring_index(_tracker,_splitchar,1) into _name; 239 /*4.取得第四个参数*/ 240 select instr(_tracker,_splitchar) into _num; 241 select insert(_tracker,1,_num+3,‘‘) into _tracker; 242 select substring_index(_tracker,_splitchar,1) into _url; 243 /*5.取得第五个参数*/ 244 select instr(_tracker,_splitchar) into _num; 245 select insert(_tracker,1,_num+3,‘‘) into _tracker; 246 select substring_index(_tracker,_splitchar,1) into _referer_url; 247 /*6.取得第六个参数*/ 248 select instr(_tracker,_splitchar) into _num; 249 select insert(_tracker,1,_num+3,‘‘) into _tracker; 250 select substring_index(_tracker,_splitchar,1) into _referer_name; 251 /*7.取得第七个参数*/ 252 select instr(_tracker,_splitchar) into _num; 253 select insert(_tracker,1,_num+3,‘‘) into _tracker; 254 select substring_index(_tracker,_splitchar,1) into _idvisitor; 255 /*8.取得第八个参数*/ 256 select instr(_tracker,_splitchar) into _num; 257 select insert(_tracker,1,_num+3,‘‘) into _tracker; 258 select substring_index(_tracker,_splitchar,1) into _sl; 259 /*9.取得第九个参数*/ 260 select instr(_tracker,_splitchar) into _num; 261 select insert(_tracker,1,_num+3,‘‘) into _tracker; 262 select substring_index(_tracker,_splitchar,1) into _gears; 263 /*10.取得第十个参数*/ 264 select instr(_tracker,_splitchar) into _num; 265 select insert(_tracker,1,_num+3,‘‘) into _tracker; 266 select substring_index(_tracker,_splitchar,1) into _java; 267 /*11.取得第十一个参数*/ 268 select instr(_tracker,_splitchar) into _num; 269 select insert(_tracker,1,_num+3,‘‘) into _tracker; 270 select substring_index(_tracker,_splitchar,1) into _flash; 271 /*12.取得第十二个参数*/ 272 select instr(_tracker,_splitchar) into _num; 273 select insert(_tracker,1,_num+3,‘‘) into _tracker; 274 select substring_index(_tracker,_splitchar,1) into _director; 275 /*13.取得第十三个参数*/ 276 select instr(_tracker,_splitchar) into _num; 277 select insert(_tracker,1,_num+3,‘‘) into _tracker; 278 select substring_index(_tracker,_splitchar,1) into _wma; 279 /*14.取得第十四个参数*/ 280 select instr(_tracker,_splitchar) into _num; 281 select insert(_tracker,1,_num+3,‘‘) into _tracker; 282 select substring_index(_tracker,_splitchar,1) into _realplayer; 283 /*15.取得第十五个参数*/ 284 select instr(_tracker,_splitchar) into _num; 285 select insert(_tracker,1,_num+3,‘‘) into _tracker; 286 select substring_index(_tracker,_splitchar,1) into _qt; 287 /*16.取得第十六个参数*/ 288 select instr(_tracker,_splitchar) into _num; 289 select insert(_tracker,1,_num+3,‘‘) into _tracker; 290 select substring_index(_tracker,_splitchar,1) into _pdf; 291 /*17.取得第十七个参数*/ 292 select instr(_tracker,_splitchar) into _num; 293 select insert(_tracker,1,_num+3,‘‘) into _tracker; 294 select substring_index(_tracker,_splitchar,1) into _cookie; 295 /*18.取得第十八个参数*/ 296 select instr(_tracker,_splitchar) into _num; 297 select insert(_tracker,1,_num+3,‘‘) into _tracker; 298 select substring_index(_tracker,_splitchar,1) into _res; 299 /*19.取得第十九个参数*/ 300 select instr(_tracker,_splitchar) into _num; 301 select insert(_tracker,1,_num+3,‘‘) into _tracker; 302 select substring_index(_tracker,_splitchar,1) into _os; 303 /*20.取得第二十个参数*/ 304 select instr(_tracker,_splitchar) into _num; 305 select insert(_tracker,1,_num+3,‘‘) into _tracker; 306 select substring_index(_tracker,_splitchar,1) into _browsername; 307 /*21.取得第二十一个参数*/ 308 select instr(_tracker,_splitchar) into _num; 309 select insert(_tracker,1,_num+3,‘‘) into _tracker; 310 select substring_index(_tracker,_splitchar,1) into _browserver; 311 /*22.取得第二十二个参数*/ 312 select instr(_tracker,_splitchar) into _num; 313 select insert(_tracker,1,_num+3,‘‘) into _tracker; 314 select substring_index(_tracker,_splitchar,1) into _keyword; 315 /*23.取得第二十三个参数*/ 316 select instr(_tracker,_splitchar) into _num; 317 select insert(_tracker,1,_num+3,‘‘) into _tracker; 318 select substring_index(_tracker,_splitchar,1) into _browerlang; 319 320 /*取得最后第二个参数*/ 321 select instr(_tracker,_splitchar) into _num; 322 select insert(_tracker,1,_num+3,‘‘) into _tracker; 323 select substring_index(_tracker,_splitchar,1) into _host; 324 /*取得最后一个个参数*/ 325 select instr(_tracker,_splitchar) into _num; 326 select insert(_tracker,1,_num+3,‘‘) into _tracker; 327 select substring_index(_tracker,_splitchar,1) into _location_ip; 328 329 /**********************************************end************************************************************************/ 330 /*根据idsite判断是否存在此网站用户*/ 331 /*这样一个判断注定了其只适用于嵌入式方式*/ 332 select main_url into curr_main_url from minc_site where idsite=_idsite and main_url=_host; 333 334 if(curr_main_url is not null) then 335 /*判断是否是当前网站*/ 336 /****************根据idvisit,ip 和 servertime 判断是否是一条新的访问select (SYSDATE()+0) into curr_time;*********************/ 337 /*日期格式的时间*/ 338 select SYSDATE() into _curr_time; 339 /*数字类型的时间*/ 340 select UNIX_TIMESTAMP(_curr_time) into curr_time; 341 342 select UNIX_TIMESTAMP(visit_last_action_time), 343 visit_last_action_time, 344 idvisit, 345 visit_exit_idaction_url, 346 visit_exit_idaction_name, 347 visitor_count_visits, 348 visitor_days_since_last 349 into 350 last_visit_time, 351 _last_visit_time, 352 curr_visit_id, 353 last_url_id, 354 last_name_id, 355 _visitor_count_visits, 356 __visitor_days_since_last 357 from minc_log_visit 358 where idsite=_idsite 359 and location_ip=_location_ip 360 and idvisitor=_idvisitor order by idvisit desc limit 0,1; 361 set discrepancy_time=curr_time-last_visit_time; 362 /******************************END********************************************************/ 363 364 /****************根据idvisit,name,url判断网页是否被访问过*********************************/ 365 /*网页标题id type=4*/ 366 select idaction into curr_name_id from minc_log_action where name=_name and type=4 and hash=CRC32(_name); 367 /*网页urlid type=1*/ 368 select idaction into curr_url_id from minc_log_action where name=_url and type=1 and hash=CRC32(_url); 369 if curr_name_id is null then 370 insert into minc_log_action (name,hash,type)values(_name,CRC32(_name),4); 371 /*获取已有网页标题的id*/ 372 select idaction into curr_name_id from minc_log_action where name=_name; 373 end if; 374 if curr_url_id is null then 375 insert into minc_log_action (name,hash,type)values(_url,CRC32(_url),1); 376 /*获取已有网页url的id*/ 377 select idaction into curr_url_id from minc_log_action where name=_url; 378 end if; 379 380 /******************************END********************************************************/ 381 if last_visit_time is null or discrepancy_time>1800 then 382 /*1.新的访问*/ 383 /*关于重返访问部分参数值*/ 384 if last_visit_time is not null then 385 set _visitor_count_visits=_visitor_count_visits+1; 386 set _visitor_days_since_last=TO_DAYS(_curr_time)-TO_DAYS(_last_visit_time); 387 set _visitor_days_since_first=__visitor_days_since_last+_visitor_days_since_last; 388 set _visitor_returning=1; 389 else 390 set _visitor_count_visits=1; 391 set _visitor_days_since_last=0; 392 set _visitor_days_since_first=0; 393 set _visitor_returning=0; 394 end if; 395 /*1.1 查看网页是否被记录过-已完成*/ 396 /*获取用户地址*/ 397 select address into _locationaddr from minc_ip as m where _location_ip>=ip_start and _location_ip<=ip_end1;/*where location_ip>=ip_start and location_ip<=ip_end*/ 398 /*1.2 将数据插入访问表*/ 399 insert into minc_log_visit(idsite, 400 idvisitor, 401 visitor_localtime, 402 visitor_returning, 403 visitor_count_visits, 404 visitor_days_since_last, 405 visitor_days_since_first, 406 visit_first_action_time, 407 visit_last_action_time, 408 visit_exit_idaction_url, 409 visit_exit_idaction_name, 410 visit_entry_idaction_url, 411 visit_entry_idaction_name, 412 visit_total_actions, 413 visit_total_time, 414 referer_name, 415 referer_url, 416 referer_keyword, 417 config_os, 418 config_browser_name, 419 config_browser_version, 420 config_resolution, 421 config_pdf, 422 config_flash, 423 config_java, 424 config_director, 425 config_quicktime, 426 config_realplayer, 427 config_windowsmedia, 428 config_gears, 429 config_silverlight, 430 config_cookie, 431 location_ip, 432 location_browser_lang, 433 location_addr 434 )values(_idsite, 435 _idvisitor, 436 _localtime, 437 _visitor_returning, 438 _visitor_count_visits, 439 _visitor_days_since_last, 440 _visitor_days_since_first, 441 _curr_time, 442 _curr_time, 443 curr_url_id, 444 curr_name_id, 445 curr_url_id, 446 curr_name_id, 447 1, 448 0, 449 _referer_name, 450 _referer_url, 451 _keyword, 452 _os, 453 _browsername, 454 _browserver, 455 _res, 456 _pdf, 457 _flash, 458 _java, 459 _director, 460 _qt, 461 _realplayer, 462 _wma, 463 _gears, 464 _sl, 465 _cookie, 466 _location_ip, 467 _browerlang, 468 _locationaddr 469 ); 470 select idvisit into curr_visit_id from minc_log_visit 471 where idsite=_idsite 472 and location_ip=_location_ip 473 and idvisitor=_idvisitor 474 and visit_last_action_time=_curr_time; 475 /*1.3 将数据插入点击表*/ 476 insert into minc_log_link_visit_action(idsite, 477 idvisitor, 478 server_time, 479 idvisit, 480 idaction_url, 481 idaction_url_ref, 482 idaction_name, 483 idaction_name_ref, 484 time_spent_ref_action 485 )values(_idsite, 486 _idvisitor, 487 _curr_time, 488 curr_visit_id, 489 curr_url_id, 490 0, 491 curr_name_id, 492 0, 493 0 494 ); 495 else 496 /*2.旧的访问*/ 497 /*2.1 查看网页是否被记录过-一已完成*/ 498 499 /*2.3 将数据插入点击表*/ 500 insert into minc_log_link_visit_action(idsite, 501 idvisitor, 502 server_time, 503 idvisit, 504 idaction_url, 505 idaction_url_ref, 506 idaction_name, 507 idaction_name_ref, 508 time_spent_ref_action 509 )values(_idsite, 510 _idvisitor, 511 _curr_time, 512 curr_visit_id, 513 curr_url_id, 514 last_url_id, 515 curr_name_id, 516 last_name_id, 517 discrepancy_time 518 ); 519 /*2.2 将数据更新访问表*/ 520 update minc_log_visit set visit_last_action_time=_curr_time, 521 visit_exit_idaction_url=curr_url_id, 522 visit_exit_idaction_name=curr_name_id, 523 visit_total_actions=visit_total_actions+1, 524 visit_total_time=visit_total_time+discrepancy_time 525 where idvisit=curr_visit_id; 526 527 528 end if; 529 end if; 530 531 END; 532 533 534 # 535 # Source for procedure mincount_test 536 # 537 538 CREATE PROCEDURE `mincount_test`(in _tracker varchar(1000)) 539 COMMENT ‘测试‘ 540 BEGIN 541 insert into min_tracker (tracker)values(_tracker); 542 543 END; 544 545 546 /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; 547 /*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
完结:这个系列只是提供了大部分的核心源码,意在希望程序员能够迅速的自己开发一套流量统计系统,而不再依赖第三方产品。合久必分,分久必合,我相信总有一天会有人需要它。
标签:
原文地址:http://www.cnblogs.com/3cKing/p/4475423.html