Hello, all.

Could   anybody  clarify  to  me  data  conversion  done  in
sqlite3_bind_text(), please?

I've written simple test:

test.c
;----------------------X8
#include <stdio.h>
#include "sqlite3.h"

int main(int argc, char* argv[])
{ int rez = 0;
  sqlite3* ss_pdb = NULL;
  sqlite3_stmt* st;

  rez = sqlite3_open_v2("base", &ss_pdb, SQLITE_OPEN_READWRITE | 
SQLITE_OPEN_CREATE, NULL);

  do
  { rez = sqlite3_exec(ss_pdb, "CREATE TABLE T(str STRING, val INTEGER);", 
NULL, NULL, NULL);
    if (rez != SQLITE_OK)
      break;

    rez = sqlite3_prepare_v2(ss_pdb, "INSERT INTO T (str, val) VALUES (?,?);", 
-1, &st, NULL);
    if (rez != SQLITE_OK)
      break;

    rez = sqlite3_bind_text(st, 1, "0001", -1, SQLITE_TRANSIENT);
    if (rez != SQLITE_OK)
      break;

    rez = sqlite3_bind_int(st, 2, 123);
    if (rez != SQLITE_OK)
    { printf("sqlite error: %s\n", sqlite3_errmsg(ss_pdb));
      break;
    }

    rez = sqlite3_step(st);
    if (rez != SQLITE_DONE)
      break;
    sqlite3_finalize(st);
  } while (0);

  sqlite3_close(ss_pdb);

  return rez;
}
;----------------------X8

makefile.vc
;----------------------X8
CC=cl
CFLAGS=/MD  /DWIN32 /nologo /GX /GA /O2 /W3 /GF /D_WIN32_WINNT=0x500
BIN=test.exe
OBJ=test.obj sqlite3.obj
RM=del
RFLAGS=

all: $(BIN)

$(BIN): $(OBJ)
        $(CC) $(CFLAGS) $(OBJ) /Fe$(BIN)

%.obj: %.c
        $(CC) $(CFLAGS) /c $<

clean:
        -$(RM) $(RFLAGS) $(BIN) 2>nul
        -$(RM) $(RFLAGS) $(OBJ) 2>nul
;----------------------X8

It  works  fine,  without  any  errors,  but  when I checked
database by sqlite3 utility, I found that value of str field
is  not  equal  to  "0001",  instead it is equal to "1".

I'd changed line with INSERT statement to

;----------------------X8
    rez = sqlite3_prepare_v2(ss_pdb, "INSERT INTO T (str, val) VALUES 
('?',?);", -1, &st, NULL);
;----------------------X8

and  got  error  SQLITE_RANGE  ("bind or column index out of
range") in next bind after sqlite3_bind_text().

;----------------------X8
    rez = sqlite3_bind_int(st, 2, 123);
;----------------------X8

How   can  I  insert  string/text  value  in  table  without
conversion?

OS: Windows XP, compiler - Microsoft Visual C++ 6.0

-- 
WBR,
 darkelf                          mailto:dark...@ukr.net

_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to