Skip to Content

原文链接:http://scn.sap.com/community/developer-center/hana/blog/2012/07/27/bring-some-euphoria-to-sap-hana

免责声明:这篇博客是基于我的个人经验,没有经过SAP的认可或支持。通过ODBC连到SAP HANA没有被SAP认可或支持,因此你必须自己承担使用它的风险,没有支持可供。

作为一个技术的传教士,我总是试图创造新的内容,与我的开发者同胞们分享,所以有一天我在学习了一些Node.JS之后,我突然想起了一种我大概十年前用的编程语言……Euphoria……它现在被称之为OpenEuphoria,因为它是开源代码。

为什么有人该关注Euphoria?嗯……根据网站上所述……“它比Basic更加简单,而且比C++更加强大”……我为了这篇博客再次用了它,我必须说,它仍然没有失去这种魔法……Euphoria是一种可爱的编程语言,有巨大的可选。

因此……为什么我们需要开始?

为此博客,我试图用我的Windows7,但是问题是ODBC连接器在64位系统上不工作,所以我用了我的Windows XP虚拟机然后开始玩。

我创建了一个ODBC连接到我的Amazon Web Services名叫SAP_HANA,然后从那开始,只有编程和快乐。

为了让事情简单,我用了跟我的博客SAP HANAPython?是的,先生!同样的方法,这是个基本方法,通过ODBC连接SAP HANA,显示了CARRIERSCITY FROM列表,并且执行了一个查询去收集以及显示数据。

Euphoria_HANA.ewx

include wxeud.e as wxeud

include odbc.e as odbc

include std/sequence.e as seq

global atom hconn, hstmt

global sequence dsn_var, user, auth, msg, carrier_key

global object data

carrier_key = {}

constant

main = create( wxFrame, {0, -1, “Euphoria and SAP HANA”, -1, -1, 450, 300}),

win = create( wxPanel, main ),

ldsn = create( wxStaticText, {win, -1, “DSN:”,120, 60}),

dsn = create( wxTextCtrl, {win, -1, “”, 200, 55} ),

lusername = create( wxStaticText, {win, -1, “Username:”,120, 90}),

username = create( wxTextCtrl, {win, -1, “”, 200, 85} ),

lpassword = create( wxStaticText, {win, -1, “Password:”,120, 120}),

password = create( wxTextCtrl, {win, -1, “”, 200, 115, -1, -1, wxTE_PASSWORD} ),

connect = create( wxButton, {win, -1,”Connect”, 200, 150})

constant

main2 = create( wxFrame, {0, -1, “Euphoria and SAP HANA”, -1, -1, 450, 300}),

win2 = create( wxPanel, main2 ),

lcarrier = create( wxStaticText, {win2, -1, “Carrier:”,120, 60}),

carrier = create( wxComboBox, {win2, -1, “”, 200, 55, -1, -1, {}}),

lcityfrom = create( wxStaticText, {win2, -1, “City From:”,120, 90}),

cityfrom = create( wxComboBox, {win2, -1, “”, 200, 85, -1, -1, {}}),

show_query = create( wxButton, {win2, -1,”Show Query”, 200, 120})

constant

main3 = create( wxFrame, {0, -1, “Euphoria and SAP HANA”, -1, -1, 600, 600}),

win3 = create( wxPanel, main3 ),

goback = create( wxButton, {win3, -1,”Go Back”, 260, 1}),

grid = create( wxGrid, {win3, -1, 1, 30, -1, -1, 1, 1, 6} )

function getConnected()

          if initODBC() < 0  then

                    abort(0)

          end if

          dsn_var = get_text_value(dsn)

          user = get_text_value(username)

          auth = get_text_value(password)

          hconn = openConnectionODBC( dsn_var, user, auth )

          if not hconn then

                    message_box(“Connection error”,”Error”,wxOK)

                    return 0

          elsif hconn < 0 then

                    msg = getErrorODBC( hconn )

                    message_box(msg[2],”Error”,wxOK)

                    return 0

          else

                    return 1

          end if

end function

function getQuery(sequence sql)

          hstmt = prepareSQL( hconn, sql )

          data = executeSQL( hstmt )

          if hstmt < 0 then

                    message_box(“Query failed”,”Error”,wxOK)

          end if

          if data < 0  then

                    message_box(“No data found”,”Error”,wxOK)

                    return 0

          else

                    data = {getColumnHeaders( hstmt )} & odbc:getData( hstmt )

                    return data

          end if

end function

