728x90

2014/08/11 - [DB/MSSQL] - MS-SQL 시퀀스 identity 생성 및 초기화하기


2014/08/11 - [DB/Oracle] - 오라클(Oracle) sequence 생성, 등록, 최종 시퀀스값 조회하기


1. MySQL 시퀀스 생성하기

CREATE TABLE test_board(
  seq INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
  title VARCHAR(20) NOT NULL
);

INSERT INTO test_board(title)
VALUES('hello');

INSERT INTO test_board(title)
VALUES('hello2');

INSERT INTO test_board(title)
VALUES('hello3');


위와같이 실행후 SELECT문 실행





확인결과 title 컬럼에만 데이터를 insert 하였는데 seq 컬럼은 자동적으로 값이 증가 하여 

insert 되는것을 확인 할 수 있었다.

위와같이 자동으로 컬럼의 숫자값을 일정하게 증가하고 싶다면 auto_increment 를 시퀀스로 사용할 컬럼에 지정을 해주면 된다.

그럼 이제 모든 데이터를 지우고 다시 같은 insert 쿼리를 동작 후 똑같이 조회를 해보도록 하자 


delete from test_board;

INSERT INTO test_board(title)
VALUES('hello');

INSERT INTO test_board(title)
VALUES('hello2');

INSERT INTO test_board(title)
VALUES('hello3');

데이터를 지우고 다시 같은 내용의 insert 구문을 넣어주었다

다시한번 데이터 조회를 해보도록 하자




위와 같이 seq가 지워진 시퀀스 값에 이어서 자동 증가하는 현상이 발생하였다.


물론 중복이 되지 않으므로 상관은 없으나 모든 데이터를 삭제 후 시퀀스값을 초기화 하길 원할때가 

있으므로 시퀀스를 초기화 해주기로 해보자


2. MySQL 시퀀스 초기화


시퀀스 초기화 하고자 할 경우는 하단의 명령어를 주면 간단하게 시퀀스값이 초기화가 된다.

alter table test_board auto_increment=1;

위와같이 alter table 후 test_board(시퀀스컬럼을 초기화 하고자 하는 테이블명) 을 지정 후 auto_increment=1(자동증가값 update를 해준다)

그럼 초기화가 정상적으로 되는지 임의의 시나리오를 작성하도록 하자


1) test_board의 데이터 모두 delete

2) 시퀀스 초기화 작업(alter table xxx auto_increment=x)

3) 다시한번 insert 쿼리 

4) select 구문을 통화 데이터 확인


위와같이 시나리오를 실행한 결과 다음과 같이 시퀀스 컬럼이 초기화 된 후, 

자동증가하여 컬럼에 추가되는것을 확인 할 수 있었다.






슈퍼맨슈퍼맨슈퍼맨



도움이 되셨다면 공감클릭! 궁금하신점은 댓글!!



출처: http://roqkffhwk.tistory.com/136 [야근싫어하는 개발자]

출처: http://roqkffhwk.tistory.com/136 [야근싫어하는 개발자]

출처: http://roqkffhwk.tistory.com/136 [야근싫어하는 개발자]

출처: http://roqkffhwk.tistory.com/136 [야근싫어하는 개발자]

출처: http://roqkffhwk.tistory.com/136 [야근싫어하는 개발자]

출처: http://roqkffhwk.tistory.com/136 [야근싫어하는 개발자]

출처: http://roqkffhwk.tistory.com/136 [야근싫어하는 개발자]

출처: http://roqkffhwk.tistory.com/136 [야근싫어하는 개발자]

출처: http://roqkffhwk.tistory.com/136 [야근싫어하는 개발자]

