Peoplecode setting value to Null

Peoplecode setting value to Null

String

Always use space to assign a null value to a string.
e.g. &Test_Str = ” “;

Number

Use 0 (zero) to assign a null value to a number.
e.g. &Test_Num = 0;

Date

Always Use blank value to assign a null value to a date otherwise it will give you invalid date error if it is equated to null or space as string.
e.g. &Test_Date = “”;

Other Data Types

For other data types like record, rowset we can assign them to null so as to get accurate results from all() and none() functions by paasing them as parameter.
e.g. &Test_Rec = null;

Application Class Properties

We can not use all() or none() functions to check if any property of application class is set. For this we will need to check by equating it to null or blank or space or zero based on its type in a conditional statement.

Hostinger Connection details

<?php defined(‘SYSPATH’) or die(‘No direct script access.’);
return array
(
‘default’ => array(
‘type’ => ‘mysqli’,
‘connection’ => array(
‘hostname’ => ‘mysql’,
‘username’ => ‘u XXXXXX_ysxxa’,
‘password’ => ‘aXXXXXXXX’,
‘persistent’ => FALSE,
‘database’ => ‘uXXXXX_ynxxa’,
),
‘table_prefix’ => ‘qxcu_’,
‘charset’ => ‘utf8’,
‘profiling’ => (Kohana::$environment===Kohana::DEVELOPMENT)? TRUE:FALSE,
),
);

Laravel Basic Directory Structure

C:\wamp\www\blog2\database\migrations : contains the Database Migration (Table strucutre)

 

C:\wamp\www\blog2\routes : contains the routing, mainly in the file WEB.php. This is where the system decides which Route file to load depending on the URL entered by the user.

Route::get(‘/users’, ‘UsersController@Index’);
Route::get(‘/users/{user_id}’, ‘UsersController@Show’);

C:\wamp\www\blog2\app\Http\Controllers: the above routes will bring the system to this directory where it will load files based on the controller name. for example: UsersController will load UsersController.php in the directory.

@Show, @Index is referring to the function within the controller.

C:\wamp\www\blog2\resources\views : contains the VIEW file of the website . Create subdirectory for paths like users/index OR users.index , users/show OR users.show. This is loaded by the controller file.

public function Index() {
$users = User::get();

return view(‘users.index’, compact(‘users’) );

}

C:\wamp\www\blog2\app : contains the App (Record/table class/representation in the system). Overriding the primarykey is done here.

 

 

 

Laravel Changing Table’s Primary key

This issue will happen when users use query like the following:

$user = DB::table(‘users’)->find($user_id);

The find() method will assume the primary key configured in Laravel, which will be $id. In order to override this, you need to declare   the MODEL (in this case, model USER) of which you will override the protected $primaryKey value to something else – for example ‘user_id’.

https://laracasts.com/discuss/channels/eloquent/set-primary-key-in-model

http://stackoverflow.com/questions/20030716/change-default-primary-key-in-eloquent

http://stackoverflow.com/questions/28508431/using-find-in-laravel-to-retrieve-a-database-object

When used in the query builder (DB::table()...) the find() method has the primary key column hardcoded as id:

public function find($id, $columns = array('*'))
{
    return $this->where('id', '=', $id)->first($columns);
}

What you should do instead is use where() and first():

$bottle = DB::table('bottle')->where('bottle_ID', 1)->first();

Or if you decide to use Eloquent Models you can specify the key column name:

class Bottle extends Eloquent {
    protected $primaryKey = 'bottle_ID';
}

And retrieve the model like this:

$bottle = Bottle::find(1);

 

Laravel Example of Migration and Table declaration

 

 

<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateUsersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
schema::create(‘users’, function (blueprint $table) {
$table->increments(‘user_id’);
$table->string(‘username’,30)->unique();
$table->string(’email’,50)->unique();
$table->string(‘password’); /* hashed */
$table->char(‘status’, 1);
$table->remembertoken();
$table->timestamp(‘created_at’);
$table->timestamp(‘updated_at’);
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists(‘users’);
}
}

php artisan migrate:refresh vs make:migration

Migrate:Refresh = to re-create tables/records in the database based on the migration files#

make:migration = to create a file that contains the definition of the table (keys etc)

C:\wamp\www\blog2>php artisan migrate:refresh

 

 

FizzBuzz Java

My attempt at the program, took me a bit because i am not used to Java syntax

 

package fizzbuzz;

/**
* @author MM
*/
public class FizzBuzz {

/**
* @param args the command line arguments
*/
public static final int NUM_THREE = 3;
public static final int NUM_FIVE = 5;

public static void main(String[] args) {
// Fizz Buzz
// Write a program that prints the numbers from 1 to 100. But for multiples of three print “Fizz” instead of the number and
//for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz”.”

for (int i = 1 ; i <= 100; i++) {

if (( i%NUM_THREE == 0) && ( i % NUM_FIVE == 0)) {
System.out.println(“FizzBuzz”);
}
else if ( i%NUM_THREE == 0) {
System.out.println(“Fizz”);
} else if ( i%NUM_FIVE == 0) {
System.out.println(“Buzz”);
} else {
System.out.println(i);
}
}
}
}

Laravel (005) Database Migration/Creation

I encountered an issue with my DB migration

C:\wamp\www\blog2>php artisan migrate:refresh

[ErrorException]
Undefined index: 2017_02_18_144317_create_tasks_table

C:\wamp\www\blog2>php artisan migrate:refresh
Migration table not found.
Migration table created successfully.
Migrated: 2017_02_18_152427_create_users_table

C:\wamp\www\blog2>php artisan migrate:refresh
Rolled back: 2017_02_18_152427_create_users_table
Migrated: 2017_02_18_152427_create_users_table

 

The issue was due to the Table MIGRATIONS containing non existent table definition (that got created/migrated before) so the system encountered an error when re-creating the table. Dropping the table MIGRATIONS an running the refresh command should resolve the issue

 

Laravel Journey (004) PHP Tinker

This is useful for testing commands to get data from DB.

However, TINKER is accessed via a Laravel site (installation). The logic is this, TINKER will allow people to query the Database, and the DB MUST BE LINKED to SOMETHING, in this case, the site  we are querying.

So it must be executed from the folder of the site.

 

C:\Windows\system32>php artisan tinker
Could not open input file: artisan

C:\Windows\system32>cd \

C:\>cd wamp\www\blog2

C:\wamp\www\blog2>php artisan tinker
Psy Shell v0.8.1 (PHP 5.6.25 ΓÇö cli) by Justin Hileman
New version is available (current: v0.8.1, latest: v0.8.2)
>>>