14

I am evaluating the SQLite database for my requirement. Does SQLite support stored procedures?

If yes then what are the limitations? Does SQLite support the range?

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
CrazyC
  • 1,840
  • 6
  • 39
  • 60
  • 1
    possible duplicate of [Creating stored procedure and SQLite?](http://stackoverflow.com/questions/3335162/creating-stored-procedure-and-sqlite) – Adil Aliyev Jul 23 '15 at 12:05

4 Answers4

14

No, it does not. See Appropriate Uses For SQLite on the main site.

Matthew Flaschen
  • 278,309
  • 50
  • 514
  • 539
  • Thanks, any other database which support the store procedures? I am looking for in process database. means, where don't need any configuration just copy that file and use it. – CrazyC Aug 04 '10 at 05:36
10

A key reason for having stored procs in a database is that you're executing SP code in the same process as the SQL engine. This makes sense for database engines designed to work as a network connected service but the imperative for SQLite is much less. Given that it run as a DLL in your current process it makes more sense to implement SP in the client language.

You can however extend SQLite with your own user defined functions in the host language (PHP, Python, Perl, C#, Javascript, Ruby etc). I've done this in C# using DevArt's SQLite to implement password hashing.

Community
  • 1
  • 1
Tony O'Hagan
  • 21,638
  • 3
  • 67
  • 78
9

If you really want to store SQL code in the DB (such as when you want to develop cross-platform apps), you can create a specific table that will store raw SQL commands that do the thing, then in the client you obtain the SQL command. e.g.

var myString = db.CreateCommand("SELECT SqlColumn FROM tablewithsqlcommands WHERE Procname=theprocedureIwant").ExecuteScalar();

and then execute it in the second step

var myResult = db.CreateCommand(myString).whatever_execution_method_you_need();
Bernardo Ramos
  • 4,048
  • 30
  • 28
ofcoursedude
  • 456
  • 4
  • 10
0

No, but you can use this:

Stored Procedures for SQLite

Here is how to create a procedure:

CREATE OR REPLACE PROCEDURE add_new_sale(@products) BEGIN 
 SET @sale_id = INSERT INTO sales (time) VALUES (datetime('now')) RETURNING id;
 FOREACH @name, @qty, @price IN @products DO 
   INSERT INTO sale_items (sale_id, name, qty, price) VALUES (@sale_id, @name, @qty, @price);
 END LOOP;
 RETURN @sale_id;
END;

And how to call it:

CALL add_new_sale(ARRAY( ARRAY('DJI Avata',2,1168.00), ARRAY('iPhone 14',1,799.90) ));

Note: I am the creator

Bernardo Ramos
  • 4,048
  • 30
  • 28