728x90
<script> 
function submit(login){ 
  form.submit();  

</script> 

폼부분은 이렇습니다. 
<form name=login method=post action=login_process.php>  -------------> method는 get으로도 해봤습니다. 

<input name="login_button" type="image" src="login_button.gif" border="0" onclick='javascript:submit(this.form);window.close();opener.document.location.reload();'  > 

opener.document.location.reload(); --------------------> 아래는 요부분에 넣어본것들 
//opener.parent.location.reload(); 
//opener.document.location.reload('main.php'); 
//opener.parent.location.reload('main.php'); 
//opener.location.replace('main.php'); 
//opener.location.reload('main.php'); 
//opener.location.reload(); 
//opener.window.location.reload(); 

스크립트 게시판에서 이렇다할 답변이 없어서요. 이런식으로 세션값 표시하는 분들이 여기에 더 많이 계실것 같아서 질문 올리네요.부디 php소스 없어서 게시판 잘못찾아왔다고 탓하지 마시고 답변 기다릴께요. 

자식창에서 로그인버튼 누르면 window.open으로 창이 열리고 
 1...로그인처리를 하고 
 2...자식창을 닫고 
 3...부모창을 새로고침해서 
 4...부모창의 상단에 세션값을 표시한다 

1,2는 되고요, 3은 reload는 하는것 같은데(화면이 창뜰때 처럼 잠깐 한번 깜빡임) 세션값이 표시가 안돼고요 4는 수동으로 브라우져의 새로고침을 눌러야 표시되네요. 

제가 많이 초보인지라 쉬운 설명과 가르침 부탁드릴꼐요.
  • 답변채택율 100%
  • 추천 0
  • 비추천 0

전체댓글수 4

  • 기술레벨커뮤니티레벨공대여자 06-06-30 13:25 

    소스보기

  • <input name="login_button" type="image" src="login_button.gif" border="0" onclick='javascript:submit(this.form);window.close();opener.document.location.reload();'  > 
    -> 
    처리 순서 때문입니다. 
    1.submit(this.form); 
    ----------=---------- 
    1을 처리합니다. page가 login_process.php 로 바뀝니다. 
    페이지가 나뀌니 JS함수는 더이상 진행되지 않습니다. 
    솔찍히 진행 된다면, 아마 딜레이 타임 때문이겠죠. 
    ---------=---------- 
    원하는데로 하실려면, 
    2.window.close(); 
    3.opener.document.location.reload();를 
    login_process.php에서 실행하시면 됩니다.
  • 기술레벨커뮤니티레벨이크 작성자 06-06-30 14:14 

    소스보기

  • 아...............됩니다 되요!!!! 
    공대여자님 너므너므 감사드립니다~~~ 
    echo("<body onLoad=javascript:window.close();opener.document.location.reload();> "); 
    이렇게 했는데요. 더 좋은 방법이 있으면 알려주세요~
  • 기술레벨커뮤니티레벨공대여자 06-06-30 14:40 

    소스보기

  • echo("<body onLoad=javascript:window.close();opener.document.location.reload();> "); 
    -> 
    echo("<body onLoad='opener.document.location.reload();window.close();'> "); 

    이벤트에는 javascript:를 붙일 필요가 없습니다. 
    1.window.close(); 
    2.opener.document.location.reload(); 
    2번이 먼저 실행되야합니다. 
    이유는 1번이 실행되면 창이 닫히는데, 그러면 다음게 실행안되죠. 
    (라고하지만... 엄격하지 않아서..)
  • 기술레벨커뮤니티레벨이크 작성자 06-07-01 13:13 

    소스보기

  • 자세하고 친절한 설명에 너무 감사드려요~~ 열심히 해서 척척 해나가는것이 답변에 대한 보답이겠죠..그럼 건강하세요~


'WEB' 카테고리의 다른 글

[PHP] setcookie, unset  (0) 2018.02.18
MySQL 시퀀스 생성하기  (0) 2018.02.14
[tradingview] Dividing candlesticks. #2072  (0) 2018.02.07
[PHP] Parsing  (0) 2018.02.05
[PHP] number with comma  (0) 2018.02.05
728x90

cheekyxy commented on 5 Oct 2017  

  • Version: "1.10"
  • Device: Windows 10
  • Browser: Google chrome

Scenario : Suppose I selected 1 month timeframe and then I want candlesticks accoding to 5min or 15min or any other time I select .
Lets say I have selected 1 day timeframe and then I select 4H candlestick option.So the chart should display 24/4 = 6 candle sticks .
So I want to know that how it can be done ?
I have attached a screenshot for example.
chart

@timocov

timocov commented on 5 Oct 2017

Hi,

  1. You can use setVisbibleRange method https://github.com/tradingview/charting_library/wiki/Chart-Methods#setvisiblerangerange-callback
  2. You can wait until we implements #2060
@cheekyxy

cheekyxy commented on 5 Oct 2017  

@timocov I to want implement the things as below:

  • First select the timeframe
    -Then the candle sticks should be shown according to Candlesticks option as shown in screenshots below:
    1 .
    chart1

chart2

@timocov

timocov commented on 5 Oct 2017

Yeah, I get it and my answer is exactly about it.

@timocov

timocov commented on 10 Oct 2017

  1. Where you call setVisibleRange? I saw it only for timeframe=='12m' in your code.
  2. Your datafeed does not support 3min resolution.
@cheekyxy

cheekyxy commented on 10 Oct 2017  

@timocov
Leave setVisibleRange for now but what should I do to support my datafeed of 1min,3min,5min ?
Please help me with that !

@cheekyxy

cheekyxy commented on 10 Oct 2017

@timocov @ezhukovskiy
After updating supported resolutions in my datafeed the resolutions are still disabled as shown in screenshot :
min_chart1

@timocov

timocov commented on 10 Oct 2017

Because your symbol does not support this resolutions. See https://github.com/tradingview/charting_library/wiki/Symbology#supported_resolutions

@cheekyxy

cheekyxy commented on 10 Oct 2017

@timocov
What should I do make it support ? Because I have commented the code for symbols search in datafeed . I just want to make it supportable.

@timocov

timocov commented on 10 Oct 2017

In symbol info you should specify which resolutions symbol supports. Please read article https://github.com/tradingview/charting_library/wiki/Symbology

@cheekyxy

cheekyxy commented on 11 Oct 2017

@timocov
Thanks a lot . Your symbolinfo suggestion worked.

@cheekyxy

cheekyxy commented on 11 Oct 2017

@timocov
I don't want to show highlighted part in my chart as shown in screenshot below . Would you help me with this ?

Screenshot : https://www.screencast.com/t/ZMp6wlEp

@cheekyxy

cheekyxy commented on 13 Oct 2017

@timocov @ezhukovskiy

Is it possible to change the data for chart when time interval is changed ?

@timocov

timocov commented on 13 Oct 2017

When interval changed the library will rerequest the data. What do you mean?

@cheekyxy

cheekyxy commented on 13 Oct 2017  

@timocov

I mean I have to change the data totally. I have to request data from another URL.

@timocov

timocov commented on 13 Oct 2017

Sorry, but it is not issue anymore.

@timocov timocov closed this on 13 Oct 2017


'WEB' 카테고리의 다른 글

MySQL 시퀀스 생성하기  (0) 2018.02.14
[PHP]자식창에서 부모창 새로고침해서 부모창에 세션결과 표시하기  (0) 2018.02.09
[PHP] Parsing  (0) 2018.02.05
[PHP] number with comma  (0) 2018.02.05
[Google Chart] Candle Stick  (0) 2018.01.30
728x90


데이터의 다음 행을 숫자로 인덱싱된 배열, 결합형 배열 또는 둘 다로 검색합니다.

구문


sqlsrv_fetch_array( resource $stmt[, int $fetchType [, row[, ]offset]])  

매개 변수

$stmt: 실행된 문에 해당하는 문 리소스입니다.

$fetchType [선택 사항]: 미리 정의 된 상수입니다. 이 매개 변수는 다음 표에 나열된 값 중 하나를 사용할 수 있습니다.

Description
SQLSRV_FETCH_NUMERIC데이터의 다음 행이 숫자형 배열로 반환됩니다.
SQLSRV_FETCH_ASSOC데이터의 다음 행이 결합형 배열로 반환됩니다. 배열 키는 결과 집합의 열 이름입니다.
SQLSRV_FETCH_BOTH데이터의 다음 행이 숫자형 배열과 결합형 배열 둘 다로 반환됩니다. 이 값은 기본값입니다.

 [선택 사항]: 버전 1.1에에서 추가 합니다. 다음 값 중 하나로 스크롤 가능 커서를 사용하는 결과 집합에서 액세스할 행을 지정합니다. (때  지정 된 fetchtype 명시적으로 지정 해야 기본값을 지정 하는 경우에 합니다.)

  • SQLSRV_SCROLL_NEXT
  • SQLSRV_SCROLL_PRIOR
  • SQLSRV_SCROLL_FIRST
  • SQLSRV_SCROLL_LAST
  • SQLSRV_SCROLL_ABSOLUTE
  • SQLSRV_SCROLL_RELATIVE

이러한 값에 대한 자세한 내용은 커서 유형 지정 및 행 선택을 참조하세요. 스크롤 가능 커서 지원이 Microsoft Drivers for PHP for SQL Server의 버전 1.1에 추가되었습니다.

오프셋 [선택 사항]: 검색할 행을 지정 하려면 데 SQLSRV_SCROLL_ABSOLUTE 및 SQLSRV_SCROLL_RELATIVE 함께 사용 합니다. 결과 집합의 첫 번째 레코드는 0입니다.

반환 값

데이터 행이 검색되는 경우 배열 이 반환됩니다. 검색할 행이 더 이상 없는 경우 null 이 반환됩니다. 오류가 발생하면 false 가 반환됩니다.

$fetchType 매개 변수의 값을 기반으로, 반환된 배열 은 숫자로 인덱싱된 배열, 결합형 배열또는 둘 다일 수 있습니다. 기본적으로 숫자 키와 결합형 키가 둘 다 있는 배열 이 반환됩니다. 반환된 배열에 있는 값의 데이터 형식은 기본 PHP 데이터 형식입니다. 기본 PHP 데이터 형식에 대한 자세한 내용은 Default PHP Data Types을 참조하세요.

주의

이름이 없는 열이 반환되면 배열 요소에 대한 결합형 키는 빈 문자열("")입니다. 예를 들어 값을 데이터베이스 테이블에 삽입하고 서버 생성 기본 키를 검색하는 다음 Transact-SQL 문을 고려해 보겠습니다.

INSERT INTO Production.ProductPhoto (LargePhoto) VALUES (?);  
SELECT SCOPE_IDENTITY()

반환 된 결과 집합이 SELECT SCOPE_IDENTITY() 이 문의 부분 결합형 배열로 검색 되 인 반환된 된 값에 대 한 키는 빈 문자열 ("")는 반환 된 열에 이름이 없기 때문에 합니다. 이를 방지하려면 결과를 숫자형 배열로 검색하거나 Transact-SQL 문에서 반환된 열에 대한 이름을 지정할 수 있습니다. 다음은 Transact-SQL에 열 이름을 지정하는 한 가지 방법입니다.

SELECT SCOPE_IDENTITY() AS PictureID

결과 집합에 이름이 없는 여러 열이 포함된 경우 마지막으로 이름이 지정되지 않은 열의 값이 빈 문자열("") 키에 할당됩니다.

예제

다음 예제는 결과 집합의 각 행을 결합형 배열로 검색합니다. 이 예제에서는 SQL Server 및 AdventureWorks 데이터베이스가 로컬 컴퓨터에 설치된 것으로 가정합니다. 모든 출력은 명령줄에서 예제가 실행될 때 콘솔에 기록됩니다.

<?php  
/* Connect to the local server using Windows Authentication and  
specify the AdventureWorks database as the database in use. */  
$serverName = "(local)";  
$connectionInfo = array( "Database"=>"AdventureWorks");  
$conn = sqlsrv_connect( $serverName, $connectionInfo);  
if( $conn === false )  
{  
     echo "Could not connect.\n";  
     die( print_r( sqlsrv_errors(), true));  
}  

/* Set up and execute the query. */  
$tsql = "SELECT FirstName, LastName  
         FROM Person.Contact  
         WHERE LastName='Alan'";  
$stmt = sqlsrv_query( $conn, $tsql);  
if( $stmt === false)  
{  
     echo "Error in query preparation/execution.\n";  
     die( print_r( sqlsrv_errors(), true));  
}  

/* Retrieve each row as an associative array and display the results.*/  
while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC))  
{  
      echo $row['LastName'].", ".$row['FirstName']."\n";  
}  

