반응형

window.onload는 모든 DOM 요소가 로딩된 후 실행


$(document).ready()는 dom이 준뵈 되거나 준비 상태일 때 실행


$(window).load()는 모든 이미지, 텍스트, css, stylesheets와 JS File이 로딩된 후 실행.

$(document).ready 보다 이후 실행.


참고 사이트 : https://www.techiediaries.com/javascript/document-ready-vs-window-onload-vs-window-load/


* 추가로 JQuery에서 $(function(){ code...});와 같이 사용되는 구문은 $(document).ready(fucntion() {code...}) 코드와 동일하다.


반응형

'웹 프로그래밍 > JavaScript' 카테고리의 다른 글

JavaScript xml 파싱  (0) 2016.02.05
JavaScript xml 사용  (0) 2016.01.27
JavaScript 함수 선언  (0) 2016.01.04
반응형


Client 란?

- 사용자가 사용하는 브라우저

- 항상 Request를 보내는 객체

- Web Server에 request를 전송하여 받은 응답값을 웹 페이지에 표시


Web Server 란?

- Client의 요청에 대한 문서를 제공하는 서버





Request Headers 란?


- 웹 브라우저에서 웹 서버에 전달해주는 데이터

- Request Header로 전달 받은 값으로 웹 서버에 적용


Response Headers 란?


- 웹 서버에서 웹 브라우저로 전달해주는 데이터




정리 된 사이트 : https://developer.mozilla.org/ko/docs/Web/HTTP/Overview

반응형

'웹 프로그래밍 > HTTP' 카테고리의 다른 글

Cross-origin resource sharing  (0) 2018.09.12
반응형

자바스크립트 코딩을 하다 알게된 오류에 대해 서술.

1. A 사이트에서 B 사이트 팝업창을 띄움

2. B 사이트 팝업창 버튼을 클릭시 A사이트의 브라우저 탭에 다른 A사이트 페이지를 띄움.


B 사이트 소스에 자바 스크립트 opener.window.open을 이용하여 2번 기능을 구현할려고 하였다.

하지만 CORS 문제로 인해 opener 접근 자체가 되지 않는다.

Request headers의 Origin과  요청한 웹 서버의 Access-Control-Allow-Origin에 허용 되지 않아 발생!

POST같은 요청을 보낼 때, 요청이 어느 주소에서 시작되었는지를 나타냅니다. 여기서 요청을 보낸 주소와 받는 주소가 다르면 CORS 문제가 발생하기도 합니다.



Cross-origin resource sharing

Cross-origin resource sharing(CORS)는 어느 한 웹 페이지에서 다른 웹 도메인의 웹 사이트 페이지에 자원 접근 요청을 막는다.


특히 Ajax 요청은 same-origin security policy 정책에 의해 기본적으로 접근이 불가능하다.


CORS는 아래의 로직으로 실행된다.




*출처 : Wikipiedia 문서 - https://en.wikipedia.org/wiki/Cross-origin_resource_sharing



CORS와 관련된 Headers


Request headers

- Origin

- Access-Control-Request-Method

- Access-Control-Request-Headers


Response headers

- Access-Control-Allow-Origin

- Access-Control-Allow-Credentials

- Access-Control-Expose-Headers

- Access-Control-Max-Age

- Access-Contorl-Allow-Method

- Access-Control-Allow-Headers


CORS의 해결법


접근할 다른 도메인의 웹 서버의 헤더에 아래 값을 추가하면 된다.


Access-Control-Allow-Origin : 접근을 허용할 웹사이트 도메인

Ex) 네이버에서의 접근을 허용할려면 Access-Control-Allow-Origin : http://www.naver.com


참고 사이트 : https://developer.mozilla.org/ko/docs/Web/HTTP/Access_control_CORS







반응형

'웹 프로그래밍 > HTTP' 카테고리의 다른 글

Client Web Server 와 Request Response  (0) 2018.09.12
반응형

