Share Coding

Tutorials, Problems, Stuffs …

Change Server Collation in MSSQL server 2017

** please create a Full Database Backup if necessary

Target: change server collation from “SQL_Latin1_General_CP1_CI_AS” to “Chinese_Hong_Kong_Stroke_90_CI_AS”

1. Check current collation

SELECT SERVERPROPERTY(N’Collation’)

1

2. Stop SQL server services

3.png

3. open a command prompt with administrative privileges, go to the BINN directory of Microsoft SQL Server and run sqlservr.exe as follow:

C:\Program Files\Microsoft SQL Server\MSSQL14.SQLEXPRESS\MSSQL\Binn
sqlservr -m -T4022 -T3659 -s”SQLEXPRESS” -q”Chinese_Hong_Kong_Stroke_90_CI_AS”

-m starts an instance of SQL Server in single-user mode

-t starts an instance of SQL Server with a specified trace flag

-s”<instance name>”

-q”<New Collation Name>”

ref: https://docs.microsoft.com/en-us/sql/database-engine/configure-windows/database-engine-service-startup-options?view=sql-server-2017

2.png

4. Restart SQL server

5

5. Check for the change in Server Collation

6

 

Advertisements

[kotlin]Getter and Setter of a field by String

In this example, even the object is a any class, we do not know the class name.

Background: I have two fields named ‘EngTitle’ and ‘Title’.
A function to copy ‘EngTitle’ into ‘Title’, so the View Model get ‘Title’ to display without handling the language.

The following shows how to get a field.

var field = `object`::class.memberProperties.find { it.name == fieldName }
var target = `object`::class.memberProperties.find { it.name == targetName }

Next, set the field by target value

if (field is KMutableProperty<*>) {
    field.setter.call(`object`, target?.getter?.call(`object`))
}

Mapping data between 2 excel sheets

There are 2 excel sheets, left one is the full list of records and the right one is the filtered list I need to retrieve the ID from sheet 1 by given Ref No.

a.png

formula:

=INDEX(‘Full list‘!$A1:$A13507,MATCH(A3,’Full list‘!$B1:$B13507,0),0)

Result:

b.png

 

Refresh global variable by request

To renew a global variable such as a token, it is possible to do it by “Tests” function.

var jsonData = JSON.parse(responseBody);
postman.setEnvironmentVariable("token", jsonData.access_token);

The code should be in “Tests”.

{
  "access_token": "780fe237-b0c0-45fa-8fde-e856206f0fce",
  "token_type": "bearer",
  "refresh_token": "bac7223d-68a0-4c5a-ae6b-62071dcb187c",
  "expires_in": 6695,
  "scope": "read write"
}

The JSON respond body.

After you click send button, the global variable “token” will update it’s value with “access_token”.

Use Volley NetworkImageView with RecyclerView somet

Volley has a component NetworkImageView. It is easy to display image which is dowloaded from the network. However, working with RecyclerView or RecyclerViewPager, it load nothing on the view.

public class RecyclerNetworkImageView extends NetworkImageView {
    public RecyclerNetworkImageView(Context context) {
        super(context);
    }

    public RecyclerNetworkImageView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public RecyclerNetworkImageView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    @Override
    protected void onDetachedFromWindow() {
        // super.onDetachedFromWindow();
    }
}

When onDetachedFromWindow() being called, the following condition will stop loading image, so we override it through a subclass and it works!

if (mImageContainer != null) {
    // If the view was bound to an image request, cancel it and clear
    // out the image from the view.
    mImageContainer.cancelRequest();
    setImageBitmap(null);
    // also clear out the container so we can reload the image if necessary.
    mImageContainer = null;
}