node 서버와 mysql 연동 시

아래 이미지와 같이 datetime 컬럼이 '2018-08-18T05:07:58.000Z' 처럼 알아 볼 수 없게 나온다면.




config.js 파일에 아래 한줄 추가 해 주시면 됩니다

dateStrings: 'date'



적용 화면

	
var mysql = require('mysql');

var mysqlConfig = {
    host     : 'localhost',
    user     : 'root',
    password : 'password',
    port     : 3306,
    database : 'databases',
    connectionLimit: 500,
    waitForConnections: true,
    dateStrings: 'date'
};
    
    
}


결과 화면


솔리디티 1차 배열의 선언 및 입력하고 받아오기 위해 아래와 같이 간단한 코드를 구현 해 보았습니다.


C++ 이나 JAVA 를 해보셨다면 어렵지 않게 이해 하실 수 있으리라 생각 됩니다.


아래 코드를 Remix 에서 실행 해 보겠습니다.

※ Remix 실행 준비 하기는 아래 링크를 참조 하시면 됩니다.

http://hatpub.tistory.com/54


	
pragma solidity ^0.4.24;
contract setArray {
    
    uint256[] DeptsId; //DeptsId 라는 정수형의 배열 선언
    
    // DeptsId 배열에 값 입력 할 함수 setDept
    function setDept(uint256 _deptid) public returns(uint256) {
        uint256 length = DeptsId.push(_deptid); 
        // push 로 파라미터 값을 넣고 length 변수에 배열의 index 를 받아 와서 return 한다.
        return(length);
    }
    
    // DeptsId 배열의 값을 불러올 함수 getDept
    function getDept(uint256 _number) public view returns(uint256) {
        // 배열의 값을 불러 올때는 index 값으로
        return(DeptsId[_number]);
    }
    
    
}




1. setDept 영역에 1~3 까지 입력을 하였습니다.




2. getDept 영역에 index 값인 0~2 를 입력 해서 call 을 하시면 위에서 입력한 1~3 의 값이 나오는 것을 확인 할 수 있습니다.

웹에서는 for 문이나 while 문을 돌려서 사용하시면 모든 값 혹은 특정 값을 불러 올 수 있습니다.


지난 포스팅에 구조체(struct) 배열(array) 를 하였는데, 기초적인 일반 배열을 지나친 것 같아 기초적인 내용을 포스팅 하였습니다.

솔리디티로 이더리움을 개발 하는 날까지 열심히 공부 해 봅시다!

solidity, ethereum

솔리디티(solidity) 로 이더리움 개발하기.


솔리디티에는 C언어와 같이 구조체(struct) 를 만들어 사용 할 수 있습니다. 



	
pragma solidity ^0.4.24;
contract test {

    // Struct 생성
    struct Employee{
        uint256 EmpId;  // 사원번호
        string EmpName; // 사원명
        string DeptName; // 부서명
    }

    // 생성한 Employee Struct 를 배열로 사용하기 위해 Employees 라는 배열 선언.
    Employee[] Employees;

    // 생성된 구조체 배열에 값 담기.
    function setEmp(uint256 _EmpId, string _EmpName, string _DeptName) public {
        // 솔리디티 배열은 push 를 이용하여 배열에 값을 입력 한다.
        Employees.push(Employee(_EmpId, _EmpName, _DeptName));
    }

    
    // 구조체 배열의 값 불러오기.
    // 배열의 특정 값과 for 문을 이용하여 배열의 전체 값을 불러 오기 위해 _number 라는 파라미터를 입력 받는다.
    function getEmp(uint _number) public view returns(uint256 getEmpId, string getEmpName, string getDeptName){
        getEmpId = Employees[_number].EmpId;
        getEmpName = Employees[_number].EmpName;
        getDeptName = Employees[_number].DeptName;
    }

}



작성한 코드를 Remix 에서 적용 해 보겠습니다.

Remix 세팅 방법은 이 전 글을 참고 하시면 됩니다.

http://hatpub.tistory.com/54?category=1009960


1. setEmp 함수에 파라미터를 주어 값 세팅.




2. getEmp 함수에 _number 파라미터 값을 주어 배열에 저장된 값 불러오기.




+ Recent posts