Pacify file locks on Windows

This change gets redbean SQLite working in write mode on Windows.
Warnings have been added to the appropriate and responsible places.
Hacking proprietary PC systems into production-worthy servers isn't
terribly high on the list of priorities. Consider BSD or Linux when
building online systems that service requests from multiple people.

Fixes #193
This commit is contained in:
Justine Tunney 2021-06-12 00:01:55 -07:00
parent 9504ebaf7e
commit 8d7d00af3a
6 changed files with 146 additions and 17 deletions

View file

@ -0,0 +1,41 @@
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi
Copyright 2021 Justine Alexandra Roberts Tunney
Permission to use, copy, modify, and/or distribute this software for
any purpose with or without fee is hereby granted, provided that the
above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/testlib/testlib.h"
#include "third_party/sqlite3/sqlite3.h"
char testlib_enable_tmp_setup_teardown;
void SetUp(void) {
sqlite3_initialize();
}
TEST(sqlite, test) {
sqlite3 *db;
sqlite3_stmt *stmt;
ASSERT_EQ(SQLITE_OK, sqlite3_open("foo.sqlite", &db));
ASSERT_EQ(SQLITE_OK,
sqlite3_prepare_v2(db, "PRAGMA synchronous=0", -1, &stmt, 0));
ASSERT_EQ(SQLITE_DONE, sqlite3_step(stmt));
ASSERT_EQ(SQLITE_OK, sqlite3_finalize(stmt));
ASSERT_EQ(SQLITE_OK,
sqlite3_prepare_v2(db, "CREATE TABLE t (x INTEGER)", -1, &stmt, 0));
ASSERT_EQ(SQLITE_DONE, sqlite3_step(stmt));
ASSERT_EQ(SQLITE_OK, sqlite3_finalize(stmt));
ASSERT_EQ(SQLITE_OK, sqlite3_close(db));
}