[MSSQL] Cursor

Program/MS-SQL 2017.06.28 09:00

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

-- =============================================

-- Author: <Author,,Name>

-- Create date: <Create Date,,>

-- Description: <Description,,>

-- =============================================

CREATE PROCEDURE proc_test

AS

BEGIN

SET NOCOUNT ON;


 declare @I_TMP_SEQ int -- 커서 table seq


DECLARE F_CURSOR CURSOR FAST_FORWARD GLOBAL FOR

select seq from table_name


OPEN F_CURSOR

FETCH NEXT FROM F_CURSOR INTO @I_TMP_SEQ

WHILE @@FETCH_STATUS = 0

BEGIN

  select * from table_name where seq = @i_tmp_seq;



FETCH NEXT FROM F_CURSOR INTO @I_TMP_SEQ

  END


CLOSE F_CURSOR

DEALLOCATE F_CURSOR


END

GO


Posted by 감자타다



#include <stdio.h>
#include <string>

#ifdef _WIN32
#include <winsock2.h>
#pragma comment(lib, "ws2_32.lib")
#endif
using namespace std;


WSADATA wsaData;
WSAStartup(MAKEWORD(2, 2), &wsaData);

PHOSTENT hostinfo;
char hostname[50];
char ipaddr[50];
memset(hostname, 0, sizeof(hostname));
memset(ipaddr, 0, sizeof(ipaddr));

int nError = gethostname(hostname, sizeof(hostname));
if (nError == 0)
{
hostinfo = gethostbyname(hostname);
// ip address 파악
strcpy(ipaddr, inet_ntoa(*(struct in_addr*)hostinfo->h_addr_list[0]));
}

WSACleanup();


CString myip;

myip.Format("%s", ipaddr);


Posted by 감자타다

SOCKADDR_IN sockAddr;

memset(&sockAddr, 0, sizeof(sockAddr));

int nSockAddrLen = sizeof(sockAddr);

BOOL bResult = m_pClientSocket->GetPeerName((SOCKADDR*)&sockAddr, &nSockAddrLen);

if(bResult)

{

ntohs(sockAddr.sin_port);

inet_ntoa(sockAddr.sin_addr);

}



sprintf(channels[MAXLOGARRAY].attribute.logmsg,"접속 - 소켓번호[%d], 접속IP[%s]",m_pClientSocket->m_hSocket, inet_ntoa(sockAddr.sin_addr));

// sprintf(channels[MAXLOGARRAY].attribute.logmsg,"클라이언트 접속(%d)",m_pClientSocket->m_hSocket);


trace_log_socket(m_pClientSocket->m_hSocket,channels[MAXLOGARRAY].attribute.logmsg);

// trace_log(index,channels[MAXLOGARRAY].attribute.logmsg);

Posted by 감자타다