Help needed with mirc script

Drake2007

Expert Member
Joined
Oct 23, 2008
Messages
4,413
im surprised no one has slapped mirc owner in the face for making scripting so hard. Probably find kark like this would drive a man insane but i guess thats the worst part of programming.. fault finding

Yeah I think it's pretty close to bash scripting though, or looks like it anyway I doubt he wrote the whole scripting language just for an irc client.
 

acidrain

Executive Member
Joined
Jan 7, 2007
Messages
5,975
Nope my sqlhandler is different... it uses the $mysql_fetch_row

Code:
/*
; MYSQL_HANDLE = $mysql_connect(ADDRESS, PORT, OPTION, DATABASE, USER, PASS)
*/
alias mysql_connect {
  var %conName = SQLcon $+ $crc($ticks $rand(0,128),0)

  .comopen %conName ADODB.Connection
  if (!$com(%conName)) error $scriptline COM error: $comerr

  if ($com(%conName, CursorLocation, 5, integer, 3) == 0) {
    error $scriptline Cannot set CursorLocation
  }
  if ($com(%conName, ConnectionString, 5, string, $ODBCString($1-)) == 0) {
    error $scriptline Cannot set ConnectionString
  }
  if ($com(%conName, Open, 1) == 0) {
    error $scriptline Cannot Open Connection
    comShowLastError $scriptline %conName
  }
  return %conName

  :error
  if $com(%conName) {
    .comclose %conName
  }
}

alias -l clearCom {
  if $com($1) {
    .comclose $1
  }
}

/*
; mysql_close MYSQL_HANDLE
*/
alias mysql_close {
  if ( !$com($1)) {
    error $scriptline Connection does not exist or already closed
  }
  elseif ($com($1, Close, 1) == 0) {
    error $scriptline cannot close connection
    comShowLastError $scriptline $1
  }
  .comclose $1
}


/*
; MYSQL_RESULT_HANDLE = $mysql_query(MYSQL_HANDLE, QUERY_STRING)
*/
alias mysql_query {
  var %rsName = SQLres $+ $crc($ticks $rand(0,128),0)
  .comopen %rsName ADODB.Recordset
  if (!$com(%rsName)) error $scriptline COM error: $comerr

  var %query = $2
  var %x = 3
  while (%x <= $0) {
    %query = %query $+ , [ [ $+($,%x) ] ]
    inc %x
  }

  if ($com(%rsName, Open, 1, string, %query, dispatch, $1, integer, 3, integer, 1) == 0) {
    error $scriptline cannot execute query : $qt(%query)
    comShowLastError $scriptline $1
  }
  return %rsName
}

alias -l comShowLastError {
  clearCom Errz
  clearCom Err1
  if $com($2, Errors, 3, dispatch* Errz) {
    if ($com(Errz, Count, 3) > 0) {
      if ($com(Errz, Item, 3, int, 0, dispatch* Err1)) {
        if ($com(Err1, Description, 3)) {
          error $1 Last Error Was : $com(Err1).result
          .comclose Err1
        }
        else {
          error $1 cannot get last error!
        }
      }
      else {
        error $1 cannot get last error!
      }
      .comclose Errz
    }
    else {
      error $1 cannot get last error!
    }
  }
}

/*
; mysql_free_result MYSQL_RESULT_HANDLE
*/
alias mysql_free_result {
  if ($com($1, Close, 1) == 0) {
    error $scriptline : cannot close RecordSet
    comShowLastError $scriptline $1
  }
  .comclose $1
}

/*
; NUMBER_OF_ROWS = $mysql_num_rows(MYSQL_RESULT_HANDLE)
*/
alias mysql_num_rows {
  if ($com($1, RecordCount, 3) == 0) {
    error $scriptline cannot get RecordCount
    comShowLastError $scriptline $1
  }
  return $com($1).result
}

/*
; MYSQL_ROW_HANDLE = $mysql_fetch_row(MYSQL_RESULT_HANDLE)
*/
alias mysql_fetch_row {
  var %fsName = SQLrow $+ $crc($ticks $rand(0,128),0)
  if ($com($1, Fields, 3, dispatch* %fsName) == 0) {
    error $scriptline Cannot get row Fields
    comShowLastError $scriptline $1
  }
  return %fsName
}

/*
; mysql_next_row MYSQL_RESULT_HANDLE
*/
alias mysql_next_row {
  if ($com($1, MoveNext, 1) == 0) {
    error $scriptline Cannot MoveNext
    comShowLastError $scriptline $1
  }
}

/*
; mysql_free_row MYSQL_ROW_HANDLE
*/
alias mysql_free_row {
  .comclose $1
}