function fillParameters(object data, atom pos, atom combo, atom key)

          sequence value, seq

          seq = {}

          if sequence( data ) then

                    for i = 2 to length( data ) do

                              value = remove_all(0,data[i][pos])

                              seq = append(seq, value)

                              if key = 1 then

                                        value = remove_all(0,data[i][1])

                                        carrier_key = append(carrier_key, value)

                              end if

              end for

              wxeud:add_item(combo, seq)

          end if

          return 1

end function

function fillCombos()

          sequence sql

          sql = “SELECT CARRID,CARRNAME FROM SFLIGHT.SCARR WHERE MANDT = 300”

          data = getQuery(sql)

          fillParameters(data, 2, carrier, 1)

          sql = “SELECT DISTINCT CITYFROM FROM SFLIGHT.SPFLI WHERE MANDT = 300”

          data = getQuery(sql)

          fillParameters(data, 1, cityfrom, 0)

          return 1

end function

function initializeGrid()

          set_col_label(grid,0,”Carrier”)

          set_col_label(grid,1,”Connection”)

          set_col_label(grid,2,”Flight Date”)

          set_col_label(grid,3,”Passenger Name”)

          set_col_label(grid,4,”City From”)

          set_col_label(grid,5,”City To”)

          atom carrier_sel, len, row, col

          sequence sql, value

          carrier_sel = get_selection(carrier) + 1

          sql = “SELECT SBOOK.CARRID,SBOOK.CONNID,FLDATE, ” &

          “PASSNAME,CITYFROM,CITYTO” &

          ” FROM SFLIGHT.SBOOK INNER JOIN SFLIGHT.SPFLI” &

          ” ON SBOOK.CONNID = SPFLI.CONNID” &

          ” WHERE SBOOK.CARRID = ‘” & carrier_key[carrier_sel] & “‘” &

          ” AND CITYFROM = ‘” & get_string_selection(cityfrom) & “‘” &

          ” AND PASSNAME <> ”” &

          ” AND SBOOK.MANDT = 300″ &

          ” AND year(FLDATE) = 2012″ &

          ” ORDER BY FLDATE DESC”

          data = getQuery(sql)

          if sequence( data ) then

                    row = 0

                    len = length( data ) – 2

                    if len > 0 then

                              append_rows(grid,len)

                              for i = 2 to length( data ) do

                                        col = 0

                                        for j = 1 to 6 do

                                                  value = remove_all(0,data[i][j])

                                                  set_cell_value(grid,value,row,col)

                                                  col = col + 1

                                        end for

                                        row = row + 1

                        end for

              end if

          end if

          set_grid_editable(grid,0)

          autosize_grid(grid)

          return 1

end function

procedure Click_connect(atom this, atom event_type, atom id, atom event )

atom ans

ans = getConnected()

if ans = 1 then

          show_window(main,0)

          fillCombos()

          wxMain( main2 )

end if

end procedure

set_event_handler(connect, get_id(connect), wxEVT_COMMAND_BUTTON_CLICKED, routine_id( “Click_connect” ))

procedure Click_show_query(atom this, atom event_type, atom id, atom event )

          show_window(main2,0)

          initializeGrid()

          wxMain( main3 )

end procedure

set_event_handler(show_query, get_id(show_query), wxEVT_COMMAND_BUTTON_CLICKED, routine_id( “Click_show_query” ))

procedure Click_goback(atom this, atom event_type, atom id, atom event )

          show_window(main3,0)

          clear_grid(grid)

          delete_rows(grid,1,get_number_rows(grid),0)

          show_window(main2,1)

end procedure

set_event_handler(goback, get_id(goback), wxEVT_COMMAND_BUTTON_CLICKED, routine_id( “Click_goback” ))

procedure main3_onClose( atom this, atom event_type, atom id, atom event )

          destroy(main)

          destroy(main2)

          destroy(main3)

end procedure

set_event_handler( main3, get_id(main3), wxEVT_CLOSE_WINDOW, routine_id(“main3_onClose”) )

wxMain( main )

像人们常说的……无图无真相……

Euphoria_HANA_001.png

Euphoria_HANA_002.png

Euphoria_HANA_003.png

Euphoria_HANA_004.png

Euphoria_HANA_005.png

Euphoria_HANA_006.png

Euphoria_HANA_007.png

你可以看到……SAP HANA非常灵活而且用起来简单……不论什么编程语言,你都会获得额外的速度,而且感觉到事情以正确的方式在进行。      

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply