SQLITE: mudanças entre as edições
		
		
		
		Ir para navegação
		Ir para pesquisar
		
|  (→SQLite) | |||
| (14 revisões intermediárias pelo mesmo usuário não estão sendo mostradas) | |||
| Linha 1: | Linha 1: | ||
| =Links= | |||
| *[https://www.sqlitetutorial.net/ SQLite Tutorial] | |||
| =SQLite= | =SQLite= | ||
| ==Command line== | |||
| <syntaxhighlight lang=bash> | |||
| $ sqlite3 base.db -csv "select * from table" | tee output.csv | |||
| $ sqlite3 base.db -headers "select * from table" | column -t -s \| | |||
| </syntaxhighlight> | |||
| ==Create BASE== | ==Create BASE== | ||
| <syntaxhighlight lang=sql> | <syntaxhighlight lang=sql> | ||
| CREATE TABLE IF NOT EXISTS arquitetura( | |||
|     ID INTEGER PRIMARY KEY AUTOINCREMENT, | |||
|     HOSTNAME text, | |||
|     PUBLIC_IP text, | |||
|     STATE text, | |||
|     LOCAL_ADDRESS text, | |||
|     LOCAL_PORT integer, | |||
|     REMOTE_ADDRESS text, | |||
|     REMOTE_PORT integer, | |||
|     PROCESS_ID integer, | |||
|     PROCESS_NAME text, | |||
|     OS_VERSION text, | |||
|     PROCESSOR_COUNT integer, | |||
|     RAM_MEMORY_KB real) | |||
| </syntaxhighlight> | </syntaxhighlight> | ||
| ==Select  | |||
| ==Select== | |||
| Example | |||
| <syntaxhighlight lang=sql> | <syntaxhighlight lang=sql> | ||
| SELECT DISTINCT | SELECT DISTINCT | ||
| Linha 31: | Linha 55: | ||
|        'REMOTE_PORT' |        'REMOTE_PORT' | ||
| </syntaxhighlight> | </syntaxhighlight> | ||
| ==Delete== | |||
| Example | |||
| <syntaxhighlight lang=sql> | |||
| delete from bloqueios where timestamp <= '$(expr $(date +"%s") - 10368000)' | |||
| </syntaxhighlight> | |||
| ==List Tables== | |||
| <syntaxhighlight lang=sql> | |||
| .tables | |||
| </syntaxhighlight> | |||
| <syntaxhighlight lang=sql> | |||
| SELECT  | |||
|     name | |||
| FROM  | |||
|     sqlite_schema | |||
| WHERE  | |||
|     type ='table' AND  | |||
|     name NOT LIKE 'sqlite_%'; | |||
| </syntaxhighlight> | |||
| ==Get Table Info== | |||
| <syntaxhighlight lang=sql> | |||
| PRAGMA table_info(table_name); | |||
| </syntaxhighlight > | |||
| == Referências == | |||
| * [https://www.sqlite.org/lang.html Documentação oficial do SQLite] | |||
Edição atual tal como às 12h23min de 3 de junho de 2025
Links
SQLite
Command line
$ sqlite3 base.db -csv "select * from table" | tee output.csv
$ sqlite3 base.db -headers "select * from table" | column -t -s \|
Create BASE
CREATE TABLE IF NOT EXISTS arquitetura(
    ID INTEGER PRIMARY KEY AUTOINCREMENT,
    HOSTNAME text,
    PUBLIC_IP text,
    STATE text,
    LOCAL_ADDRESS text,
    LOCAL_PORT integer,
    REMOTE_ADDRESS text,
    REMOTE_PORT integer,
    PROCESS_ID integer,
    PROCESS_NAME text,
    OS_VERSION text,
    PROCESSOR_COUNT integer,
    RAM_MEMORY_KB real)
Select
Example
SELECT DISTINCT
      HOSTNAME,
      REMOTE_ADDRESS,
      REMOTE_PORT,
      PROCESS_NAME
    FROM
      arquitetura
    WHERE
      STATE == 'ESTABLISHED'
    AND
      LOCAL_PORT NOT IN (
        SELECT DISTINCT
          LOCAL_PORT
        FROM
          arquitetura
        WHERE
          STATE == 'LISTENING'
        AND
          LOCAL_ADDRESS <> '127.0.0.1'
          )
    AND
      LOCAL_ADDRESS <> '127.0.0.1'
    ORDER BY
      'REMOTE_PORT'
Delete
Example
delete from bloqueios where timestamp <= '$(expr $(date +"%s") - 10368000)'
List Tables
.tables
SELECT 
    name
FROM 
    sqlite_schema
WHERE 
    type ='table' AND 
    name NOT LIKE 'sqlite_%';
Get Table Info
PRAGMA table_info(table_name);