TABLE COLUMN 속성 변경


1. 제약조건이 없는 테이블 컬럼 변경 SQL 쿼리


ALTER TABLE [table name] ALTER COLUMN [column name] [date type] [NULL | NOT NULL]


2. 속성을 변경할 테이블 컬럼에 제약조건이 걸려 있는 경우

1번 쿼리를 실행하면 


Msg 5074, Level 16, State 1, Line 2
개체 'DF_SampleTable_Name'은(는) 열 'Name'에 종속되어 있습니다.
Msg 4922, Level 16, State 9, Line 2
하나 이상의 개체가 이 열에 액세스하므로 ALTER TABLE ALTER COLUMN Name이(가) 실패했습니다


위와 같은 에러메세지가 발생한다.

위 에러 메세지는 속성을 변경할 해당 컬럼에 "Primary key"가 설정되어 있거나 "기본값 또는 바인딩" 또는 "그 외 제약 조건"이 설정되어 있어서 발생하는 경우이다.


위 에러 메세지를 해결하기 위해 해당 컬럼에 적용된 제약조건을 제거하고 컬럼 속성을 변경 또는 삭제하면 된다.


먼제 삭제할 제약 조건의 이름을 확인하기 위해 Table에 걸린 제약 조건 확인 SQL 쿼리를 실행한다.


EXEC sp_helpindex [table name]


위 쿼리로 Table에 설정된 Key를 확인할 수 있다.


기본값 또는 바인딩 제약 조건명은 컬럼 변경 SQL문을 실행할 때 발생하는 오류 메세지에서 확인 할 수 있다. 위 오류 메세지에서는 "DF_SampleTable_Name" 이 Name컬럼에 걸린 기본값 또는 바인딩을 설정한 제약 조건의 이름이다.


제약 조건 삭제 SQL 쿼리


ALTER TABLE [table name] DROP CONSTRAINT [제약 조건 이름]


위 쿼리로 제약조건을 제거 할 수 있다.


제약 조건을 제거하면 1번에서 소개한 쿼리문을 실행하여 테이블 컬럼 속성을 변경할 수 있다.


* 단 컬럼 내 데이터가 변경할 데이터 타입으로 형식이 아니면 컬럼 데이터 타입 속성 변경이 실패한다.


반응형

'Database > SQL Server' 카테고리의 다른 글

B-TREE 구조  (0) 2018.11.15
SQL 실행계획  (0) 2018.11.12
Database 내 모든 테이블 정보 확인  (0) 2018.06.14
동적 쿼리와 정적 쿼리  (0) 2018.05.23
Stored Procedure(저장 프로시저)  (0) 2018.05.23
반응형

Database 살펴 볼 때 내부 테이블들의 모든 정보를 알고 싶은 경우가 있다.


각 테이블을 조회하는 노가다 성 작업으로 해결할 수 도 있지만 테이블의 수가 많을 경우는 많은 시간이 소비된다.


다행히 한번에 모든 테이블 정보를 볼 수 있는 sql 쿼리문이 있다.


SELECT * FROM INFORMATION_SCHEMA.COLUMNS ORDER BY TABLE_NAME


위 쿼리문을 동작하면 Database 내 모든 테이블 컬럼 정보를 확인할 수 있다.


*Microsoft SQL Server Management Studio에서 실행.

반응형

'Database > SQL Server' 카테고리의 다른 글

SQL 실행계획  (0) 2018.11.12
[MSSQL] Table Column 속성 변경  (0) 2018.06.25
동적 쿼리와 정적 쿼리  (0) 2018.05.23
Stored Procedure(저장 프로시저)  (0) 2018.05.23
MS-SQL SP_EXECUTESQL  (0) 2018.05.23
반응형

Modals

