Remove push.apply() as it crashes on very long lists
parent
880fb10561
commit
809ddfad04
|
@ -1,6 +1,6 @@
|
|||
// Простенький "селект билдер" по мотивам MediaWiki-овского, успешно юзаю подобный в PHP уже лет 8
|
||||
// (c) Виталий Филиппов, 2019-2020
|
||||
// Версия 2020-03-25
|
||||
// Версия 2020-06-12
|
||||
|
||||
// В PHP, правда, прикольнее - там в массиве можно смешивать строковые и численные ключи,
|
||||
// благодаря чему можно писать $where = [ 't1.a=t2.a', 't2.b' => [ 1, 2, 3 ] ]
|
||||
|
@ -64,14 +64,14 @@ function select_builder(tables, fields, where, options)
|
|||
sql += ' FROM ';
|
||||
const t = tables_builder(tables);
|
||||
sql += t.sql;
|
||||
bind.push.apply(bind, t.bind);
|
||||
t.bind.forEach(v => bind.push(v));
|
||||
where = where_builder(where);
|
||||
sql += ' WHERE '+(where.sql || '1=1');
|
||||
bind.push.apply(bind, where.bind);
|
||||
where.bind.forEach(v => bind.push(v));
|
||||
if (t.moreWhere)
|
||||
{
|
||||
sql += ' AND '+t.moreWhere.sql;
|
||||
bind.push.apply(bind, t.moreWhere.bind);
|
||||
t.moreWhere.bind.forEach(v => bind.push(v));
|
||||
}
|
||||
if (options['GROUP BY'] || options.group_by)
|
||||
{
|
||||
|
@ -137,7 +137,7 @@ function tables_builder(tables)
|
|||
for (const row of table.rows)
|
||||
{
|
||||
sql += (i > 0 ? ', (' : '(') + table.keys.map(() => '?').join(', ')+')';
|
||||
bind.push.apply(bind, table.keys.map(k => row[k]));
|
||||
table.keys.forEach(k => bind.push(row[k]));
|
||||
i++;
|
||||
}
|
||||
sql += ') AS '+k+'('+table.keys.join(', ')+')';
|
||||
|
@ -145,7 +145,7 @@ function tables_builder(tables)
|
|||
else if (table instanceof Text)
|
||||
{
|
||||
sql += '(' + table.sql + ') ' + k;
|
||||
bind.push.apply(bind, table.bind);
|
||||
table.bind.forEach(v => bind.push(v));
|
||||
}
|
||||
else if (typeof table == 'object')
|
||||
{
|
||||
|
@ -163,7 +163,7 @@ function tables_builder(tables)
|
|||
{
|
||||
sql += subjoin.sql;
|
||||
}
|
||||
bind.push.apply(subjoin.bind);
|
||||
subjoin.bind.forEach(v => bind.push(v));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -177,13 +177,13 @@ function tables_builder(tables)
|
|||
else
|
||||
{
|
||||
conds.sql += ' AND ' + more_on.sql;
|
||||
conds.bind.push.apply(conds.bind, more_on.bind);
|
||||
more_on.bind.forEach(v => conds.bind.push(v));
|
||||
}
|
||||
}
|
||||
if (!first)
|
||||
{
|
||||
sql += ' ON ' + (conds.sql || '1=1');
|
||||
bind.push.apply(bind, conds.bind);
|
||||
conds.bind.forEach(v => bind.push(v));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -234,7 +234,7 @@ function where_or_set(fields, for_condition)
|
|||
}
|
||||
// FIXME: check bind variable count
|
||||
w.push(k);
|
||||
bind.push.apply(bind, v);
|
||||
v.forEach(v => bind.push(v));
|
||||
continue;
|
||||
}
|
||||
v = v instanceof Array ? v : [ v ];
|
||||
|
@ -253,7 +253,7 @@ function where_or_set(fields, for_condition)
|
|||
{
|
||||
// (a, b) in ((...), ...)
|
||||
w.push(k + ' in (' + v.map(vi => '('+vi.map(() => '?').join(', ')+')') + ')');
|
||||
v.map(vi => bind.push.apply(bind, vi));
|
||||
v.forEach(vi => vi.forEach(v => bind.push(v)));
|
||||
}
|
||||
else if (!for_condition)
|
||||
{
|
||||
|
@ -267,7 +267,7 @@ function where_or_set(fields, for_condition)
|
|||
if (v.length > 0)
|
||||
{
|
||||
w.push(k+' in (' + v.map(() => '?').join(', ') + ')' + (n > v.length ? ' or '+k+' is null' : ''));
|
||||
bind.push.apply(bind, v);
|
||||
v.forEach(v => bind.push(v));
|
||||
}
|
||||
else if (n > 0)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue