sql-splitter 1.21.0

High-performance CLI tool for splitting large SQL dump files into individual table files
Documentation
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
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
//! Batch manager for DuckDB Appender-based bulk loading.
//!
//! This module provides efficient batched insertion of rows into DuckDB
//! using the Appender API instead of individual INSERT statement execution.

use crate::parser::{ParsedValue, SqlDialect};
use crate::transform_common::quote_ident;
use ahash::AHashMap;
use anyhow::Result;
use duckdb::Connection;

use super::ImportStats;

/// Maximum rows to accumulate per batch before flushing
pub const MAX_ROWS_PER_BATCH: usize = 10_000;

/// A batch of rows for a single table
#[derive(Debug)]
pub struct InsertBatch {
    /// Target table name
    pub table: String,
    /// Source SQL dialect, used to map source-default schemas to DuckDB's
    /// default schema in generated batch inserts.
    pub dialect: SqlDialect,
    /// Column list if explicitly specified
    pub columns: Option<Vec<String>>,
    /// Accumulated rows (each row is a Vec of ParsedValue)
    pub rows: Vec<Vec<ParsedValue>>,
    /// Original SQL statements for fallback execution
    pub statements: Vec<String>,
    /// Number of rows contributed by each statement
    pub rows_per_statement: Vec<usize>,
}

impl InsertBatch {
    /// Create a new batch for a table
    pub fn new(table: String, columns: Option<Vec<String>>, dialect: SqlDialect) -> Self {
        Self {
            table,
            dialect,
            columns,
            rows: Vec::new(),
            statements: Vec::new(),
            rows_per_statement: Vec::new(),
        }
    }

    /// Total number of rows in batch
    pub fn row_count(&self) -> usize {
        self.rows.len()
    }

    /// Clear the batch
    pub fn clear(&mut self) {
        self.rows.clear();
        self.statements.clear();
        self.rows_per_statement.clear();
    }
}

/// Batch key: (table_name, column_layout, source dialect).
/// Using Option<Vec<String>> for columns allows distinguishing between
/// different column orderings for the same table. The source dialect is part
/// of the key because it determines the DuckDB table-name mapping.
type BatchKey = (String, Option<Vec<String>>, SqlDialect);

/// Manages batched INSERT operations for multiple tables
pub struct BatchManager {
    /// Active batches keyed by (table, columns)
    batches: AHashMap<BatchKey, InsertBatch>,
    /// Maximum rows per batch
    max_rows_per_batch: usize,
}

impl BatchManager {
    /// Create a new batch manager
    pub fn new(max_rows_per_batch: usize) -> Self {
        Self {
            batches: AHashMap::new(),
            max_rows_per_batch,
        }
    }

    /// Queue rows for insertion, returning a batch if it's ready to flush
    pub fn queue_insert(
        &mut self,
        table: &str,
        columns: Option<Vec<String>>,
        rows: Vec<Vec<ParsedValue>>,
        original_sql: String,
        dialect: SqlDialect,
    ) -> Option<InsertBatch> {
        let row_count = rows.len();
        let key = (table.to_string(), columns.clone(), dialect);

        let batch = self
            .batches
            .entry(key)
            .or_insert_with(|| InsertBatch::new(table.to_string(), columns, dialect));

        batch.rows.extend(rows);
        batch.statements.push(original_sql);
        batch.rows_per_statement.push(row_count);

        // Check if we need to flush
        if batch.rows.len() >= self.max_rows_per_batch {
            // Take the batch out and return it
            let key = (table.to_string(), batch.columns.clone(), dialect);
            self.batches.remove(&key)
        } else {
            None
        }
    }

    /// Get any batches that are ready to flush
    pub fn get_ready_batches(&mut self) -> Vec<InsertBatch> {
        let mut ready = Vec::new();
        let mut to_remove = Vec::new();

        for (key, batch) in &self.batches {
            if batch.rows.len() >= self.max_rows_per_batch {
                to_remove.push(key.clone());
            }
        }

        for key in to_remove {
            if let Some(batch) = self.batches.remove(&key) {
                ready.push(batch);
            }
        }

        ready
    }

    /// Flush all remaining batches
    pub fn drain_all(&mut self) -> Vec<InsertBatch> {
        self.batches.drain().map(|(_, batch)| batch).collect()
    }

    /// Check if there are any pending batches
    pub fn has_pending(&self) -> bool {
        !self.batches.is_empty()
    }
}

/// Format a ParsedValue for SQL insertion
fn format_value_for_sql(value: &ParsedValue) -> String {
    match value {
        ParsedValue::Null => "NULL".to_string(),
        ParsedValue::Integer(n) => n.to_string(),
        ParsedValue::BigInteger(n) => n.to_string(),
        ParsedValue::String { value } => {
            // Escape single quotes by doubling them (SQL standard)
            let escaped = value.replace('\'', "''");
            format!("'{}'", escaped)
        }
        ParsedValue::Hex(bytes) => {
            // `ParsedValue::Hex` carries the literal as written, `0x` prefix
            // included, so the digits are already hex -- re-encoding the bytes
            // would hex-encode the ASCII characters and turn 0x30 into
            // x'30783330'.
            format!("x'{}'", hex_digits(bytes))
        }
        ParsedValue::Other(raw) => {
            let s = String::from_utf8_lossy(raw);
            // Try to parse as float
            if s.parse::<f64>().is_ok() {
                s.to_string()
            } else {
                // Treat as text
                let escaped = s.replace('\'', "''");
                format!("'{}'", escaped)
            }
        }
    }
}

/// Generate a batched INSERT statement from parsed values
fn generate_batch_insert(
    table: &str,
    columns: &Option<Vec<String>>,
    rows: &[Vec<ParsedValue>],
    dialect: SqlDialect,
) -> String {
    if rows.is_empty() {
        return String::new();
    }

    // DuckDB loads PostgreSQL's `public` and SQL Server's standard system
    // schemas into its default schema. Match the DDL and direct-INSERT paths.
    let duckdb_table = match dialect {
        SqlDialect::Postgres => table.strip_prefix("public.").unwrap_or(table),
        SqlDialect::Mssql => ["dbo.", "master.", "tempdb.", "model.", "msdb."]
            .iter()
            .find_map(|prefix| table.strip_prefix(prefix))
            .unwrap_or(table),
        SqlDialect::MySql | SqlDialect::Sqlite => table,
    };
    let mut sql = format!(
        "INSERT INTO {}",
        quote_ident(SqlDialect::Postgres, duckdb_table)
    );

    // Add column list if specified
    if let Some(cols) = columns {
        sql.push_str(" (");
        for (i, col) in cols.iter().enumerate() {
            if i > 0 {
                sql.push_str(", ");
            }
            sql.push('"');
            sql.push_str(col);
            sql.push('"');
        }
        sql.push(')');
    }

    sql.push_str(" VALUES\n");

    for (i, row) in rows.iter().enumerate() {
        if i > 0 {
            sql.push_str(",\n");
        }
        sql.push('(');
        for (j, value) in row.iter().enumerate() {
            if j > 0 {
                sql.push_str(", ");
            }
            sql.push_str(&format_value_for_sql(value));
        }
        sql.push(')');
    }
    sql.push(';');

    sql
}

/// Flush a batch using DuckDB's Appender API with transactional fallback
pub fn flush_batch(
    conn: &Connection,
    batch: &mut InsertBatch,
    stats: &mut ImportStats,
    failed_tables: &mut std::collections::HashSet<String>,
) -> Result<()> {
    if batch.rows.is_empty() {
        return Ok(());
    }

    // Skip tables we know don't exist
    if failed_tables.contains(&batch.table) {
        batch.clear();
        return Ok(());
    }

    // Fastest path: hand the parsed values straight to DuckDB's Appender. The
    // batched-INSERT path below has to serialize every value back into SQL text
    // that DuckDB then re-parses -- profiling put ~75% of import time in
    // duckdb::ClientContext::CreatePreparedStatement doing exactly that. The
    // Appender skips the parser entirely. It is not always applicable, so it
    // reports false and leaves the batch untouched when it bails.
    match try_appender_insert(conn, batch, stats) {
        Ok(true) => {
            batch.clear();
            return Ok(());
        }
        Ok(false) => {} // not eligible, fall through to SQL
        Err(e) => {
            // The append was rolled back, so falling through cannot double-insert.
            if stats.warnings.len() < 100 {
                stats.warnings.push(format!(
                    "Appender failed for {}, using SQL: {}",
                    batch.table, e
                ));
            }
        }
    }

    // Try the fast path with batched INSERT
    match try_batch_insert(conn, batch, stats) {
        Ok(true) => {
            // Success via batched INSERT
            batch.clear();
            Ok(())
        }
        Ok(false) => {
            // Table doesn't exist or other non-recoverable error
            failed_tables.insert(batch.table.clone());
            batch.clear();
            Ok(())
        }
        Err(_) => {
            // Batched INSERT failed (constraint violation, type mismatch, etc.)
            // Fall back to per-statement execution
            fallback_execute(conn, batch, stats)?;
            batch.clear();
            Ok(())
        }
    }
}

/// Map the DuckDB table name the way the SQL path does, so both agree on which
/// table a batch targets.
fn duckdb_table_name(table: &str, dialect: SqlDialect) -> &str {
    match dialect {
        SqlDialect::Postgres => table.strip_prefix("public.").unwrap_or(table),
        SqlDialect::Mssql => ["dbo.", "master.", "tempdb.", "model.", "msdb."]
            .iter()
            .find_map(|prefix| table.strip_prefix(prefix))
            .unwrap_or(table),
        SqlDialect::MySql | SqlDialect::Sqlite => table,
    }
}

/// Convert a parsed value for the Appender. `Other` holds raw bytes for
/// decimals, floats and expressions like `NOW()`; binding those as text would
/// either lose exactness or be flatly wrong, so those batches take the SQL path
/// where DuckDB parses them into the column's own type.
fn appender_value(v: &ParsedValue) -> Option<duckdb::types::Value> {
    use duckdb::types::Value as V;
    Some(match v {
        ParsedValue::Null => V::Null,
        ParsedValue::Integer(i) => V::BigInt(*i),
        ParsedValue::BigInteger(i) => V::HugeInt(*i),
        ParsedValue::String { value } => V::Text(value.clone()),
        ParsedValue::Hex(b) => V::Blob(decode_hex_literal(b)?),
        ParsedValue::Other(_) => return None,
    })
}

/// The hex digits of a `0xABCD` literal, without the prefix.
fn hex_digits(raw: &[u8]) -> std::borrow::Cow<'_, str> {
    let digits = raw
        .strip_prefix(b"0x")
        .or_else(|| raw.strip_prefix(b"0X"))
        .unwrap_or(raw);
    String::from_utf8_lossy(digits)
}

/// Decode a `0xABCD` literal into the bytes it denotes. MySQL left-pads an odd
/// digit count, so `0xABC` is the two bytes `0x0A 0xBC`.
fn decode_hex_literal(raw: &[u8]) -> Option<Vec<u8>> {
    let digits = hex_digits(raw);
    let d = digits.as_bytes();
    if d.is_empty() || !d.iter().all(u8::is_ascii_hexdigit) {
        return None;
    }
    let mut out = Vec::with_capacity(d.len().div_ceil(2));
    let mut idx = 0;
    if d.len() % 2 == 1 {
        out.push((d[0] as char).to_digit(16)? as u8);
        idx = 1;
    }
    while idx < d.len() {
        let hi = (d[idx] as char).to_digit(16)? as u8;
        let lo = (d[idx + 1] as char).to_digit(16)? as u8;
        out.push((hi << 4) | lo);
        idx += 2;
    }
    Some(out)
}

/// Append a batch with DuckDB's Appender, bypassing SQL parsing entirely.
///
/// `Ok(false)` means the batch is not eligible and nothing was written, so the
/// caller should use the SQL path. `Err` means the append failed *and was rolled
/// back*, so the caller can also fall through without double-inserting.
///
/// Eligibility is deliberately strict. The Appender binds positionally across
/// every column of the table, so a batch whose column list differs from the
/// table's own order -- or omits a column -- would silently write values into
/// the wrong columns. That is worse than being slow, so anything short of an
/// exact match declines.
fn try_appender_insert(
    conn: &Connection,
    batch: &InsertBatch,
    stats: &mut ImportStats,
) -> Result<bool> {
    let table = duckdb_table_name(&batch.table, batch.dialect);

    // The table's real column order, straight from the catalog.
    let mut stmt = conn.prepare(
        "SELECT column_name FROM information_schema.columns \
         WHERE table_name = ? ORDER BY ordinal_position",
    )?;
    let table_cols: Vec<String> = stmt
        .query_map([table], |r| r.get::<_, String>(0))?
        .collect::<std::result::Result<_, _>>()?;
    if table_cols.is_empty() {
        return Ok(false); // unknown table; let the SQL path produce the error
    }

    // An explicit column list must match the catalog exactly, in order.
    if let Some(cols) = &batch.columns {
        if cols.len() != table_cols.len()
            || !cols
                .iter()
                .zip(&table_cols)
                .all(|(a, b)| a.eq_ignore_ascii_case(b))
        {
            return Ok(false);
        }
    }

    // Every row must be full width and hold only bindable values.
    let width = table_cols.len();
    let mut values: Vec<duckdb::types::Value> = Vec::with_capacity(batch.rows.len() * width);
    for row in &batch.rows {
        if row.len() != width {
            return Ok(false);
        }
        for v in row {
            match appender_value(v) {
                Some(val) => values.push(val),
                None => return Ok(false),
            }
        }
    }

    // Wrap in a transaction so a type-cast failure part-way through leaves no
    // partially appended rows behind for the SQL fallback to duplicate.
    conn.execute_batch("BEGIN TRANSACTION")?;
    let appended = (|| -> duckdb::Result<()> {
        let mut app = conn.appender(table)?;
        let mut refs: Vec<&dyn duckdb::ToSql> = Vec::with_capacity(width);
        for chunk in values.chunks(width) {
            refs.clear();
            refs.extend(chunk.iter().map(|v| v as &dyn duckdb::ToSql));
            app.append_row(refs.as_slice())?;
        }
        app.flush()
    })();

    match appended {
        Ok(()) => {
            conn.execute_batch("COMMIT")?;
            stats.insert_statements += batch.statements.len();
            stats.rows_inserted += batch.rows.len() as u64;
            Ok(true)
        }
        Err(e) => {
            conn.execute_batch("ROLLBACK")?;
            Err(e.into())
        }
    }
}

/// Try to insert using batched SQL execution, returns Ok(true) on success,
/// Ok(false) if table doesn't exist, Err on constraint/type errors
fn try_batch_insert(
    conn: &Connection,
    batch: &InsertBatch,
    stats: &mut ImportStats,
) -> Result<bool> {
    // Generate a single batched INSERT statement
    let batch_sql = generate_batch_insert(&batch.table, &batch.columns, &batch.rows, batch.dialect);
    if batch_sql.is_empty() {
        return Ok(true);
    }

    // Execute the batched INSERT (within the loader's transaction context)
    match conn.execute(&batch_sql, []) {
        Ok(_) => {
            stats.insert_statements += batch.statements.len();
            stats.rows_inserted += batch.rows.len() as u64;
            Ok(true)
        }
        Err(e) => {
            // Check if it's a "table not found" error
            if is_missing_table_error(&e) {
                return Ok(false);
            }
            Err(e.into())
        }
    }
}

/// FK violations also say that a key "does not exist", so only a catalog
/// missing-table error can tell the loader to skip future rows for a table.
fn is_missing_table_error(error: &duckdb::Error) -> bool {
    matches!(
        error,
        duckdb::Error::DuckDBFailure(_, Some(message))
            if message.starts_with("Catalog Error: Table with name ")
    )
}

/// Fallback: execute original SQL statements one by one
fn fallback_execute(conn: &Connection, batch: &InsertBatch, stats: &mut ImportStats) -> Result<()> {
    for stmt in &batch.statements {
        match conn.execute(stmt, []) {
            Ok(_) => {
                stats.insert_statements += 1;
                stats.rows_inserted += count_insert_rows(stmt);
            }
            Err(e) => {
                if stats.warnings.len() < 100 {
                    stats.warnings.push(format!(
                        "Failed INSERT for {} in fallback: {}",
                        batch.table, e
                    ));
                }
                stats.statements_skipped += 1;
            }
        }
    }
    Ok(())
}

