-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsql_stmt.go
391 lines (356 loc) · 7.85 KB
/
sql_stmt.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
package main
const sqlStmtQueryLoginInfo = `
select
user_id, pwdhash from player
where
lower(user_name) = lower(?1) or email = ?1
`
const sqlStmtToggleUncap = `
update part_stats
set is_uncapped_override =
case when is_uncapped_override = 't' then
'f'
else
't'
end
where user_id = ?1 and part_id = ?2
`
const sqlStmtQueryDLInfo = `
select
song.song_id,
song.checksum as "audio_checksum",
ifnull(song.remote_dl, '') as "song_dl",
cast(chart_info.difficulty as text) as "difficulty",
chart_info.checksum as "chart_checksum",
ifnull(chart_info.remote_dl, '') as "chart_dl"
from
%s, song, chart_info
where
pur.user_id = ?1
and song.song_id = chart_info.song_id
and %s
and (song.remote_dl = 't' or chart_info.remote_dl = 't')
%s
`
const sqlStmtOwnedChar = `
select
part_id,
ifnull(is_uncapped_override, '') as uncapped_override,
ifnull(is_uncapped, '') as uncapped,
overdrive,
prog,
frag,
prog_tempest,
part_stats.lv,
part_stats.exp_val,
level_exp.exp_val as level_exp
from
part_stats, level_exp
where
part_stats.user_id = ?1
and part_stats.lv = level_exp.lv
`
const sqlStmtCharStaticStats = `
select
ifnull(v.part_id, -1) as has_voice,
ifnull(skill_id, '') as skill,
ifnull(skill_id_uncap, '') as skill_uncap,
ifnull(skill_requires_uncap, '') skill_requires_uncap,
skill_unlock_level,
part_name,
char_type
from
partner p left outer join part_voice v on p.part_id = v.part_id
where
p.part_id = ?
`
const sqlStmtSingleCharCond = `and part_stats.part_id = %d`
const sqlStmtChangeChar = `
update
player
set
partner = ?1, is_skill_sealed = ?2
where
user_id = ?3
`
const slqStmtGameInfo = `
select
cast(strftime('%s', 'now') as decimal),
max_stamina,
stamina_recover_tick,
core_exp,
ifnull(world_ranking_enabled, ''),
ifnull(is_byd_chapter_unlocked, '')
from
game_info
`
const sqlStmtLevelStep = `select lv, exp_val from level_exp`
const sqlStmtPackInfo = `
select
pack_name, price, orig_price, discount_from, discount_to
from
pack
`
const sqlStmtPackItem = `
select
item_id, item_type, is_available
from
pack_item
where
pack_name = ?
`
const sqlStmtReadBackupData = `select backup_data from data_backup where user_id = ?`
const sqlStmtWriteBackupDate = `update data_backup set backup_data = ?1 where user_id = ?2`
const sqlStmtScoreLookup = `
select
sc.played_date,
so.song_id,
so.title_local_en,
sc.difficulty,
c.rating as base_rating,
sc.score,
sc.shiny_pure,
sc.pure,
sc.far,
sc.lost,
sc.rating,
sc.health,
sc.clear_type
from
player p, best_score b, score sc, song so, chart_info c
where
p.user_code = ?
and p.user_id = b.user_id
and p.user_id = sc.user_id
and sc.played_date = b.played_date
and so.song_id = sc.song_id
and so.song_id = c.song_id
and c.difficulty = sc.difficulty
and c.rating * 100 > p.rating - 250
order by
sc.rating desc
`
const sqlStmtGetScoreLookupRating = `
with
best as (
select ROW_NUMBER () OVER (
order by rating desc
) row_num,
rating
from best_score b, score s
where b.user_id = ?1
and b.user_id = s.user_id
and b.played_date = s.played_date
),
recent as (
select rating
from recent_score r, score s
where r.user_id = ?1
and r.is_recent_10 = 't'
and r.user_id = s.user_id
and r.played_date = s.played_date
)
select
ifnull(b30, 0), ifnull(r10, 0)
from (
select ifnull(sum(rating), 0) / ifnull(count(rating), 1) b30
from best
where row_num <= 30
), (
select ifnull(sum(rating), 0) / ifnull(count(rating), 1) r10
from recent
)
`
const sqlStmtBaseRating = `
select rating from chart_info where song_id = ?1 and difficulty = ?2
`
const sqlStmtInsertScore = `
insert into score (
user_id,
played_date,
song_id,
difficulty,
score,
shiny_pure,
pure,
far,
lost,
rating,
health,
clear_type
) values(?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, ?11, ?12)
`
const sqlStmtLookupBestScore = `
select
s.score, s.played_date
from
best_score b, score s
where
b.user_id = ?1
and b.user_id = s.user_id
and b.played_date = s.played_date
and s.song_id = ?2
and s.difficulty = ?3
`
const sqlStmtInsertBestScore = `
insert into best_score(user_id, played_date) values(?1, ?2)
`
const sqlStmtReplaceBestScore = `
update best_score set played_date = ?1 where played_date = ?2
`
const sqlStmtLookupRecentScore = `
select
s.rating,
s.played_date,
(s.song_id || s.difficulty) iden,
r.is_recent_10
from
recent_score r, score s
where
r.user_id = ?1
and r.user_id = s.user_id
and r.played_date = s.played_date
`
const sqlStmtReplaceRecnetScore = `
update recent_score
set played_date = ?1, is_recent_10 = ?2
where user_id = ?3 and played_date = ?4
`
const sqlStmtInsertRecentScore = `
insert into recent_score(user_id, played_date, is_recent_10)
values(?1, ?2, ?3)
`
const sqlStmtComputeRating = `
with
best as (
select ROW_NUMBER () OVER (
order by rating desc
) row_num,
rating
from best_score b, score s
where b.user_id = ?1
and b.user_id = s.user_id
and b.played_date = s.played_date
),
recent as (
select rating
from recent_score r, score s
where r.user_id = ?1
and r.is_recent_10 = 't'
and r.user_id = s.user_id
and r.played_date = s.played_date
)
select
round((ifnull(b30, 0) + ifnull(r10, 0)) / (ifnull(b30_count, 1) + ifnull(r10_count, 1)) * 100)
from (
select sum(rating) b30, count(rating) b30_count from best
where row_num <= 30
), (
select sum(rating) r10, count(rating) r10_count from recent
)
`
const sqlStmtUpdateRating = `
update player set rating = ?1 where user_id = ?2
`
const sqlStmtUserInfo = `
select
user_name,
user_code,
ifnull(display_name, '') as displayname,
ticket,
ifnull(partner, 0) as part_id,
ifnull(is_locked_name_duplicated, '') as locked,
ifnull(is_skill_sealed, '') as skill_sealed,
ifnull(curr_map, '') as curr_map,
prog_boost,
stamina,
next_fragstam_ts,
max_stamina_ts,
ifnull(max_stamina_notification, ''),
ifnull(is_hide_rating, ''),
ifnull(favorite_partner, 0),
recent_score_date, max_friend,
rating,
join_date
from
player
where
user_id = ?
`
const sqlStmtAprilfools = `
select ifnull(is_aprilfools, '') from game_info
`
const sqlStmtCoreInfo = `
select
c.internal_id, c.core_name, amount
from
core_possess_info p, core c
where
user_id = ?
and
c.core_id = p.core_id
`
const sqlStmtMostRecentScore = `
select
s.song_id, s.difficulty, s.score,
s.shiny_pure, s.pure, s.far, s.lost,
s.health, s.modifier,
s.clear_type, s2.clear_type "best clear type"
from
score s, best_score b, score s2
where
s.user_id = ?1
and s.played_date = (select max(played_date) from score)
and s.song_id = s2.song_id
and b.user_id = ?1
and b.played_date = s2.played_date
`
const sqlStmtUserSetting = `
update player set %s = '%s' where user_id = %d
`
const sqlStmtFavouritePartner = `
update player set favorite_partner = '%d' where user_id = %d
`
const sqlStmtMapInfo = `
select
available_from,
available_to,
beyond_health,
chapter,
coordinate,
ifnull(custom_bg, '') custom_bg,
ifnull(is_beyond, '') is_beyond,
ifnull(is_legacy, '') is_legacy,
ifnull(is_repeatable, '') is_repeatable,
world_map.map_id,
ifnull(require_id, '') require_id,
ifnull(require_type, '') require_type,
ifnull(require_value, 1) require_value,
stamina_cost,
step_count,
curr_capture,
curr_position,
ifnull(is_locked, '') is_locked
from
world_map, player_map_prog
where
player_map_prog.map_id = world_map.map_id
and player_map_prog.user_id = ?1
`
const sqlStmtCurrentMap = `
select ifnull(curr_map, '') from player where user_id = ?1
`
const sqlStmtMapAffinity = `
select part_id, multiplier from map_affinity where map_id = ?1
`
const sqlStmtRewards = `
select
ifnull(reward_id, "") reward_id,
item_type,
ifnull(amount, 0) amount,
position
from
map_reward
where
map_id = ?1
`