• 로그인 함 해보끄나?

  • Sarangnamu.net June 17, 2003
    Home Login Profile Study Open Project Q&A Google Code
    sqlite sample with arm
    Last Modify : 10 December, 2010(03:39)
    #include <sqlite3.h>
    #include <string>
    #include <iostream>
    
    int main(int argc, char** argv)
    {
    	sqlite3* db;
    	sqlite3_stmt* stmt;
    
    	int res = sqlite3_open("./test.db", &db);
    
    	if (res != SQLITE_OK)
    	{
    		sqlite3_close(db);
    	}
    
    	std::string szSQL;
    	szSQL  = "CREATE TABLE IF NOT EXISTS Test (";
    	szSQL += "no INTEGER PRIMARY KEY AUTOINCREMENT,";
    	szSQL += "szWidgetID TEXT, nDate INTEGER);\n"; 
    	szSQL += "CREATE INDEX idx_widget_id ON Test (szWidgetID);";
    		
    	char* szError;
    	res = sqlite3_exec(db, szSQL.c_str(), NULL, NULL, &szError);
    	if (res != SQLITE_OK)
    		std::cout << "Error CreateDB" << std::endl;
    
    	time_t tmThis;
    	time(&tmThis);
    	char szTime[64] = {0};
    	sprintf(szTime, "%ld", tmThis);
    
    	szSQL  = "INSERT INTO Test(szWidgetID, nDate) VALUES('100','";
    	szSQL += szTime;
    	szSQL += "')";
    	
    	res = sqlite3_exec(db, szSQL.c_str(), NULL, NULL, &szError);
    	if (res != SQLITE_OK)
    		std::cout << "Error : " << szSQL.c_str() << std::endl << szError << std::endl;
    
    	szSQL = "SELECT * FROM Test";
    
    	const char* szConstError;
    	res = sqlite3_prepare_v2(db, szSQL.c_str(), szSQL.size(), &stmt, &szConstError);
    	if (res != SQLITE_OK)
    		std::cout << "Error SELECT " << szSQL.c_str() << std::endl << szConstError << std::endl;
    
    	res = sqlite3_step(stmt);	
    	
    	std::cout << "DB Data : " << std::endl;
    	std::cout << "1:" << sqlite3_column_int(stmt, 0) << std::endl;
    	std::cout << "2:" << sqlite3_column_text(stmt, 1) << std::endl;
    	std::cout << "3:" << sqlite3_column_int(stmt, 2) << std::endl;
    
    	sqlite3_finalize(stmt);
    
    
    	sqlite3_close(db);
    
    	return 1;
    }
    
    ///////////
    // makefile
    ///////////
    
    CXX         = /usr/local/arm/4.2.2-eabi-armv6/usr/bin/arm-unknown-linux-gnueabi-g++
    AR          = /usr/local/arm/4.2.2-eabi-armv6/usr/bin/arm-unknown-linux-gnueabi-ar
    LD          = /usr/local/arm/4.2.2-eabi-armv6/usr/bin/arm-unknown-linux-gnueabi-ld
    
    CXXFLAGS = $(INC) -Os -mfpu=vfp -mfloat-abi=softfp -mcpu=arm1176jzf-s
    
    INC = \
    	-I./\
    	-I/opt/prizm_mid/unit2s/target/include\
    
    LIB = \
    	-I/opt/prizm_mid/unit2s/target/lib
    
    SRCS = \
    	./db.cpp
    
    LIBS = \
    		/opt/prizm_mid/unit2s/target/lib/libsqlite3.a\
    		-lpthread \
    		-ldl
    
    OBJS = $(SRCS:.cpp=.o)
    
    TARGET = ../test-nfs/db
    
    ALL : $(TARGET)
    
    $(TARGET) : $(OBJS)
    			$(CXX) $(CXXFLAGS) -o $@ $(OBJS) $(LIBS)
    
    
    dep :
    	gccmakedep $(CXXFLAGS) $(SRCS)
    
    
    clean:
    	rm -f $(OBJS) 
    
    # DO NOT DELETE
    db.o: db.cpp /opt/prizm_mid/unit2s/target/include/sqlite3.h \
      /usr/lib/gcc/i486-linux-gnu/4.3.2/include/stdarg.h
    

    Comment


    입력하3 1498429442



    Locations of visitors to this page