library("RSQLite")
library("sqldf")
library("tcltk")

#connect to the database
db <- dbConnect(SQLite(), dbname="../input/database.sqlite")
#List of tables
dbListTables(db)

#Load data
#trainSearchStream<-dbGetQuery(db, "SELECT trainSearchStream.SearchID,trainSearchStream.AdID,trainSearchStream.Position,trainSearchStream.objectType, trainSearchStream.HistCTR,trainSearchStream.IsClick,SearchInfo.SearchDate, SearchInfo.UserID,SearchInfo.CategoryID as SearchCategoryID,AdsInfo.Price,AdsInfo.LocationID,AdsInfo.CategoryID FROM trainSearchStream, SearchInfo, UserInfo, AdsInfo where trainSearchStream.SearchID = SearchInfo.SearchID and SearchInfo.UserID=UserInfo.UserID and trainSearchStream.AdID=AdsInfo.AdID and AdsInfo.IsContext=1 limit 3000000")
#testSearchStream<-dbGetQuery(db, "SELECT testSearchStream.TestId, testSearchStream.Position, testSearchStream.HistCTR,AdsInfo.Price,AdsInfo.LocationID,AdsInfo.CategoryID, SearchInfo.UserID, SearchInfo.CategoryID as SearchCategoryID FROM testSearchStream, SearchInfo, AdsInfo where testSearchStream.SearchID = SearchInfo.SearchID and testSearchStream.AdID=AdsInfo.AdID and AdsInfo.IsContext=1 ")

test_<-dbGetQuery(db,"select * from trainSearchStream where SearchID <=40000000")
#test_<-dbGetQuery(db,"select * from trainSearchStream limit 10000000")
length(test_$SearchID)


