Tutorial by Examples: sql

Dapper makes it easy to follow best practice by way of fully parameterized SQL. Parameters are important, so dapper makes it easy to get it right. You just express your parameters in the normal way for your RDBMS (usually @foo, ?foo or :foo) and give dapper an object that has a member called foo...
Since Java 6, the recommended way to access an SQL-based database in Java is via the JDBC(Java DataBase Connectivity) API. This API comes in two packagages: java.sql and javax.sql. JDBC defines database interactions in terms of Connections and Drivers. A Driver interacts with the database, and pr...
SQL injection is a kind of attack that allows a malicious user to modify the SQL query, adding unwanted commands to it. For example, the following code is vulnerable: // Do not use this vulnerable code! $sql = 'SELECT name, email, user_level FROM users WHERE userID = ' . $_GET['user']; $conn->...
There are two ways to connect to a MySQL/MariaDB server, depending on your infrastructure. Standard (TCP/IP) connection $dsn = 'mysql:dbname=demo;host=server;port=3306;charset=utf8'; $connection = new \PDO($dsn, $username, $password); // throw exceptions, when SQL error is caused $connection-...
public class DatabaseHelper extends SQLiteOpenHelper { private static final String DATABASE_NAME = "Example.db"; private static final int DATABASE_VERSION = 3; // For all Primary Keys _id should be used as column name public static final String COLUMN_ID = "_id&q...
One of the easiest ways to connect to MySQL is by using mysql module. This module handles the connection between Node.js app and MySQL server. You can install it like any other module: npm install --save mysql Now you have to create a mysql connection, which you can later query. const mysql ...
Follow previous example of creating a seed. This example uses a MySQL Dump to seed a table in the project database. The table must be created before seeding. <?php use Illuminate\Database\Seeder; class UserTableSeeder extends Seeder { /** * Run the database seeds. * ...
PL/SQL (Procedural Language/Structured Query Language) is Oracle Corporation's procedural extension for SQL and the Oracle relational database. PL/SQL is available in Oracle Database (since version 7), TimesTen in-memory database (since version 11.2.1), and IBM DB2 (since version 9.7). The basic un...
PL/SQL Function: CREATE OR REPLACE FUNCTION split_String( i_str IN VARCHAR2, i_delim IN VARCHAR2 DEFAULT ',' ) RETURN SYS.ODCIVARCHAR2LIST DETERMINISTIC AS p_result SYS.ODCIVARCHAR2LIST := SYS.ODCIVARCHAR2LIST(); p_start NUMBER(5) := 1; p_end NUMBER(5); ...
In the Project.pro file we add : CONFIG += sql in MainWindow.h we write : #include <QMainWindow> #include <QSql> #include <QDebug> namespace Ui { class MainWindow; } class MainWindow : public QMainWindow { Q_OBJECT public: explicit MainWindow(QWidget...
One of the more popular .NET providers for Postgresql is Npgsql, which is ADO.NET compatible and is used nearly identically as other .NET database providers. A typical query is performed by creating a command, binding parameters, and then executing the command. In C#: var connString = "Host=m...
List employees earning more than $50000 born this century. List their name, date of birth and salary, sorted alphabetically by name. SELECT employee_name, date_of_birth, salary FROM employees WHERE salary > 50000 AND date_of_birth >= DATE '2000-01-01' ORDER BY employee_name; Show...
In order to install PostgreSQL on OSX, you need to know which versions are currently supported. Use this command to see what versions you have available. sudo port list | grep "^postgresql[[:digit:]]\{2\}[[:space:]]" You should get a list that looks something like the following: post...
When SQL/Plus or SQL Developer display dates they will perform an implicit conversion to a string using the default date format model (see the Setting the Default Date Format Model example). You can change how a date is displayed by changing the NLS_DATE_FORMAT parameter.
Controls that can be bound with data can make use of SqlDataSource controls. The SqlDataSource control not only allows you to retrieve data from a database, but also edit and sort the data. Retrieving Data Stored Procedure: <asp:SqlDataSource ID="SqlDataSourceEmployees" runat=&q...
The C-API is the most powerful way to access PostgreSQL and it is surprisingly comfortable. Compilation and linking During compilation, you have to add the PostgreSQL include directory, which can be found with pg_config --includedir, to the include path. You must link with the PostgreSQL client s...
Below is a simple example which shows average item's price of each item per weekday. First, suppose we have a table which keeps daily records of all items' prices. CREATE TABLE tbl_stock(item NVARCHAR(10), weekday NVARCHAR(10), price INT); INSERT INTO tbl_stock VALUES ('Item1', 'Mon', 110), (...
To connect using java.sql.DriverManager you need a JDBC url to connect to your database. JDBC urls are database specific, but they are all of the form jdbc:<subprotocol>:<subname> Where <subprotocol> identifies the driver or database (for example postgresql, mysql, firebirdsql,...
DBContract.java //Define the tables and columns of your local database public final class DBContract { /*Content Authority its a name for the content provider, is convenient to use the package app name to be unique on the device */ public static final String CONTENT_AUTHORITY =...
To change MySQL's root user password: Step 1: Stop the MySQL server. in Ubuntu or Debian: sudo /etc/init.d/mysql stop in CentOS, Fedora or Red Hat Enterprise Linux: sudo /etc/init.d/mysqld stop Step 2: Start the MySQL server without the privilege system. sudo mysqld_safe --skip-grant-tab...

Page 1 of 10