Wednesday, October 7, 2020

Postgress - Read a XML file from a postgress table XML column

SELECT xmltable.* FROM xmldata, XMLTABLE('//ROWS/ROW' PASSING data COLUMNS id int PATH '@id', "COUNTRY_NAME" text, country_id text PATH 'COUNTRY_ID', size_sq_km float PATH 'SIZE[@unit = "sq_mi"]', size_other text PATH 'concat(SIZE[@unit!="sq_km"], " ", SIZE[@unit!="sq_km"]/@unit)', premier_name text PATH 'PREMIER_NAME' DEFAULT 'not specified'); SELECT xmltable.* FROM table1, XMLTABLE('//Project/Tasks/Task' PASSING xdata COLUMNS "Name" text); SELECT xmltable.* FROM "ProjXML", XMLTABLE('//Project/Tasks/Task' PASSING Document COLUMNS "Name" text, "BuildNumber" text PATH "../,

Postgres Table/ Filed returns from a Function/ Procedure

CREATE TABLE foo (fooid INT, foosubid INT, fooname TEXT); INSERT INTO foo VALUES (1, 2, 'three'); INSERT INTO foo VALUES (4, 5, 'six'); CREATE OR REPLACE FUNCTION get_all_file_info() RETURNS SETOF bia_t_project_file_info AS $BODY$ DECLARE r bia_t_project_file_info%rowtype; BEGIN FOR r IN SELECT * FROM bia_t_project_file_info WHERE pfi_id > 0 loop -- public.bia_t_project_file_info -- can do some processing here RETURN NEXT r; -- return current row of SELECT END LOOP; RETURN; END $BODY$ LANGUAGE plpgsql; SELECT * FROM get_all_file_info(); -- drop function get_available_flightid create or replace FUNCTION get_available_flightid() RETURNS SETOF varchar(250) AS $BODY$ BEGIN RETURN QUERY SELECT pfi_filename FROM project WHERE pfi_id > 0; -- Since execution is not finished, we can check whether rows were returned -- and raise exception if not. IF NOT FOUND THEN RAISE EXCEPTION 'No flight at %.', $1; END IF; RETURN; END $BODY$ LANGUAGE plpgsql; -- Returns available flights or raises exception if there are no -- available flights. SELECT * FROM get_available_flightid(CURRENT_DATE);

Wednesday, June 10, 2020

React in a Single Page (All samples in W3Scool in one page)

Copy below HTML code into a HTML file which you like and run the HTML.

ex: Copy the code

      create a test.html blank file in your PC

     Paste the code and Run it.  


<!DOCTYPE html>
<html>
<script src="https://unpkg.com/react@16/umd/react.production.min.js"></script>
<script src="https://unpkg.com/react-dom@16/umd/react-dom.production.min.js"></script>
<script src="https://unpkg.com/babel-standalone@6.15.0/babel.min.js"></script>
<script type="text/babel">


class MyForm extends React.Component {
  constructor(props) {
    super(props);
    this.state = { username: '',
        age: 10,
        sex: "Male",
        errormessage: '',
        description: 'The content of a textarea goes in the value attribute'};
  };
 
  myChangeHandler = (xx) => {
   // this.setState({username: xx.target.value});
        let name = xx.target.name;
        let val = xx.target.value;
       
        this.setState({[name]: val});
  }
 
    myChangeAge = (xx) => {
   // this.setState({username: xx.target.value});
        let name = xx.target.name;
        let val = xx.target.value;
        let err = '';
        if (name="age"){
            if (!Number(val)){
                // alert("Not a number")
                err = <strong>Your age must be a number</strong>;    // Error handling            
               
            }
        }
        this.setState({errormessage: err});
        this.setState({[name]: val});
  }
 
  render() {
    let header = '';
    {/*Conditional rendering */}
    if (this.state.username) {
      header = <h1>Hello {this.state.username}</h1>;
    } else {
      header = '';
    }
   
    return (
      <form>
      {header}
      <p>Enter your name:</p>
      <input
        type='text'
        name='username'
        onChange={this.myChangeHandler}
      />
      <div>
            <input
        type='text'
        name='age'
        onChange={this.myChangeAge}
      />
      </div>
      <div>
            <input
        type='submit'
      />
      </div>
       {this.state.errormessage} {/*<-- Error message displaying */}
       <textarea value={this.state.description} />
       <div>
           <select>
              <option value="Ford">Ford</option>
              <option value="Volvo" selected>Volvo</option>
              <option value="Fiat">Fiat</option>
           </select>
       </div>

      </form>
    );
  }
}

class Hello extends React.Component {
  
  render() {
    return <h1>Hello {this.props.test2} !</h1>
  }
 
  // when this component is unmounted from a process, then this function getting execute
  componentWillUnmount() {
    alert("The component named Header is about to be unmounted.");
  }   
   
   
}


class Men extends React.Component {
    constructor(props){
        super(props);
        this.state={
         val1: 1,
         val2: 2,
         val3: 3,
         show: false
       
        };
    }
   
    //The getDerivedStateFromProps() method is called right before rendering the element(s) in the DOM.
    changeval=(props)=>{
        this.setState({val1: this.props.var1});
    }
   
    //The getDerivedStateFromProps() method is called right before rendering the element(s) in the DOM.
    changeva2=()=>{
        this.setState({val1: 11});
    }
   
    //this keyword should represent the component that owns the method.
    showval=(props)=>{
       
        this.setState({show: this.props.show2});
    };
   
    regularfunction = function(){
        document.getElementById("div3").innerHTML += this;
    }
   
    arrowfunction = () =>{
        document.getElementById("div4").innerHTML += this;
    }
   
    showval2=()=>{
       
        if (this.state.show == false)
        {
            this.setState({show: true});
        }
        else
        {
            this.setState({show: false});
        }
       
    }
   
    paramfunc=(x, y)=>{
        alert(x + y);
    }
   
   paramfuncevent=(x, y, ev)=>{
        alert(x + y + " " + ev.type);
    }
   
   
//The componentDidMount() method is called after the component is rendered.   
  componentDidMount() {
    setTimeout(() => {
      this.setState({val1: 10})
    }, 8000)
  }


  //method is called right before rendering the element(s) in the DOM.
  //first method that is called when a component gets updated.
  //shouldComponentUpdate is not a matter at this level;
  //***** if this method is executed, that mean, you cannot change this val1 value agaian.
  //Line is commeneted due to other values not working because of this function
  /*static getDerivedStateFromProps(props, state) {
        return {val1: props.var1};
        //changeval;
  }*/
 
 
  //if you need to lock the component as unmuted, then this is a way
  shouldComponentUpdate() {
    return true;//if false, components are never updates, default is anyway true;
  }

  //This will identify each state of a component and can compare with the current and the
  //previouse values
    getSnapshotBeforeUpdate(prevProps, prevState) {
    document.getElementById("div1").innerHTML =
    "Before the update, the favorite was " + prevState.val1;
  }
 
  //Once the componen changes, this function is executing. Specially if you impliment getSnapshotBeforeUpdate()
  // you must have this function too.
  componentDidUpdate() {
    document.getElementById("div2").innerHTML =
    "The updated favorite is " + this.state.val1;
  }
   

    render(){
       
        let hel1;
       
        if (this.state.show){
            hel1 = <Hello  test2={this.props.test2}/> ;
        }
       
        return  (<div>
                    <h1>  Men class {this.props.test} {this.state.val1} </h1>
                    {hel1}
                    <p> value is {this.state.val1}     </p>
                   
                    {/* Events are in Camel cases, ex: onClick(). event handlers are in {this.changeva2}, ex: onClick={this.changeva2}
                    A good practice is to put the event handler as a method in the component class:*/}
                    <div><button id="b1" type="button"  onClick={this.changeva2}>Change value</button></div>
                    <div><button id="b2" type="button"  onClick={this.showval}>Show</button></div>
                    <div><button id="b2" type="button"  onClick={this.showval2}>Togle</button></div>
                    <div>
                        {/* with arrow functions there are no binding of "this".
                        In regular functions the this keyword represented the object that called the function
                        With arrow functions, the this keyword always represents the object that defined the arrow function
                        <div><button id="b3" type="button"  onClick={this.regularfunction}>Show</button></div>*/}
                        <div><button id="b4" type="button"  onClick={this.arrowfunction}>Togle</button></div>                   
                    </div>
                    {/* calling a function with params}*/}
                    <div><button id="b5" type="button"  onClick={()=>this.paramfunc("Test one", " Two")}>Param func</button></div>   
                    <div><button id="b6" type="button"  onClick={(ev)=>this.paramfuncevent("Test one", " Two", ev)}>Param func event</button></div>   
                    <div id="div1"></div>
                </div>) ;
   
    }   

}

      
       ReactDOM.render(<Men test="woow" test2="xx" var1="8"  show2={true}/>, document.getElementById('mydiv2'))
      
       ReactDOM.render(<MyForm />, document.getElementById('div6'));
      
</script>


<body>

        <div id="mydiv2"></div>
        <div id="div2"></div>
       
        <div id="div3"></div>
        <div id="div4"></div>
       
        <div id="div6"></div>
       
</body>
</html>

Wednesday, March 25, 2020

Create a New User in SQL server and Grant only a Given DB Access only


-- 1.

create LOGIN sa_uat2 WITH PASSWORD='abc123', CHECK_POLICY = OFF;


--2.

USE master;

GO

DENY VIEW ANY DATABASE TO sa_uat2;



-- 3.
USE master;

GO

ALTER AUTHORIZATION ON DATABASE::DB_Name_You_need TO sa_uat2;

GO

Tuesday, September 3, 2019

Resting the SQL server auto incremental number

Resting the SQL server auto incremental number


DBCC CHECKIDENT ( [SFA_M_PRODUCT_PRICES], RESEED,220);


Tuesday, July 16, 2019

Create Navigation Panel Sample in React Native

How the Navigation sample Works
==============================================================
 1. install react-navigation using  
npm install react-navigation or 
yarn add react-navigation
2. Folder Struncture should like below
NavigationTest
  .
...assets
TabBarIcon.js
Color.js 
  ...navigation
  MainNavigation.js
...screens
  HomeScreen.js
  ProfileScreen.js
  HomeScreen2.js
 ProfileScreen2.js
App.js
 2. Create some native components called

HomeScreen.js
 ProfileScreen.js
 HomeScreen2.js
 ProfileScreen2.js
in a folder called "Screen" .
At the bottom area, you can see the samples.
3. Create
TabBarIcon.js , Color.js in the asset folder

4. Create  
MainNavigation.js in the navigation folder.
5. Scripts
MainNavigation.js file
=================================================================

import React from 'react';
import { Platform } from 'react-native';
import { createStackNavigator, createSwitchNavigator, createAppContainer, createBottomTabNavigator,
createDrawerNavigator } from 'react-navigation';
import AuthLoadingScreen from '../screens/AuthLoadingScreen';

import ProfileScreen from '../screens/ProfileScreen';
import HomeScreen2 from '../screens/HomeScreen2';
import ProfileScreen2 from '../screens/ProfileScreen2';
import HomeScreen from '../screens/HomeScreen';
import TabBarIcon from '../assets/TabBarIcon';


//Create Staks for each menu items you need

const TabHome = createStackNavigator({
Home: {screen: HomeScreen},
});
//Add navigation options like below to manage, Icon, titles to your menu item
TabHome.navigationOptions = {
tabBarLabel: 'Home in SUB 1',
tabBarIcon: ({ focused }) => (
<TabBarIcon
focused={focused}
name={
Platform.OS === 'ios'
? `ios-information-circle${focused ? '' : '-outline'}`
: 'md-pulse'
}
/>
),
};

//Create Staks for each menu items you need. In here we didn't add a navigation
 options
const TabProfile = createStackNavigator({
Profile: {screen: ProfileScreen},
});
//Create Staks for each menu items you need
const DrawHome2 = createStackNavigator({
Home: {screen: HomeScreen2},
});
//Add navigation options like below to manage, Icon, titles to your menu item
DrawHome2.navigationOptions = {
drawerLabel: 'Notifications',
drawerIcon: ({ focused }) => (
<TabBarIcon
focused={focused}
name={
Platform.OS === 'ios'
? `ios-information-circle${focused ? '' : '-outline'}`
: 'md-pulse'
}
/>
)
};
//Create Staks for each menu items you need
const DrawProfile2 = createStackNavigator({
Profile: {screen: ProfileScreen2},
});
//Add navigation options like below to manage, Icon, titles to your menu item
DrawProfile2.navigationOptions = {
tabBarLabel: 'Home in SUB 1',
drawerIcon: ({ focused }) => (
<TabBarIcon
focused={focused}
name={
Platform.OS === 'ios'
? `ios-information-circle${focused ? '' : '-outline'}`
: 'md-pulse'
}
/>
),
};
//Create the Navigator types for your Menu items.
//In here Menu Items "TabHome"', and "TabProfile", put into a TabNavigator,
// which you can see at the bottom of the Screen

const TabNav = createBottomTabNavigator(
{
TAB1: TabHome,
TAB2: TabProfile,
}
)
//Create the Navigator types for your Menu items.
//In here Menu Items "DrawHome2"', and "DrawProfile2", put into a DrawerNavigator,
// which you can see by pulling it from the left side.
 
const DrawNav = createDrawerNavigator(
{
DRAW1: DrawHome2,
DRAW2: DrawProfile2,
}
)

// Now Add all the Navigators to a Switch Navigator. By using this, you can
// simply switch between each navigator types by using
// this.props.navigation.navigate('Sub1');
or
// this.props.navigation.navigate('Sub2'); 

export default createAppContainer(createSwitchNavigator(
{
AuthLoading: AuthLoadingScreen,
Sub1: TabNav,
Sub2: DrawNav,
},
{
initialRouteName: 'Sub2', // You can set the default Sub menu from here.
}
));

===================================================
App.js file
==================================================== 

import React from 'react';
import MainNavigation from './navigation/MainNavigation';


export default function App() {
return (
<MainNavigation/>
);
}
=====================================================
TabBarIcon.js file
======================================================
import React from 'react';
import { Ionicons } from '@expo/vector-icons';

import Colors from './Colors';

export default function TabBarIcon(props) {
return (
<Ionicons
name={props.name}
size={26}
style={{ marginBottom: -3 }}
color={props.focused ? Colors.tabIconSelected : Colors.tabIconDefault}
/>
);
}

=====================================================
Color.js
======================================================
const tintColor = '#2f95dc';

export default {
tintColor,
tabIconDefault: '#ccc',
tabIconSelected: tintColor,
tabBar: '#fefefe',
errorBackground: 'red',
errorText: '#fff',
warningBackground: '#EAEB5E',
warningText: '#666804',
noticeBackground: tintColor,
noticeText: '#fff',
};



===========================================================================
 HomeScreen.js
===========================================================================

import React from 'react';
import {View, Text, Button} from 'react-native';


export default class HomeScreen extends React.Component {
render(){
return(
<View>
<Text> Home screen Woow </Text>
<Button title="GoTo Sub2" onPress={this.GoToSub2}/>
</View>

);
}

GoToSub2 = ()=>{
this.props.navigation.navigate('Sub2');
}

}
===========================================================================
 HomeScreen2.js
===========================================================================
import React from 'react';
import {View, Text, Button} from 'react-native';

export default class HomeScreen2 extends React.Component {
render(){

return(
<View>
<Text> Home screen </Text>
<Button title = "Goto Sub 1" onPress={this._GoToSub1Async}></Button>
</View>

);
}

static navigationOptions = {
title: 'Lots of features here',
};

_GoToSub1Async = () => {
this.props.navigation.navigate('Sub1');
};

}

===========================================================================
ProfileScreen.js
===========================================================================

import React from 'react';
import {View, Text} from 'react-native';

const ProfileScreen = () => {

return(
<View>
<Text> ProfileScreen screen </Text>
</View>
);

}


export default ProfileScreen;

===========================================================================
 ProfileScreen2.js
===========================================================================

import React from 'react';
import {View, Text} from 'react-native';

const ProfileScreen2 = () => {

return(
<View>
<Text> ProfileScreen screen 2 </Text>
</View>
);

}

export default ProfileScreen2;

Saturday, June 15, 2019

Postgress - Read a XML file from a postgress table XML column

SELECT xmltable.* FROM xmldata, XMLTABLE('//ROWS/ROW' PASSING data COLUMNS id int PATH ...