Quick Functions

SQLite contains several functions for performing different types of options whether they are small or big. We don't have to write the SQL query to perform them every time just for a sneak peek.

getCNames

This function is used often when we have to retrieve the column names of tables(s).

sqlite.getCNames(
    [
        ["table1_db1", "table2_db1"],
        ["table1_db2", "table2_db2"]
    ]
)

Output:

[
    [columns of table1_db1, columns of table2_db1],
    [columns of table1_db2, columns of table2_db2]
]

getNColumns

Same as getCNames but instead of returning the names of columns, it returns the number of columns.

sqlite.getCNames(
    [
        ["table1_db1", "table2_db1"],
        ["table1_db2", "table2_db2"]
    ]
)

Output:

[
    [n(columns) of table1_db1, n(columns) of table2_db1],
    [n(columns) of table1_db2, n(columns) of table2_db2]
]

getNRecords

This function is used when we have to calculate the no. of records in a table.

sqlite.getNRecords(
    [
        ["table1_db1", "table2_db1"],
        ["table1_db2", "table2_db2"]
    ]
)

Output:

[
    [n(records) of table1_db1, n(records) of table2_db1],
    [n(records) of table1_db2, n(records) of table2_db2]
]

The output will be the same as the by getNColumns but this time the count is for records instead of columns. It returns list as the result.

getTCommand

This function is often used when we have get the command using which the specified tables was created. The order of output is same as of all other functions.

sqlite.getTCommand(
    [
        ["table1_db1", "table2_db1"],
        ["table1_db2", "table2_db2"]
    ]
)

Output:

[
    [command of table1_db1, command of table2_db1],
    [command of table1_db2, command of table2_db2]
]

getTNames

This function is often used when we have get the names of tables in database(s).

sqlite.getTCommand(
    [
        ["table1_db1", "table2_db1"],
        ["table1_db2", "table2_db2"]
    ]
)

Output:

[
    [command of table1_db1, command of table2_db1],
    [command of table1_db2, command of table2_db2]
]

getDbSize

This function is used when we have to get the size of database(s).

sqlite.getDbSize(
    ["db1", "db2"]
)

Output:

[
    "size of db1",
    "size of db2"
]

For example:

[
    '106496 bytes (0.106496 MB)',
    '126345 bytes (0.126345 MB)'
]

getSampleDb

This function is useful when we have to perform some test (or experiment) operations on a database apart from our main database. This function generates a sample database for those tests.

This function generates two types of databases, big or small.

sqlite.getSampleDb("db name", bigData=True)  # Will generate big data
sqlite.getSampleDb("db name", bigData=False)  # Will generate small data

bigData=False will generate data with 3 tables city (1000 records), country (239 records), countrylanguage (303 records)

bigData=True will generate data with 3 tables city (2500 records), country (239 records), countrylanguage (984 records)

Note: This data is taken from MySQL data repository and not generated by SQL-Tools team.

Last updated