data-toggle="modal" - Triggers click to open a modal dialog referenced by data-target="element"data-target="target-element" - The element that the modal should open (can be #id or .class)
data-dismiss="modal" - Triggers close of the modal on click


Dropdowns

data-toggle="dropdown" - Triggers click to open a drop-down
data-target="#" - Only exists to help when use the dropdown on link to prevent url change


ScrollSpy

data-spy="scroll" - Triggers the SpyScroll on the element (usually goes to <body>
data-target="target-element" - The element that the scroll-spy should by applied to
data-offset="X" - X represents the number of pixels from top when calculating position of scroll


Togglable tabs

data-toggle="tab" - Triggers click to open the relevant tab referenced by data-target="element"
data-toggle="pill" - Same as tab but for pill-styling
data-target="target-element" - The element that the modal should open (can be #id or .class)


Tooltips

data-toggle="tooltip" - Triggers adding a tooltip to the element

data-animation
data-container
data-delay
data-html
data-placement
data-selector
data-template
data-title
data-trigger
data-viewport


Popovers

data-toggle="popover" - Triggers click to open a popover

data-animation
data-container
data-content
data-delay
data-html
data-placement
data-selector
data-template
data-title
data-trigger
data-viewport


Alert messages

data-dismiss="alert" - Triggers click to close the alert box created by bootstrap


Buttons

data-loading-text="Loading..." - Show a text while loading (note that it's deprecated)
data-toggle="button" - note the singular Makes a button single toggle-button data-toggle="buttons" - note the plural Makes a group of buttons a toggle-buttons
data-complete-text="Finished" - Text to change on button when the method complete is called


Collapse

data-toggle="collapse" - Triggers click to collapse the referenced element
data-target="element" - The referenced element
data-parent="element" - The parent element, used for accordion-style collapsing


Carousel

data-ride="carousel" - Triggers a slide-show (carousel) on the container
data-target="element" - The referenced carousel element that this element is part of
data-slide-to="X" - X is the number of the next slide
data-slide="prev|next" - Triggers click to toggle the carousel to the prev|next slide
data-interval="X" - The amount of time to delay between automatically cycling an item
data-pause="hover" - Pause the cycling on mouse over
data-wrap="true" - Whether the carousel should cycle continuously or have hard stops
data-keyboard="true" - Whether the carousel should react to keyboard events


Affix

data-spy="affix" - Triggers affix (emulating the sticky positioning effect)
data-offset-top="X" - Number of pixels to offset the element from top
data-offset-bottom="X" - Number of pixels to offset the element from bottom

*참고 사이트 : https://stackoverflow.com/questions/38336625/how-many-data-attributes-there-are-in-bootstrap-what-they-do-and-what-are-the-p

https://getbootstrap.com/docs/3.3/javascript/

반응형
반응형

동적쿼리

- 코드 실행 시점에 SQL 쿼리문이 동적으로 구성되고 실행되는 쿼리

- Stored Procedure를 생성할 때 필요에 따라 동적 쿼리로 작성

- 동적 쿼리 실행 SQL 문자열에 값이 바뀌는 변수를 넣어 쿼리문을 작성하게 되면 SP가 새로 캐싱되어 재사용성을 떨어트림


정적쿼리

- 변수에 문자열을 대입하여 쿼리문을 작성하는 것이 아닌 일반적으로 작성된 SQL 쿼리

- 정적 쿼리로 작성된 Stored Procedure는 새로 캐싱되지 않아 재사용성을 떨어트리지 않는다.


* 위 내용을 요약하자면 작성한 쿼리가 어떠한 상황에서도 변경되지 않는 쿼리가 정적쿼리가 될 것이고 입력값이나 특정 상황에 따라 쿼리문이 변경될 수 있는 쿼리가 동적쿼리이다.


동적쿼리의 실행

- 동적쿼리는 EXEC()함수를 사용하거나 SP_EXECUTESQL을 사용하여 실행한다.




Stored Procedure(저장 프로시저) < 동적쿼리로 작성된 SP 예제가 있으니 참고

반응형

'Database > SQL Server' 카테고리의 다른 글

SQL 실행계획  (0) 2018.11.12
[MSSQL] Table Column 속성 변경  (0) 2018.06.25
Database 내 모든 테이블 정보 확인  (0) 2018.06.14
Stored Procedure(저장 프로시저)  (0) 2018.05.23
MS-SQL SP_EXECUTESQL  (0) 2018.05.23
반응형

MS SQL Stored Procedure


저장 프로시저란?

- SQL Query문들을 하나의 함수처럼 실행하기 위한 Query의 집합


장점 

  1. 하나의 요청으로 여러 SQL 쿼리를 실행하여 네트워크 부하 감소
  2. 미리 구문 분석 및 내부 중간 코드로 변환을 끝내야 함으로 처리 시간 감소
  3. 최초 사용한 SP는 캐싱이 되어 재사용이 용이
  4. 사용자에게 테이블 접근 권한을 대신 프로지서 접근 권한을 주어 DataBase 보안성 강화
  5. 모듈식 프로그래밍 가능

SP 작성 방법 



위와 같이 SSMS(2014) 에서 클릭하면 아래와 같은 파일이 생긴다



매개 변수
작성자Your name
만든 날짜Today's date
DescriptionReturns employee data
Procedure_nameHumanResources.uspGetEmployeesTest
@Param1@LastName
@Datatype_For_Param1nvarchar(50)
Default_Value_For_Param1NULL
@Param2@FirstName
@Datatype_For_Param2nvarchar(50)
Default_Value_For_Param2NULL


각 매개 변수칸에 입력 값을 넣어주어 실행하면 SP가 만들어 진다.









예제 SP를 실행하기 위한 table 셋팅


CREATE TABLE testTable(

NAME NVARCHAR(50),

AGE INT)

GO


INSERT INTO testTable (NAME,AGE) VALUES ('코드블랙',15)

INSERT INTO testTable (NAME,AGE) VALUES ('홍길동',25)

INSERT INTO testTable (NAME,AGE) VALUES ('김복남',35)

INSERT INTO testTable  (NAME,AGE) VALUES ('이순신',52)

INSERT INTO testTable (NAME,AGE) VALUES ('둘리',26)


SELECT * 

FROM testTable


위 쿼리를 실행하면 테이블을 만들고 만들어진 테이블 내용을 확인할 수 있다.








동적쿼리와 sp_executesql을 이용한 입력 변수와 출력변수가 있는 SP 예제

- @input의 입력 값의 유무에 따라 WHERE절을 @Sql String에 추가하여 Sql문이 새로 캐싱 되는 SP


CREATE PROCEDURE TestSP 

-- Add the parameters for the stored procedure here

    @input       NVARCHAR(50) =null,

    @output     INT                 =0   OUT

AS


----------------------------------------------------

--sp_executesql을 실행할 변수 선언

----------------------------------------------------


DECLARE @Sql      NVARCHAR(MAX) = ''

DECLARE @Where  NVARCHAR(MAX) = ''

DECLARE @Param  NVARCHAR(MAX) = ''


----------------------------------------------------

--입력 이름이 들어오면 WHERE절 추가

----------------------------------------------------

IF ISNULL(@input,'') <> '' BEGIN

SET @Where = @Where + N'

    WHERE NAME = @input '

END


BEGIN

-- SET NOCOUNT ON added to prevent extra result sets from

-- interfering with SELECT statements.

SET NOCOUNT ON;


SET @Sql = @Sql + N'

    SELECT @output = AGE

    FROM   dbo.testTable '


SET @Sql = @Sql + @Where


SET @Param = N'

    @input  NVARCHAR(50),

    @output INT OUT '


EXEC SP_EXECUTESQL @Sql

                  ,@Param

                  ,@input  = @input

                  ,@output = @output


반응형

'Database > SQL Server' 카테고리의 다른 글

SQL 실행계획  (0) 2018.11.12
[MSSQL] Table Column 속성 변경  (0) 2018.06.25
Database 내 모든 테이블 정보 확인  (0) 2018.06.14
동적 쿼리와 정적 쿼리  (0) 2018.05.23
MS-SQL SP_EXECUTESQL  (0) 2018.05.23
반응형

[MS-SQL SP_EXECUTESQL]



@stmt

- 유니코드 문자열이나 SQL쿼리문을 일괄 처리

- @stmt 유니코드 상수 또는 문자열만 가능

- N'문자열'은 가능하지만 '문자열'은 불가능


@params

- @stmt에 포함된 몯느 매개변수의 정의를 포함하는 유니코드 문자열

- @stmt와 동일하게 유니코드 문자열이나 상수만 가능

- 출력 변수일 경우 [OUT|OUTPUT] 명시


@param1...n

- 매개변수 문자열에 정의 된 첫번째 매개변수의 값

- @stmt에 제공되는 모든 매개변수에 대해 제공되는 매개변수 값이 있어야 한다







*참고문서 https://docs.microsoft.com/ko-kr/sql/relational-databases/system-stored-procedures/sp-executesql-transact-sql?view=sql-server-2017



반응형

'Database > SQL Server' 카테고리의 다른 글

SQL 실행계획  (0) 2018.11.12
[MSSQL] Table Column 속성 변경  (0) 2018.06.25
Database 내 모든 테이블 정보 확인  (0) 2018.06.14
동적 쿼리와 정적 쿼리  (0) 2018.05.23
Stored Procedure(저장 프로시저)  (0) 2018.05.23
반응형

Python 2.7 Single Linked list 구현


참고자료 : starmooc.kr kaist 문일철 교수 데이터구조 및 분석 인강


class Node:

value = ''

nextnode = ''

binhead = False

bintail = False


def __init__(self, value='', nextnode='', binhead=False, bintail=False):

self.value = value

self.nextnode = nextnode

self.binhead = binhead

self.bintail = bintail

def getValue(self):

return self.value

def setValue(self, value=''):

self.value = value

def getNext(self):

return self.nextnode

def setNext(self, nextnode=''):

self.nextnode = nextnode

def isTail(self):

return self.bintail

def isHead(self):

return self.binhead




class SinglyLinkedlist:

nodehead = ''

nodetail = ''

size = 0


def __init__(self):

self.nodetail = Node(bintail = True)

self.nodehead = Node(binhead = True, nextnode = self.nodetail)

def insertAt(self, objInsert, idxInsert):

nodeNew = Node(value=objInser)

nodePrev = self.get(idxInsert - 1)

nodeNext = nodePrev.getNext()

nodePrev.setNext(nodeNew)

nodeNew.setNext(nodeNext)

self.size = self.size+1

def removeAt(self, idxRemove):

nodePrev = self.get(idxRemove - 1)

nodeRemove = nodePrev.getNext()

nodeNext = nodeRemove.getNext()

nodePrev.setNext(nodeNext)

self.size = self.size - 1

return nodeRemove.getValue()

def get(self, idxRetrieve):

nodeReturn = self.nodeHead

for itr in range(idxRetreve + 1):

nodeReturn = nodeReturn.getNext()

return nodeReturn

def printStatus(self):

nodeCurrent = self.nodehead

while nodeCurrent.getNext().isTail() == False:

nodeCurrent = nodeCurrent.getNext()

print nodeCurrent.getValue(),

print

def getSize(self)

return self.size


반응형

'프로그래밍 > Python' 카테고리의 다른 글

[Python]sqlalchemy 사용법  (0) 2022.12.07
[PYTHON] 파이썬 함수 매개변수  (0) 2022.08.11
[Python] flask_restful fields  (0) 2021.10.08
창원시 버스 API 사용하기  (1) 2016.02.22

+ Recent posts