flat assembler
Message board for the users of flat assembler.

flat assembler > Linux > SQLite

Author
Thread Post new topic Reply to topic
narada



Joined: 15 Feb 2008
Posts: 77
Location: Ukraine, Dnepropetrovsk
Hi!
Anybody know how to use sqlite.so in linux-asm programs???
For Win it's not a problem, but for linux... i can't find any example on the web... (((


HELP, PLEASE!!!

_________________
http://www.omegicus.com
Post 08 Oct 2009, 19:11
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
kohlrak



Joined: 21 Jul 2006
Posts: 1421
Location: Uncle Sam's Pad
You have to import it. The post just below this one has an example of importing SO files, but if you need something immediately that you don't have to worry too much about understanding, i have something in the macros section that'll help out. The example is for gtk, but i think you'll be able to use it. Though, with recent changes, it might be advisable to keep your eye out for future improvements to fasm itself.
Post 08 Oct 2009, 23:33
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger Reply with quote
pelaillo
Missing in inaction


Joined: 19 Jun 2003
Posts: 863
Location: Colombia
Here is a very simple example that uses the fasm's new features for ELF
Code:
;Use fasm 1.69 or later (for extended ELF support)

SQLITE_OK =0
SQLITE_ROW =100

format ELF executable
entry start

include 'import32.inc'
include 'proc32.inc'

interpreter '/lib/ld-linux.so.2'
needed 'libc.so.6','libsqlite3.so.0'
import printf,exit,\
   sqlite3_open,sqlite3_prepare_v2,sqlite3_step,\
     sqlite3_column_text,sqlite3_finalize,sqlite3_close


segment readable executable

start:
 cinvoke sqlite3_open,database,ppDB
  cmp eax,SQLITE_OK
   jne .error_opening
  
    cinvoke printf,msg1,database
        cinvoke sqlite3_prepare_v2,[ppDB],SQL1,SQL1_len,ppStmt,0
    cmp eax,SQLITE_OK
   jne .error_compiling
        cinvoke sqlite3_step,[ppStmt] ; Creating a table
    cinvoke sqlite3_finalize,[ppStmt]

       cinvoke sqlite3_prepare_v2,[ppDB],SQL2,SQL2_len,ppStmt,0
    cmp eax,SQLITE_OK
   jne .error_compiling
        cinvoke sqlite3_step,[ppStmt] ; inserting some records
      cinvoke sqlite3_finalize,[ppStmt]

       cinvoke sqlite3_prepare_v2,[ppDB],SQL3,SQL3_len,ppStmt,0
    cmp eax,SQLITE_OK
   jne .error_compiling

  .get_row:
 cinvoke sqlite3_step,[ppStmt]
       cmp eax,SQLITE_ROW
  jne .rows_done
      cinvoke sqlite3_column_text,[ppStmt],0
      cinvoke printf,text,eax
     cinvoke sqlite3_column_text,[ppStmt],1
      cinvoke printf,text,eax
     jmp .get_row
  .rows_done:
   cinvoke sqlite3_finalize,[ppStmt]
  .closing:
        cinvoke sqlite3_prepare_v2,[ppDB],SQL4,SQL4_len,ppStmt,0
    cmp eax,SQLITE_OK
   jne .error_compiling
        cinvoke sqlite3_step,[ppStmt] ; dropping the table
  cinvoke sqlite3_finalize,[ppStmt]
   cinvoke sqlite3_close,[ppDB]
  .the_end:
     cinvoke exit

  .error_compiling:
 cinvoke printf,msg2
 jmp .closing

  .error_opening:
   cinvoke printf,msg3
 jmp .the_end

segment readable writeable

ppDB dd 0
ppStmt dd 0

database db "tes.sqlite",0
SQL1 db "CREATE TABLE functions (name,description)",0
SQL1_len = $ - SQL1
SQL2 db "INSERT INTO functions VALUES ('hello', 'world')",0
SQL2_len = $ - SQL2
SQL3 db "SELECT * FROM functions",0
SQL3_len = $ - SQL3
SQL4 db "DROP TABLE functions",0
SQL4_len = $ - SQL4
text db "%s",0xA,0
msg1 db 'Sqlite3 test program. Reading "%s" database file.',0xA,0
msg2 db "Error compiling the SQL statement.",0xA,0
msg3 db "Error opening the database file.",0xA,0
    


Last edited by pelaillo on 08 Apr 2010, 13:59; edited 1 time in total
Post 09 Oct 2009, 06:24
View user's profile Send private message Yahoo Messenger Reply with quote
narada



Joined: 15 Feb 2008
Posts: 77
Location: Ukraine, Dnepropetrovsk
+1) thanks.

+ some another question: for linux i am programming just few month, so i don't know some info.

So, can i convert .so to .o ?
Post 09 Oct 2009, 13:52
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
pelaillo
Missing in inaction


Joined: 19 Jun 2003
Posts: 863
Location: Colombia
narada,
One .so file is a shared object (executable library) already linked and could be composed of several object files. The answer to your question is yes, but the method depends on what you really want to accomplish.
Post 09 Oct 2009, 18:58
View user's profile Send private message Yahoo Messenger Reply with quote
kohlrak



Joined: 21 Jul 2006
Posts: 1421
Location: Uncle Sam's Pad
Odds are, if you're using linux and you have a .so file, there is a .o file in another folder or available for download.

I just did a little research on it and it's obviously open source, so by all means, dig in. Just make an object file instead and use a linker.
Post 10 Oct 2009, 03:46
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger Reply with quote
codesz



Joined: 30 Sep 2009
Posts: 10
It works fine.

SQLITE_OK =0
SQLITE_ROW =100
Post 25 Nov 2009, 12:14
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2018, Tomasz Grysztar.

Powered by rwasa.