<?php
$o['tables']['search'] = configs::get('db', 'table_prefix').'cache_nbsearch';
$o['tables']['searchrel'] = configs::get('db', 'table_prefix').'cache_nbsearchrel';
$o['tables']['report'] = configs::get('db', 'table_prefix').'cache_nbreport';
$o['tables']['nfo'] = configs::get('db', 'table_prefix').'cache_nbnfo';
$o['tables']['imdb'] = configs::get('db', 'table_prefix').'cache_imdb';
$o['structs']['search'] = Array('ref' => 'ref',
'date' => 'date');
$o['structs']['searchrel'] = Array('ref' => 'ref',
'id' => 'id');
$o['structs']['report'] = Array('id' => 'id',
'report'=> 'report',
'date' => 'date');
$o['structs']['nfo'] = Array('id' => 'id',
'nfo' => 'nfo',
'date' => 'date');
$o['structs']['imdb'] = Array('id' => 'id',
'meta' => 'meta',
'date' => 'date');
$o['mysql'] = Array( 'search_iscached' => Array ('ispresent', "SELECT COUNT(*) FROM `%table_search%` WHERE %struct_search_ref%='%arg_id%'"),
'report_iscached' => Array ('ispresent', "SELECT COUNT(*) FROM `%table_report%` WHERE %struct_report_id%='%arg_id%'"),
'nfo_iscached' => Array ('ispresent', "SELECT COUNT(*) FROM `%table_nfo%` WHERE %struct_nfo_id%='%arg_id%'"),
'imdb_iscached' => Array ('ispresent', "SELECT COUNT(*) FROM `%table_imdb%` WHERE %struct_imdb_id%='%arg_id%'"),
'search_isexpired' => Array ('ispresent', "SELECT COUNT(*) FROM `%table_search%` WHERE %struct_search_ref%='%arg_id%' AND %struct_search_date% < '%arg_limit%'"),
'report_isexpired' => Array ('ispresent', "SELECT COUNT(*) FROM `%table_report%` WHERE %struct_report_id%='%arg_id%' AND %struct_report_date% < '%arg_limit%'"),
'nfo_isexpired' => Array ('ispresent', "SELECT COUNT(*) FROM `%table_nfo%` WHERE %struct_nfo_id%='%arg_id%' AND %struct_nfo_date% < '%arg_limit%'"),
'imdb_isexpired' => Array ('ispresent', "SELECT COUNT(*) FROM `%table_imdb%` WHERE %struct_imdb_id%='%arg_id%' AND %struct_imdb_date% < '%arg_limit%'"),
'insert_search' => Array ('insert', "INSERT INTO `%table_search%` (%struct_search_ref%, %struct_search_date%) VALUES ('%arg_ref%', '%arg_time%')"),
'insert_report' => Array ('insert', "INSERT INTO `%table_report%` (%struct_report_id%, %struct_report_report%, %struct_report_date%) VALUES ('%arg_id%', '%arg_data%', '%arg_time%')"),
'append_result' => Array ('insert', "INSERT INTO `%table_searchrel%` (%struct_searchrel_ref%, %struct_searchrel_id%) VALUES ('%arg_ref%', '%arg_id%')"),
'insert_nfo' => Array ('insert', "INSERT INTO `%table_nfo%` (%struct_nfo_id%, %struct_nfo_nfo%, %struct_nfo_date%) VALUES ('%arg_id%', '%arg_data%', '%arg_time%')"),
'insert_imdb' => Array ('insert', "INSERT INTO `%table_imdb%` (%struct_imdb_id%, %struct_imdb_meta%, %struct_imdb_date%) VALUES ('%arg_id%', '%arg_data%', '%arg_time%')"),
'drop_results' => Array ('delete', "DELETE %table_search%.*,%table_searchrel%.* FROM `%table_search%`, `%table_searchrel%` WHERE %struct_search_ref%='%arg_ref%' AND %struct_searchrel_ref%='%arg_ref%'"),
'drop_report' => Array ('delete', "DELETE FROM `%table_report%` WHERE %struct_report_id%='%arg_id%'"),
'fetch_results' => Array ('fetchfield', "SELECT %struct_searchrel_id% FROM `%table_searchrel%` WHERE %struct_searchrel_ref%='%arg_ref%' ORDER BY `unic` ASC LIMIT %arg_start%, %arg_end%"),
'count_results' => Array ('getcount', "SELECT COUNT(*) FROM `%table_searchrel%` WHERE %struct_searchrel_ref%='%arg_ref%'"),
'get_report' => Array ('getonefield',"SELECT %struct_report_report% FROM `%table_report%` WHERE %struct_report_id%='%arg_id%' LIMIT 1"),
'get_nfo' => Array ('getonefield',"SELECT %struct_nfo_nfo% FROM `%table_nfo%` WHERE %struct_nfo_id%='%arg_id%' LIMIT 1"),
'get_imdb' => Array ('getonefield',"SELECT %struct_imdb_meta% FROM `%table_imdb%` WHERE %struct_imdb_id%='%arg_id%' LIMIT 1"),
'expire_search' => Array ('delete', "DELETE %table_search%.*,%table_searchrel%.* FROM `%table_search%`, `%table_searchrel%` WHERE %struct_search_date% < '%arg_limit%' AND %struct_searchrel_ref%=%struct_search_ref%"),
'expire_report' => Array ('delete', "DELETE FROM `%table_report%` WHERE %struct_report_date% < '%arg_limit%'"),
'expire_nfo' => Array ('delete', "DELETE FROM `%table_nfo%` WHERE %struct_nfo_date% < '%arg_limit%'"),
'expire_imdb' => Array ('delete', "DELETE FROM `%table_imdb%` WHERE %struct_imdb_date% < '%arg_limit%'"),
'update_report_date'=> Array ('update', "UPDATE `%table_report%` SET %struct_report_date%='%arg_time%' WHERE %struct_report_id%='%arg_id%'"),
);
$o['create']['mysql']['search'] = "CREATE TABLE `%table%` ( `%struct_ref%` varchar(32) NOT NULL,
`%struct_date%` int(16) NOT NULL ) ENGINE=MyISAM DEFAULT CHARSET=utf8;";
$o['create']['mysql']['searchrel'] = "CREATE TABLE `%table%` ( `unic` bigint(16) NOT NULL auto_increment,
`%struct_ref%` varchar(32) NOT NULL,
`%struct_id%` varchar(32) NOT NULL, PRIMARY_KEY(`unic`)) ENGINE=MyISAM DEFAULT CHARSET=utf8;";
$o['create']['mysql']['report'] = "CREATE TABLE `%table%` ( `%struct_id%` varchar(32) NOT NULL,
`%struct_date%` int(16) NOT NULL,
`%struct_report%` blob NOT NULL ) ENGINE=MyISAM DEFAULT CHARSET=utf8;";
$o['create']['mysql']['nfo'] = "CREATE TABLE `%table%` ( `%struct_id%` varchar(32) NOT NULL,
`%struct_date%` int(16) NOT NULL,
`%struct_nfo%` blob NOT NULL ) ENGINE=MyISAM DEFAULT CHARSET=utf8;";
$o['create']['mysql']['imdb'] = "CREATE TABLE `%table%` ( `%struct_id%` varchar(32) NOT NULL,
`%struct_date%` int(16) NOT NULL,
`%struct_meta%` blob NOT NULL ) ENGINE=MyISAM DEFAULT CHARSET=utf8;";
$o['create']['sqlite'] = "";
return $o;