/* Free statement and connection resources. */  
sqlsrv_free_stmt( $stmt);  
sqlsrv_close( $conn);  
?>  

예제

다음 예제는 결과 집합의 각 행을 숫자로 인덱싱된 배열로 검색합니다.

제품 정보를 검색 하는 예제는 Purchasing.PurchaseOrderDetail 지정된 된 날짜와 재고량이 있는 제품에 대 한 AdventureWorks 데이터베이스의 테이블 (StockQty) 지정된 된 값 보다 작습니다.

이 예제에서는 SQL Server 및 AdventureWorks 데이터베이스가 로컬 컴퓨터에 설치된 것으로 가정합니다. 모든 출력은 명령줄에서 예제가 실행될 때 콘솔에 기록됩니다.

<?php  
/* Connect to the local server using Windows Authentication and  
specify the AdventureWorks database as the database in use. */  
$serverName = "(local)";  
$connectionInfo = array( "Database"=>"AdventureWorks");  
$conn = sqlsrv_connect( $serverName, $connectionInfo);  
if( $conn === false )  
{  
     echo "Could not connect.\n";  
     die( print_r( sqlsrv_errors(), true));  
}  

/* Define the query. */  
$tsql = "SELECT ProductID,  
                UnitPrice,  
                StockedQty   
         FROM Purchasing.PurchaseOrderDetail  
         WHERE StockedQty < 3   
         AND DueDate='2002-01-29'";  

