Jump to content

Newbie89

Members
  • Posts

    58
  • Joined

  • Last visited

Posts posted by Newbie89

  1. There's not enough code there to suggest anything to change. Your question is how to get your program to wait a minute to do something else? I assume you don't just want the program to sleep for that minute, correct?
    Ya,I don't want the program to sleep for that minute.I want it perform repeatably like insert,delete,insert,delete...
  2. Can some help me check and recorrect my code?

    if (T_Time >= InTime){if (cal_count<60){printf("insert data till one minute\n");sprintf(sql_lite, "insert into Packet (Dated,Time,Src_MAC,Dest_MAC,Net_P,Trans_P,Src_IP, Dest_IP,Src_Port,Dest_Port,Cap_Bytes) values ('%s','%s','%s','%s','%s','%s','%s','%s','%ld','%l d','%ld');",DT, TM, Src_MAC, Dest_MAC, Net_P,Trans_P, Src_IP, Dest_IP, Src_Port, Dest_Port, Cap_Bytes);error = sqlite3_exec(conn, sql_lite, 0, 0, 0);cal_count=cal_count+1;}else{printf("update each one minute\n");sprintf(del_lite,"delete from Packet;");error = sqlite3_exec(conn, del_lite, 0, 0, 0);/*printf("Date=%s\tTime=%s\nSrc_MAC=%s\tDest MAC=%s\nNet_P=%s\tTrans_P=%s\nSrc_IP=%s\tDest_IP=% s\nSrc_Port=%ld\tDest_Port=%ld\nPacket Size=%ld\n", DT, TM, Src_MAC, Dest_MAC, Net_P,Trans_P, Src_IP, Dest_IP, Src_Port, Dest_Port, Cap_Bytes);*/sleep(1);}}elsebreak;
    I try and found that something wrong in my code.In my code just for one minute to keep data.How do I keep data for each 1 minute? :Pleased:
  3. Below is my output: hong@ubuntu:~/Check$ sqlite3 hong.sl3<create.sqlhong@ubuntu:~/Check$ gcc -o insert insert.c -lsqlite3hong@ubuntu:~/Check$ ./insertEnter the number of data to be inserted1Enter the name of the student for insertJohnEnter the date, month, year of the student12 12 2012Enter the time12.00Enter the matrix number of the student for insert091232432=======================================1|10/10/2012|9.35am|Kean Heng|91021434=======================================We received 1 records.Total rows=100hong@ubuntu:~/Check$

  4. Can help me see the problem?Below is my code Create.sql create table student (No integer primary key autoincrement, Date1 varchar(20), Time varchar(10),Name varchar(10), Id_no integer); insert into student (Date1 , Time, Name, Id_no) values ('10/10/2012', '9.35am', 'Kean Heng', '091021434'); insert.c # include <stdio.h> # include <sqlite3.h> # include <stdlib.h> int main(void) { sqlite3 *conn; sqlite3_stmt *res; int error = 0; int rec_count = 0; const char *errMSG; const char *tail; char sql_lite[900]=" "; char name[50]; int date=0,month=0,year=0,matrix_number=0,number,x; float time =0; error = sqlite3_open("hong.sl3", &conn); if (error) { printf("Can not open database"); } printf("Enter the number of data to be inserted\n"); scanf("%d",&x); for(number=x;number>0;number--) { printf("Enter the name of the student for insert\n"); scanf("%s",name); printf("Enter the date, month, year of the student\n"); scanf("%d%d%d",&date,&month,&year); printf("Enter the time \n"); scanf("%f",&time); printf("Enter the matrix number of the student for insert\n"); scanf("%d",&matrix_number); } sprintf(sql_lite, "insert into student values ('%d/%d/%d','%.2fam','%s',%d);",date,month,year,time,name,matrix_number); error = sqlite3_exec(conn, sql_lite, 0, 0, 0); error = sqlite3_prepare_v2(conn, "select * from student order by No",1000, &res, &tail); if (error != SQLITE_OK) { printf("We did not get any data!"); exit(0); } printf("=======================================\n"); while (sqlite3_step(res) == SQLITE_ROW) { printf("%d|", sqlite3_column_int(res, 0)); printf("%s|", sqlite3_column_text(res, 1)); printf("%s|", sqlite3_column_text(res, 2)); printf("%s|", sqlite3_column_text(res, 3)); printf("%u\n", sqlite3_column_int(res, 4)); rec_count++; } printf("=======================================\n"); printf("We received %d records.\nTotal rows=%d\n", rec_count,SQLITE_ROW); sqlite3_finalize(res); sqlite3_close(conn); return 0; }

  5. How to insert data in the last row but not in the first row using C language.Do sqlite have function that control the row of the insert?I want the sequential row numbers from insert query.Thanks.

  6. #include <stdio.h>#include <sqlite3.h>#include <stdlib.h>static char *createsql = "CREATE TABLE Employee(" "ID INTEGER PRIMARY KEY," "Name VARCHAR(10)," "BadgeID VARCHAR(10));";static char *insertsql = "INSERT INTO Employee VALUES(NULL, 'Danny', '12345');";static char *querysql = "SELECT * FROM Employee;";void main(void){int i,j;int rows, cols;sqlite3 *db;char *errMsg = NULL;char **result;/* Open database file */if (sqlite3_open("my_example.db3", &db, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL)){ return ;}/* Build Table */ sqlite3_exec(db, createsql, 0, 0, &errMsg);/* Add a new record */ sqlite3_exec(db, insertsql, 0, 0, &errMsg);/* Get the last insert record's ID */ printf("%d\n", sqlite3_last_insert_rowid(db));/* Get all records in database */ sqlite3_get_table(db , querysql, &result , &rows, &cols, &errMsg);/* List all the data */ for (i=0;i<rows;i++){ for (j=0;j<cols;j++) { printf("%s\t", result[i*cols+j]); } printf("\n");} /* Free table */ sqlite3_free_table(result);/* Close database */ sqlite3_close(db);} Above is the code...When I'm compile it,I get the error in the terminal: hong@ubuntu:~/test$ gcc -lsqlite3 -o sqlite_exp sqlite_exp.csqlite_exp.c: In function ‘main’:sqlite_exp.c:18:1: error: too many arguments to function ‘sqlite3_open’/usr/include/sqlite3.h:2579:16: note: declared heresqlite_exp.c:32:1: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘sqlite3_int64’ [-Wformat] Can anyone help me point out the correction?thanks...

  7. I have succesfully compile the sqlite-amalgamation-3071300 and extract the file.After that I compile the sqlite3.c into the SBC TS-5500.When execute the sqlite command,it show no response with the next line,anyone can help me solve this problem?Below is my output problem:[root@miniepc Hong]#./a.out SQLite version 3.7.13 2012-06-11 02:05:22 Enter ".help" for instructions Enter SQL statements terminated with a ";" sqlite> create table artist(ID INTEGER PRIMARY KEY,Artist_name TEXT); ...> insert into artist(NULL,'hong'); ...> select * from artist; ...> .quit ...>

×
×
  • Create New...