Show Menu
Cheatography

mbe_queries Cheat Sheet (DRAFT) by

private

This is a draft cheat sheet. It is a work in progress and is not finished yet.

check_­sub­scr­ibe­r_a­cti­ve_­to_­ser­vic­e_group

input
msisdn, service_id
sql
select servic­e_id,id from mt_sub­scr­ibers where msisdn=? and active='y' and servic­e_id=?
if(!$s­ubs­cri­ber_id)
select servic­e_id,id from mt_sub­scr­ibers where msisdn=? and active='y' and service_id in(select id from services where servic­e_g­rou­p_id=?
return
$alrea­dy_­sub­_se­rvi­ce_­id,­$su­bsc­rib­er_id

get_mo­_sh­ort­cod­e_b­ase­d_o­n_s­erv­ice_id

input
service_id
sql
select mo_sho­rt_code from keywords where servic­e_id=? limit 1
return: $mo_sh­ort­_code
example: Synive­rseNlg5
if (!$mo_­sho­rt_­code)
select k.mo_s­hor­t_code from keywords k,carr­ier­_se­rvi­ce_­ove­rride cor where cor.ov­err­ide­_se­rvi­ce_id=? and cor.in­com­ing­_se­rvi­ce_­id=­k.s­erv­ice_id limit 1

get_me­ssa­ges­_ba­sed­_on­_se­rvice

input
$servi­ce_id, $svc_m­sg_­type_id
sql
select smm.id, smm.bi­lled, smm.tpoa, smm.ms­g_p­rio­rity, smm.sc_id, smm.cr­edi­t_v­alue, m.msg, mt.type, smt.sv­c_type, smm.delay, smm.de­lay­_mi­nutes from servic­e_m­sg_­matrix smm, messages m, messag­es_type mt, servic­e_m­sg_type smt where smm.se­rvi­ce_id=? and smm.sv­c_m­sg_­type_id in($sv­c_m­sg_­typ­e_id) and smm.ms­g_i­d=m.id and m.msg_­typ­e_i­d=mt.id and smm.sv­c_m­sg_­typ­e_i­d=s­mt.id order by smm.
return: $sth_msg
statement to the sql command

checkc­hec­k_s­hor­tco­de_­overide

purpose
check if there's short code override
input
$short­_co­de_id
sql
select c.inco­min­g_s­hor­t_c­ode_id, g.id from carrie­r_s­hor­tco­de_­ove­rride c,shor­t_codes sc,gat­eways g where c.inco­min­g_s­hor­t_c­ode­_id=? and c.inco­min­g_s­hor­t_c­ode­_id­=sc.id and sc.gat­ewa­y_i­d=g.id
return
$short­cod­e_o­ver­rid­e_id, $gatew­ay_id
 

get_se­rvi­ce_­group

input
service_id
sql
select servic­e_g­roup_id from services where id=?
return
servic­e_g­roup_id

get_se­rvi­ce_url

input
service_id
sql
select c.sub_­uri­,s.w­ap­_ti­tle­,sc.sh­ort­_code from services s,shor­t_codes sc,company c where s.id=? and s.mt_s­hor­t_c­ode­_id­=sc.id and s.comp­any­_id­=c.id
return
$uri,$­tit­le,$sc

add_su­bsc­riber

sql
insert into mt_sub­scr­ibers ( msisdn, active, subscr­ipt­ion­_date, keyword, short_­code, mobile­_ca­rri­er_id, servic­e_id, source, sub_sh­ort­_code, user_ip, affili­ate­_uri, refere­nce­_se­rvi­ce_id, email) values (?,'y'­,no­w()­,?,­?,?­,?,­?,?­,?,­?,?,?)
return
$id

add_su­bsc­rib­ers­_tiny

input
$mt_su­bsc­rib­er_id, $short_uri
sql
insert into mt_sub­scr­ibe­rs_­tin­y_u­ri(­mt_­sub­scr­ibe­r_id, shortend) values­(?,?)
shortend
random 6 characters string
return $short­end_uri
short_uri . $shortend
 

get_ap­pli­cat­ion­_se­ttings

input
app_name
sql
select app_m.s­vc­_ms­g_t­ype­_id­,ap­p_p.ms­g_p­rio­rit­y_i­d,a­pp.id from applic­ations app,ap­pli­cat­ion­_msgs app_m,­app­lic­ati­on_­pri­ority app_p where app.name=? and app.id­=ap­p_m.app_id and app.id­=ap­p_p.app_id
return
$msg_p­rio­rit­y_i­d,$­msg­_ty­pe_­id,­$app_id
note
$msg_t­ype_id: list of ids separate by ','

set_cu­sto­mer­_credit

input
$subsc­rib­er_id, $credi­t_value
sql
insert into custom­er_­credit (mt_su­bsc­rib­er_­id,­credit) values (?,?)
return: $id
id of record table custom­er_­credit

insert­Sub­scr­iberLog

input
$s_id, $key_id, $billed, $kw, $short­_code, $mobil­e_c­arr­ier_id
sql
insert into mt_sub­scr­ipt­ion_log (mt_su­bsc­rib­er_id, key_id, billed, reques­t_date, keyword, short_­code, mobile­_ca­rri­er_id) values (?,?,?­,no­w()­,?,?,?)
return
$billed_id

get_ga­tew­ayi­d_a­pi_name

input
short_­code_id
sql
select sc.gat­ewa­y_id, g.api_­name, sc.premium from short_­codes sc, gateways g where sc.id=? and sc.gat­ewa­y_i­d=g.id
return
$gatew­ay_id, $api_name, $premium
example
5, sybase, y