/*
; COLUMN_VALUE = mysql_row(MYSQL_ROW_HANDLE, ROW_NUMBER)
; COLUMN_NAME  = mysql_row(MYSQL_ROW_HANDLE, ROW_NUMBER).Name
*/
alias mysql_row {
  if ($2 == 0) {
    if ($com($1, Count, 3) == 0) {
      error $scriptline Cannot get Field count
      comShowLastError $scriptline $1
    }
    return $com($1).result
  }
  else {
    if ($com($1, Item, 1, integer, $calc($2 - 1), dispatch* SQLTEMP) == 0) {
      error $scriptline Cannot get Field $2
      comShowLastError $scriptline $1
    }
    if ($prop == Name) {
      if ($com(SQLTEMP, Name, 3) == 0) {
        error $scriptline Cannot get Value of Field $2
        comShowLastError $scriptline $1
      }
    }
    else {
      if ($com(SQLTEMP, Value, 3) == 0) {
        error $scriptline Cannot get Value of Field $2
        comShowLastError $scriptline $1
      }
    }
    var %result = $com(SQLTEMP).result

    .comclose SQLTEMP
    return %result
  }
}

alias -l error {
  echo 4 -s MYSQL_ERROR : line $1 : $2-
}

alias -l nop {
  return
}

; Clears stuck COMs
alias mysql_clear {
  var %x = $com(0)
  while (%x > 0) {
    comclose $com(%x)
    dec %x
  }
}

; MYODBC_CONNECTION_STRING = ODBCString(ADDRESS, PORT, OPTION, DATABASE, USER, PASS)
alias -l ODBCString {
  tokenize 32 $1-
  return Driver={MySQL ODBC 5.1 Driver};Server= $+ $1 $+ ;Port= $+ $2 $+ ;Option= $+ $3 $+ ;Database= $+ $4 $+ ;Uid= $+ $5 $+ ;Pwd= $+ $6- $+ ;
}


alias MYSQL {
  return $readini($scriptdirmysql.ini, $1, $prop)
}
 

acidrain

Executive Member
Joined
Jan 7, 2007
Messages
5,975
Getting late and getting gatvol of this thing, Gonna tackle it again tomorrow if im in the mood lol

Thanks anyways thus far
 

newklear

Expert Member
Joined
Apr 15, 2008
Messages
1,458
I'm hoping this is it.. might be something simple hehe

Are you sure local variables are being fetched correctly ?
You mentioned that the script keeps on bombing out at the "IF statements"
It seems the local variable's being set have an undefined/arbitoury value and therefore the 'IF statements' are not able to process.
Is the $calc function missing ?

var %uptime = $mysql_fetch_row(%test,1)
var %secs = (%uptime % 60)
var %mins = (%uptime / 60 % 60)
var %hours = (%uptime / 3600 % 24)
var %days = (%uptime / 86400)

try
var %uptime $mysql_fetch_row(%test,1)
var %secs $calc(%uptime % 60)
var %mins $calc(%uptime / (60 % 60))
var %hours $calc(%uptime / (3600 % 24))
var %days $calc(%uptime / 86400)

Do a quick test by temporarily using global variables instead of local and check what value they were set after the script was run. (Just change 'var' to 'set' in the above example to switch to global variables)

Also good to have flood protection (Default 5 seconds)
-Just add as the first 2 lines under the 'on *:TEXT:!Uptime*:#:'
-'$address($nick,2)' can be used in place of '$nick':
if (%flood [ $+ [ $nick ] ] == 1) { halt }
set -u5 %flood [ $+ [ $nick ] ] 1
 
Last edited:

guest2013-1

guest
Joined
Aug 22, 2003
Messages
19,800
Just remember mIRC has it's own programming, so the issue with the "if" having insufficient parameters could possibly be that it was expecting if (laddeeda == true){ and not if (!laddeeda) {

Hence it bitching about the insufficient parameters?

I haven't done anything in mIRC since 1998 so seeing you're able to query direct from a database is kind of cool :D

The index should start from 0 AFAIK
 

newklear

Expert Member
Joined
Apr 15, 2008
Messages
1,458
Just remember mIRC has it's own programming, so the issue with the "if" having insufficient parameters could possibly be that it was expecting if (laddeeda == true){ and not if (!laddeeda) {

Hence it bitching about the insufficient parameters?

I haven't done anything in mIRC since 1998 so seeing you're able to query direct from a database is kind of cool :D

The index should start from 0 AFAIK

I'm pretty sure it's the $Calc function that is missing which is causing the script to halt on the 'IF statements'

'if (!%laddeeda) { }' is the same as writing 'if (%laddeeda == $null) { }'
 
Top