SQLITE: mudanças entre as edições

De Wiki Clusterlab.com.br
Ir para navegação Ir para pesquisar
Linha 55: Linha 55:
</syntaxhighlight>
</syntaxhighlight>
==List Tables==
==List Tables==
Example
<syntaxhighlight lang=sql>
<syntaxhighlight lang=sql>
.tables
.tables

Edição das 14h26min de 27 de janeiro de 2020

SQLite

Command line

sqlite3 base.db -csv "select * from table" | tee output.csv

Create BASE

CREATE TABLE IF NOT EXISTS arquitetura(
    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

Get Table Info

PRAGMA table_info(table_name);