Skip to content

Commit

Permalink
cli: Fix crash on missing args (#94)
Browse files Browse the repository at this point in the history
Fix crash that occurs when running vsql cli without a .vsql file cmd argument.
  • Loading branch information
BEN00262 authored Jun 19, 2022
1 parent e6aa7fa commit 04071ff
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions cmd/vsql.v
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import vsql
fn main() {
mut cmd := cli.Command{
name: 'vsql'
usage: '<file>'
required_args: 1
description: 'vsql is a single-file SQL database written in V'
execute: cli_command
}
Expand Down Expand Up @@ -61,23 +63,27 @@ fn cli_command(cmd cli.Command) ? {
print_version()

mut db := vsql.open(cmd.args[0])?

for {
print('vsql> ')
query := os.get_line()

start := time.ticks()
result := db.query(query)?
for row in result {
for column in result.columns {
print('$column.name: ${row.get_string(column.name)} ')
if query != "" {
start := time.ticks()
result := db.query(query)?
for row in result {
for column in result.columns {
print('$column.name: ${row.get_string(column.name)} ')
}
}

if result.rows.len > 0 {
println('')
}
}

if result.rows.len > 0 {
println('')
println('$result.rows.len ${vsql.pluralize(result.rows.len, 'row')} (${time.ticks() - start} ms)')
}

println('$result.rows.len ${vsql.pluralize(result.rows.len, 'row')} (${time.ticks() - start} ms)')
println('')
}
}
Expand Down

0 comments on commit 04071ff

Please sign in to comment.