Monday, 30 March 2020

MSSQL condition query and case sensitivity

If exists select, else  insert
if not exists (select 1 from  [ClinRefFileTypeMaster] where [ClinRefTypeName] =@name)
Insert into [ClinRefFileTypeMaster] ([ClinRefTypeName]) values (@name) 
select (as desired) from ClinRefFileTypeMaster where where [ClinRefTypeName] =@name

MSSQl case sentitive?
depends on collation, default collation ends with _cs is case insensitive _cs means case
case insensitive 
utf8_general_ci  makes it case insensitive, where CI means case insensitive
Comparisons are case insensitive when the column uses a collation which ends with _ci (such as the default latin1_general_ci collation) and they are case sensitive when the column uses a collation which ends with _cs or _bin (such as the utf8_unicode_cs and utf8_bin collations).

Friday, 27 March 2020

php sql_srv get last inserted id

$query = "INSERT INTO test (col1, col2) VALUES (?,?); SELECT SCOPE_IDENTITY()";
$resource=sqlsrv_query($conn, $query, $arrParams);
($query); bool fetchStatus = sqlsrv_fetch($query); if(fetchStatus === false) { die( print_r( sqlsrv_errors(), true)); } if(fetchStatus === null) { // Some work when there are no results in the result set } else { $id = sqlsrv_get_field($query, 0); } ...
query needs to have SELECT SCOPE_IDENTITY() for get last insert ID to work

Returns the last identity value inserted into an identity column in the same scope. A scope is a module: a stored procedure, trigger, function, or batch. Therefore, if two statements are in the same stored procedure, function, or batch, they are in the same scope

Thursday, 26 March 2020

relative path, php getcwd

# one level up current dir
cd ..
# equivalent 
cd ./..
# This means .. is used after directory
# one levelup of /home/test/dir and go to /home/test/vendor
cd /home/test/dir/../vendor

#PHP working directory is the directory where you run the script
echo getcwd();

# If you run the script /home/test/myscript.php, working directory is /home/test
# If you have a file in /home/test/function/test.php, and you have another file in /home/test/vendor/myscript.php

# in /home/test/function/test.php, require_once '../vendor/myscript.php' will not work, because curretn working directory is /home/test. One level up that is /home, and there is no such thing as /home/vendor 

require_once __DIR__ . '/../vendor/myscript'

__DIR__ is current directory of file so /home/test/function, so /../ means one level up that means /home/test, then /home/test/vendor

Wednesday, 25 March 2020

Vue error handler (can be used with Vuex)


  • Type: Function
  • Default: undefined
  • Usage:
    Vue.config.errorHandler = function (err, vm, info) {
      // handle error
      // `info` is a Vue-specific error info, e.g. which lifecycle hook
      // the error was found in. Only available in 2.2.0+
    Assign a handler for uncaught errors during component render function and watchers. The handler gets called with the error and the Vue instance.

Vue Element dateoptions to filter dates


       computed : {
     * VUE ELEMEENT picker-options (
    expireTimeOption: function () {
        // Current cutoff date PST string
        var current_date = this.cutoff // date from backend
        return  {
            * Whether to Disable date in the date picker
            * @param DateObject  Date      The date supplied from date picker in PST  Sat May 02 2020 00:00:00 GMT-0700 (Pacific Daylight Time)
            disabledDate(date) {
              // PST
              console.log('Cut off date is ' + current_date)
              if ( ! current_date) {
                return false
              // Make cut off Date into Date()
              var current_cut_off_date = new Date(current_date)
              // Get Today's date
              var today = new Date()
              // Find out last month of current date
              var resulting_date = new Date(current_date) // current date
              resulting_date.setDate(1) // going to 1st of the month
              resulting_date.setHours(-1) // going to last hour before this date even started.
              // If Today is less than cutoff date do nothing
              if (today.getTime() <= current_cut_off_date.getTime()) {
                // Allow transaction date to be last month but not the month before that
                // // Find out last month of resulting_date
                var prev_resulting_date = resulting_date // current date
                prev_resulting_date.setDate(1) // going to 1st of the month
                prev_resulting_date.setHours(-1) // going to last hour before this date even started.
                return date.getTime() <= prev_resulting_date.getTime()

              return date.getTime() <= resulting_date.getTime()


Other references :
    placeholder="Please select">

  // js中定义范围
  // picker-options的值是一个对象,他的disabledDate属性可以设置禁用日期,有一个参数是当前选择的日期
  data () {
    return {
      pickerOptions: {}, // 日期设置对象

  created {
   // disabledDate 为true表示不可选,false表示可选
   this.pickerOptions.disabledDate = disabledDate (time) {
      // 设置可选择的日期为今天之后的一个月内
      let curDate = (new Date()).getTime()
      // 这里算出一个月的毫秒数,这里使用30的平均值,实际中应根据具体的每个月有多少天计算
      let day = 30 * 24 * 3600 * 1000
      let dateRegion = curDate + day
      return time.getTime() < - 8.64e7 || time.getTime() > dateRegion

      // 设置选择的日期小于当前的日期,小于返回true,日期不可选
      // return time.getTime() < - 8.64e7

Vuex with webpack to load every file in modules, and auto import them

import Vue from 'vue'
import Vuex from 'vuex'
import getters from './getters'


const modulesFiles = require.context('./modules', true, /\.js$/)

// you do not need `import app from './modules/app'`
// it will auto require all vuex module from modules file
const modules = modulesFiles.keys().reduce((modules, modulePath) => {
  // set './app.js' => 'app'
  const moduleName = modulePath.replace(/^\.\/(.*)\.\w+$/, '$1')
  const value = modulesFiles(modulePath)
  modules[moduleName] = value.default
  return modules
}, {})

const store = new Vuex.Store({

export default store

const store = new Vuex.Store({
  state: {
    todos: [
      { id: 1, text: '...', done: true },
      { id: 2, text: '...', done: false }
  getters: {
    doneTodos: state => {
      return state.todos.filter(todo => todo.done)