SQLite3插入时间实例
能够将时间插入sqlite3,并能够按时间区间搜索。 void my_first_sqlite3_func() { int i; sqlite3 *db; sqlite3_stmt
能够将时间插入sqlite3,并能够按时间区间搜索。
void my_first_sqlite3_func()
{
int i;
sqlite3 *db;
sqlite3_stmt *stmt;
char name[16], occ[16];
char *sql_drop="drop table if exists people;";
char *sql_create="create table people (id, time, blob);";
char *sql_insert="insert into people values (?, ?, ?);";
// char *sql_select="select * from people;";
char *sql_select="select * from people where time between datetime('2012-04-12 20:35:10.30') and datetime('2012-04-12 20:35:30.30');";
int len = strlen(sql_select);
sqlite3_open("mydb.db", &db);
sqlite3_exec(db, "PRAGMA synchronous = OFF; ", 0,0,0);
sqlite3_prepare(db, sql_drop, strlen(sql_drop), &stmt, NULL);
sqlite3_step(stmt);
sqlite3_prepare(db, sql_create, strlen(sql_create), &stmt, NULL);
sqlite3_step(stmt);
char *data = "fjaksdjfkasdjfklasjdkfjasdkfjksadjfklsdajfksdajfklsdjkfljsdakfkjdgkadjfkajkfajskfljasdlkfjadsk";
sqlite3_prepare(db, sql_insert, strlen(sql_insert), &stmt, NULL);
printf("begin write!\n");
char myTime[30];
for(i=10;i {
sprintf(myTime, "2012-04-12 20:35:%d.30", i);
int len = strlen(data);
sqlite3_bind_int(stmt, 1, i);
sqlite3_bind_text(stmt, 2, myTime, strlen(myTime), NULL);
sqlite3_bind_blob(stmt, 3, data, len, NULL);
sqlite3_step(stmt);
sqlite3_reset(stmt);
}
printf("finish write!\n");
printf("begin search!\n");
sqlite3_prepare(db, sql_select, strlen(sql_select), &stmt, NULL);
i=0;
while(SQLITE_DONE !=sqlite3_step(stmt))
{
int id = sqlite3_column_int(stmt, 0);
char * time = (char *)sqlite3_column_text(stmt, 1);
int bytes = sqlite3_column_bytes(stmt, 2);
char *out_data = (char *)sqlite3_column_blob(stmt, 2);
i++;
printf("%d %s\n", i, time);
}
printf("finish search!\n");
sqlite3_finalize(stmt);
sqlite3_close(db);
}
int main()
{
my_first_sqlite3_func();
getchar();
return 0;
}

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



How to create a user login system using PHP and SQLite In today's Internet era, a user login system is one of the basic functions of many websites and applications. This article will introduce how to create a simple and powerful user login system using PHP and SQLite. SQLite is an embedded database engine. It is a zero-configuration, server-side database engine. PHP is a popular server-side scripting language that can be used in conjunction with SQLite to create a flexible and efficient user login system. by

Implementing user permissions and access control using PHP and SQLite In modern web applications, user permissions and access control are a very important part. With proper permissions management, you can ensure that only authorized users can access specific pages and functions. In this article, we will learn how to implement basic user permissions and access control using PHP and SQLite. First, we need to create a SQLite database to store information about users and their permissions. The following is the structure of a simple user table and permission table

PHP and SQLite: How to Compress and Encrypt Data In many web applications, data security and storage space utilization are very important considerations. PHP and SQLite are two very widely used tools, and this article will introduce how to use them for data compression and encryption. SQLite is a lightweight embedded database engine that does not have a separate server process but interacts directly with applications. PHP is a popular server-side scripting language that is widely used to build dynamic

Using PHP and SQLite to implement data charts and visualization overview: With the advent of the big data era, data charts and visualizations have become an important way to display and analyze data. In this article, we will introduce how to use PHP and SQLite to implement data charts and visualization functions. Take an example as an example to show how to read data from a SQLite database and use a common data chart library to display the data. Preparation: First, you need to ensure that PHP and SQLite databases have been installed. If it is not installed, you can

With the development of the Internet, blogs have become a platform for more and more people to share their lives, knowledge and ideas. If you also want to create a blog of your own, then this article will introduce how to use PHP and SQLite to create a simple blog. Determine the needs Before starting to create a blog, we need to determine the functions we want to achieve. For example: Create a blog post Edit a blog post Delete a blog post Display a list of blog posts Display blog post details User authentication and permission control Install PHP and SQLite We need to install PHP and S

PHP and SQLite: How to deal with long connections and disconnection and reconnection Introduction: In web development, PHP and SQLite are two commonly used technologies. However, long connections and disconnection and reconnection are some of the problems often encountered when using PHP and SQLite. This article will introduce how to handle the problems of long connections and disconnection and reconnection in PHP, and provide some example codes to help developers better understand and solve these problems. 1. Persistent connection problem When using PHP to connect to SQLite database, long connection (Persis

How to Import and Export Data Using PHP and SQLite Importing and exporting data is one of the common tasks while developing a website or application. Using PHP and SQLite, we can easily import data from external files into SQLite database and export data from database to external files. This article will introduce how to use PHP and SQLite to import and export data, and provide corresponding code examples. Data import First, we need to prepare an external file containing the data to be imported. this file

How to use PHP and SQLite for full-text search and indexing strategies Introduction: In modern application development, full-text search capabilities are indispensable in many fields. Whether on blogs, news websites, or e-commerce platforms, users are accustomed to using keywords to search. Therefore, to improve user experience and provide better search results, we need to provide full-text search capabilities using appropriate search and indexing strategies. In this article, we will explore how to use PHP and SQLite databases to implement full-text search and