/* Execute the query. */  
$stmt = sqlsrv_query( $conn, $tsql);  
if ( $stmt )  
{  
     echo "Statement executed.\n";  
}   
else   
{  
     echo "Error in statement execution.\n";  
     die( print_r( sqlsrv_errors(), true));  
}  

/* Iterate through the result set printing a row of data upon each  
iteration.*/  
while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_NUMERIC))  
{  
     echo "ProdID: ".$row[0]."\n";  
     echo "UnitPrice: ".$row[1]."\n";  
     echo "StockedQty: ".$row[2]."\n";  
     echo "-----------------\n";  
}  

/* Free statement and connection resources. */  
sqlsrv_free_stmt( $stmt);  
sqlsrv_close( $conn);  
?>  

sqlsrv_fetch_array 함수에 따라 데이터는 항상 반환 된 기본 PHP 데이터 형식합니다. PHP 데이터 형식을 지정하는 방법에 대한 자세한 내용은 How to: Specify PHP Data Types을 참조하세요.

이름이 없는 필드가 검색되는 경우 배열 요소에 대한 결합형 키는 빈 문자열("")입니다. 자세한 내용은 sqlsrv_fetch_array를 참조하세요.

참고 항목

SQLSRV 드라이버 API 참조
데이터 검색
설명서의 코드 예제 정보
PHP SQL 드라이버 프로그래밍 가이드

'DB' 카테고리의 다른 글

PATH=$PATH:/usr/local/mysql/bin;  (0) 2018.04.19
SQL Database Performance Tuning for Developers  (0) 2018.04.10
[MSSQL]sqlsrv_execute  (0) 2018.02.05
jQuery mouseleave()  (0) 2018.01.14
mysqli_result::fetch_array  (0) 2018.01.14

+ Recent posts