Home Database Mysql Tutorial SQLite3插入时间实例

SQLite3插入时间实例

Jun 07, 2016 pm 05:13 PM
sqlite sqlite3 number

能够将时间插入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;
}

linux

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1652
14
PHP Tutorial
1251
29
C# Tutorial
1224
24
How to create a user login system using PHP and SQLite How to create a user login system using PHP and SQLite Jul 28, 2023 pm 09:27 PM

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

PHP and SQLite: How to do data compression and encryption PHP and SQLite: How to do data compression and encryption Jul 29, 2023 am 08:36 AM

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

Implementing user permissions and access control using PHP and SQLite Implementing user permissions and access control using PHP and SQLite Jul 29, 2023 pm 02:33 PM

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

Data charting and visualization using PHP and SQLite Data charting and visualization using PHP and SQLite Jul 28, 2023 pm 01:01 PM

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

PHP and SQLite: How to deal with long connections and disconnection and reconnection PHP and SQLite: How to deal with long connections and disconnection and reconnection Jul 29, 2023 am 09:05 AM

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 use PHP and SQLite for full-text search and indexing strategies How to use PHP and SQLite for full-text search and indexing strategies Jul 29, 2023 pm 08:45 PM

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

Create SQLite database from CSV file using Python Create SQLite database from CSV file using Python Aug 31, 2023 pm 12:17 PM

In today's data-driven world, having an efficient approach to data processing is crucial, and SQLite is one of the best solutions for small database systems. SQLite is a popular relational database system that is easy to use, lightweight, and scalable. One way to store data in SQLite is in CSV format. This enables us to store structured data in flat files and can easily parse it with the help of Python. In this tutorial, we will learn how to create a SQLite database from a CSV file using Python. What is a SQLite database? SQLite is a software library that provides a relational database management system (RDBMS) that stores data in independent,

Database handling in Python: SQLite and Redis Database handling in Python: SQLite and Redis Sep 04, 2023 pm 07:37 PM

In the information age we live in, we can see how much data the world is exchanging. We are basically creating, storing and retrieving data on a broad scale! There should be a way to handle all this - there's no way it could spread everywhere without any management, right? This is a database management system (DBMS). A DBMS is a software system that allows you to create, store, modify, retrieve, and otherwise manipulate data in a database. Such systems also vary in size, from small systems running only on personal computers to large systems running on mainframes. The focus of this tutorial is Python, not database design. Yes, Python is very capable of interacting with databases, and that's what I'm going to show you in this tutorial. you

See all articles