/// Count rows in an INSERT statement (simple heuristic)
fn count_insert_rows(sql: &str) -> u64 {
    if let Some(values_pos) = sql.to_uppercase().find("VALUES") {
        let after_values = &sql[values_pos + 6..];
        let mut count = 0u64;
        let mut depth: i32 = 0;
        let mut in_string = false;
        let mut prev_char = ' ';

        for c in after_values.chars() {
            if c == '\'' && prev_char != '\\' {
                in_string = !in_string;
            }
            if !in_string {
                if c == '(' {
                    if depth == 0 {
                        count += 1;
                    }
                    depth += 1;
                } else if c == ')' {
                    depth = depth.saturating_sub(1);
                }
            }
            prev_char = c;
        }
        count
    } else {
        1
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn hex_literal_decodes_to_the_bytes_it_denotes() {
        // `ParsedValue::Hex` keeps the `0x` prefix, so a naive re-encode of the
        // payload turns 0x30 into the four ASCII bytes "0x30".
        assert_eq!(decode_hex_literal(b"0x30").unwrap(), vec![0x30]);
        assert_eq!(decode_hex_literal(b"0x623a303b").unwrap(), b"b:0;".to_vec());
        assert_eq!(decode_hex_literal(b"0XFF").unwrap(), vec![0xff]);
        // MySQL left-pads an odd digit count: 0xABC is 0x0A 0xBC.
        assert_eq!(decode_hex_literal(b"0xABC").unwrap(), vec![0x0a, 0xbc]);
        assert!(decode_hex_literal(b"0x").is_none());
        assert!(decode_hex_literal(b"0xZZ").is_none());
    }

    #[test]
    fn hex_literal_renders_as_sql_blob_without_double_encoding() {
        let v = ParsedValue::Hex(b"0x623a303b".to_vec());
        assert_eq!(format_value_for_sql(&v), "x'623a303b'");
    }

    #[test]
    fn test_batch_manager_queue() {
        let mut mgr = BatchManager::new(100);

        let rows = vec![vec![
            ParsedValue::Integer(1),
            ParsedValue::String {
                value: "test".to_string(),
            },
        ]];

        let result = mgr.queue_insert(
            "users",
            None,
            rows,
            "INSERT INTO users VALUES (1, 'test')".to_string(),
            SqlDialect::MySql,
        );
        assert!(result.is_none()); // Not ready yet
        assert!(mgr.has_pending());
    }

    #[test]
    fn test_batch_manager_flush_threshold() {
        let mut mgr = BatchManager::new(2);

        let rows1 = vec![vec![ParsedValue::Integer(1)]];
        let rows2 = vec![vec![ParsedValue::Integer(2)], vec![ParsedValue::Integer(3)]];

        mgr.queue_insert("test", None, rows1, "SQL1".to_string(), SqlDialect::MySql);
        let result = mgr.queue_insert("test", None, rows2, "SQL2".to_string(), SqlDialect::MySql);

        assert!(result.is_some());
        let batch = result.unwrap();
        assert_eq!(batch.row_count(), 3);
    }

    #[test]
    fn test_count_insert_rows() {
        assert_eq!(count_insert_rows("INSERT INTO t VALUES (1)"), 1);
        assert_eq!(count_insert_rows("INSERT INTO t VALUES (1), (2), (3)"), 3);
        assert_eq!(
            count_insert_rows("INSERT INTO t VALUES (1, 'a(b)'), (2, 'c')"),
            2
        );
    }

    #[test]
    fn test_generate_batch_insert_with_columns() {
        let rows = vec![
            vec![
                ParsedValue::String {
                    value: "alice".to_string(),
                },
                ParsedValue::Integer(1),
            ],
            vec![
                ParsedValue::String {
                    value: "bob".to_string(),
                },
                ParsedValue::Integer(2),
            ],
        ];
        let columns = Some(vec!["name".to_string(), "id".to_string()]);
        let sql = generate_batch_insert("users", &columns, &rows, SqlDialect::MySql);
        assert!(sql.contains("INSERT INTO \"users\" (\"name\", \"id\") VALUES"));
        assert!(sql.contains("'alice'"));
        assert!(sql.contains("'bob'"));
    }

    #[test]
    fn test_generate_batch_insert_without_columns() {
        let rows = vec![vec![
            ParsedValue::Integer(1),
            ParsedValue::String {
                value: "test".to_string(),
            },
        ]];
        let sql = generate_batch_insert("test", &None, &rows, SqlDialect::MySql);
        assert_eq!(sql, "INSERT INTO \"test\" VALUES\n(1, 'test');");
    }

    #[test]
    fn batch_insert_quotes_qualified_table_components_separately() {
        let rows = vec![vec![ParsedValue::Integer(1)]];
        let sql = generate_batch_insert("tenant_a.users", &None, &rows, SqlDialect::Postgres);

        assert_eq!(sql, "INSERT INTO \"tenant_a\".\"users\" VALUES\n(1);");
    }

    #[test]
    fn batch_insert_maps_postgres_public_to_duckdb_default_schema() {
        let rows = vec![vec![ParsedValue::Integer(1)]];
        let sql = generate_batch_insert("public.users", &None, &rows, SqlDialect::Postgres);

        assert_eq!(sql, "INSERT INTO \"users\" VALUES\n(1);");
    }

    #[test]
    fn batch_insert_maps_mssql_dbo_to_duckdb_default_schema() {
        let rows = vec![vec![ParsedValue::Integer(1)]];
        let sql = generate_batch_insert("dbo.users", &None, &rows, SqlDialect::Mssql);

        assert_eq!(sql, "INSERT INTO \"users\" VALUES\n(1);");
    }
}