Posts

SQL vs ORM

Creating a table In SQL the table can be created using the CREATE TABLE command CREATE TABLE people( name VARCHAR(30), NIC VARCHAR(10) PRIMARY KEY, phone VARCHAR(20) ); In ORM we can create types and use them to create a table. Object Type syntax CREATE TYPE <object_type_name> AS OBJECT( <attribute1> <datatype>, <attribute2> <datatype> ); First, we have to create a type as an object using the CREATE TYPE command CREATE TYPE person AS OBJECT( name VARCHAR(30), phone VARCHAR(20) ); Then we can create the table using the above type CREATE TABLE person_table OF person( NIC PRIMARY KEY ); Inserting data into a table We can insert data in two ways Method 1 Without specifying the object name INSERT INTO person_table VALUES(101, 'John', 'Smith', 'jsmith@example.com', '1-650-555-0135'); Method 2 Using the object name INSERT INTO person_table VALUES(person(101, 'John', 'Smith', &#

SQL Syntaxes

Select data from a table To select all(*) the data from a table  SELECT * FROM TABLE_NAME; To select specific columns of a table SELECT COLUMN_1, COLUMN_2,..., COLUMN_n FROM TABLE_NAME; ; DISTINCT - To select distinct(different) values SELECT DISTINCT COLUMN_1, COLUMN_2,..., COLUMN_n FROM TABLE_NAME; To list the number of distinct rows SELECT COUNT(DISTINCT COLUMN_NAME) FROM TABLE_NAME; or SELECT COUNT(*) AS COLUMN_NAME_IDENTIFIER FROM (SELECT DISTINCT COLUMN_NAME FROM TABLE_NAME); To give a condition to the select statement SELECT COLUMN_1, COLUMN_2,...,COLUMN_n FROM TABLE_NAME  WHERE condition When using the WHERE condition, 1. if it's an integer COLUMN_NAME = INT_VALUE 2. if it's a string (single quotation is required) COLUMN_NAME = 'STRING_VALUE' 3. if it's a date (single quotation is required and the format must be YYYY-MM-DD) COLUMN_NAME = 'YEAR-MONTH-DATE' Using AND syntax with WHERE con

Supporting code snippets for OOP take home assignment

Open a file and read data line by line. You're given a text(.txt) file as the input and not allowed to do manual user inputs. So you have to read the text file using your program. It can be done in the following way. Here the line is taken into a String called 'line'. To read lines you have to use the library 'fstream' #include <fstream> string line; ifstream myfile ("yourfilename.txt"); if (myfile.is_open()){ while(getline(myfile,line)){ // Enter your code here } myfile.close(); } src :  http://www.cplusplus.com/doc/tutorial/files/ Spliting string into two with blank space Method 1 Here 'line' is the String which we read from the file. To store the two sub strings we use a vector called tokens of type String. If you use this method after splitting the string into two parts you have to cast it into int. #include <vector> #include <string> #include <sstream> #include <it

Binary Search Tree Implementation

#include <stdio.h> #include <string.h> #include <stdlib.h> typedef struct Node{ int data; struct Node *left; struct Node *right; }node; node *root = NULL; node *insertNode(node *tree, int data){ if(root==NULL){ root = createNode(data); return NULL; } if(tree==NULL){ return createNode(data); } if(data < tree->data){ tree->left = insertNode(tree->left, data); } else{ tree->right = insertNode(tree->right, data); } } int createNode(int data){ node *newNode = malloc(sizeof(node)); newNode -> data = data; newNode -> left = NULL; newNode -> right = NULL; printf("Node %d created\n", data); return newNode; } node *inorderTraverse(node *tree){ if(tree != NULL){ inorderTraverse(tree->left); printf("%d ", tree->data); inorderTraverse(tree->right); } } node *postorderTraverse(node *tree){ if(tree != NULL){ postorderTraverse(tree->left); postorderTraverse(tree->right);

Arduino Joy Stick module

Image
Here is a simple Example of using the  Joy Stick  module with button. Circuit Diagram Source Code // Arduino pin numbers const int SW_pin = 2; // digital pin 2 connected to switch output const int X_pin = 0; // analog pin 0 connected to X output const int Y_pin = 1; // analog pin 1connected to Y output const int Xmin = 8; // left - digital pin 8 const int Ymax = 9; // right - digital pin 9 const int Ymin = 10; // down - digital pin 10 const int Xmax = 11; // up - digital pin 11 int Y; int X; int SW; void setup() {   pinMode(SW_pin, INPUT);   pinMode(Xmin, OUTPUT);   pinMode(Xmax, OUTPUT);   pinMode(Ymin, OUTPUT);   pinMode(Ymax, OUTPUT);   digitalWrite(SW_pin, HIGH);   Serial.begin(115200); } void loop() {   Serial.print("Switch:  ");   Serial.print(digitalRead(SW_pin));   Serial.print("\n");   Serial.print("X-axis: ");   Serial.print(analogRead(X_pin));   Serial.print("\n");   Serial.print("Y-axis: &

Getting started with MySQL using wamp server

After installing the wamp server on your computer follow the below steps. Step 1 : Run the command prompt.  Step 2 : Copy the path of the bin folder of the wamp server. usually it is, C:\wamp64\bin\mysql\mysql5.7.19\bin Step 3 : Go back to the command prompt and change the directory to the path you copied C:\Users\admin>cd C:\wamp64\bin\mysql\mysql5.7.19\bin Step 4 : Then type the command "mysql -u root -p", then press enter. C:\wamp64\bin\mysql\mysql5.7.19\bin>mysql -u root -p Step 5 : Then it will request the password, just enter because there isn't a password. Enter password: Step 6 : If you have successfully connected following message will be prompted. Welcome to the MySQL monitor.  Commands end with ; or \g. Your MySQL connection id is 3 Server version: 5.7.19 MySQL Community Server (GPL) Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and

How to surf trough screens using screen timeout

Assume you have two activities First Activity and Second Activity. To go to the second activity from the first activity without tapping add the below code into the 'onCreate' class in the activity. Here we use the android Handler getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);new android.os.Handler().postDelayed(new Runnable() { @Override public void run() { Intent i1 = new Intent(FirstActivity.this, SecondActivity.class); startActivity(i1); } }, 3000); According to the above code the time it takes to go to the next screen it takes 3 seconds (3000 milli seconds)